Testing a participant is gory-detail-stuff. You must know a lot about the internals of Ruote. Because; In order to 'test' a participant, we have to mimic the environment the participant lives and is executed in.
Since we are isolating the participant in our experiment^W... tests we have to prevent the participant from communicating with Ruote. In order to do so we have replace the #reply function with an own singleton.
participant = Participant.new
def participant.reply; end
The singleton-method reply just has to do ... nothing (certainly not reply to the the engine!)
Loading a workitem is pretty simple, just instantiate a Ruote::Workitem
and load it with the propper values for your tests
wi = Ruote::Workitem.new( 'fields' => { 'my_field' => 'my value' } )
To get the parameters (as given in your process definition), you will have to place them within the fields
hash.
wi = Ruote::Workitem.new(
'fields' => {
'my_field' => 'my value'
'params' => {
'passed_from_pdef' => 'not really, no...'
},
})
Since we want to emulate, or mimic, the environment Ruote builds around our participants, we cannot simply call on_workitem
, we have to do what ruote does.
it "should receive the workitem" do
wi = Ruote::Workitem.new( 'fields' => { 'my_field' => 'my value' } )
subject._on_workitem(wi)
subject.workitem.should == wi
end
Or, for old(er) ruote installments
it "should consume the workitem" do
wi = Ruote::Workitem.new( 'fields' => { 'my_field' => 'my value' } )
subject.expects(:consume).with(wi)
subject._consume(wi)
end
Since you have overridden reply (with nothing) you can just test participant.workitem
and expect it to have the latest-greatest.
How you test your side-effects is up to you...
If you have subclassed the storage participant, the rules change a little
In order for the storage participant to function propperly, an instance of the ruote engine should be supplied
engine = Ruote::Dashboard.new(Ruote::HashStorage.new())
participant = MyStorageParticipant(engine)
First thing the the StorageParticipant sub-class does (or should do) in on_workitem
is call super
- this will wreak havoc, unless you make sure that you have a workitem with a (valid) fei
workitem = RuoteWorkitem.new(
'fei' => { 'expid' => 0, 'wfid' => 'some-wfid-could-be-anything', 'engine_id' => 'engine' },
'fields' => { ... }
)
- The code examples provided are not runnable out-off-the-box and are meant has a hook for you to start your work on.
- These code examples are RSpec specific and assume the use of Mocha as a mocking framework.