Introduce names for FiniteMachine instances#73
Introduce names for FiniteMachine instances#73raw-bin wants to merge 1 commit intopiotrmurach:masterfrom
Conversation
piotrmurach
left a comment
There was a problem hiding this comment.
Thank you for submitting this PR! Things are looking good. I added few comments. Most importantly, we need another test for when uuid gets generated.
| fsm.stop(1, 2) | ||
| output.rewind | ||
| expect(output.read).to match(/Transition: @event=stop @with=\[1,2\] yellow -> red/) | ||
| expect(output.read).to match(/Transition: @machine=TrafficLights @event=stop @with=\[1,2\] yellow -> red/) |
There was a problem hiding this comment.
Metrics/LineLength: Line is too long. [110/80]
| fsm.slow | ||
| output.rewind | ||
| expect(output.read).to match(/Transition: @event=slow green -> yellow/) | ||
| expect(output.read).to match(/Transition: @machine=TrafficLights @event=slow green -> yellow/) |
There was a problem hiding this comment.
Metrics/LineLength: Line is too long. [98/80]
| logger.report_transition('TrafficLights', :go, :red, :green) | ||
|
|
||
| expect(log).to have_received(:info).with("Transition: @event=go red -> green") | ||
| expect(log).to have_received(:info).with("Transition: @machine=TrafficLights @event=go red -> green") |
There was a problem hiding this comment.
Metrics/LineLength: Line is too long. [105/80]
piotrmurach
left a comment
There was a problem hiding this comment.
Thank you for working on the suggestions. We still need another test for when the name isn't specified to ensure generating short UUID works correctly.
|
|
||
| it "logs transitions" do | ||
| fsm = FiniteMachine.new log_transitions: true do | ||
| fsm = FiniteMachine.new name: "TrafficLights", log_transitions: true do |
There was a problem hiding this comment.
We need a test case when the name is not specified. I'd probably keep this test as it was without the name and test the short UUID generation. Let me know if you need any pointers on how to test this.
There was a problem hiding this comment.
Understood. I'll give it a shot and reach out if I run into trouble. Thanks.
There was a problem hiding this comment.
Hi @piotrmurach: Just wanted to chime in and let you know that I got distracted but will get back to this in the next couple of days. Thanks.
Describe the change
This PR introduces the ability to specify an optional name for new FiniteMachine instances.
Why are we doing this?
Currently transition logs don't specify the FiniteMachine for which event transitions happen. This makes it hard to understand or post process the logs.
Benefits
It will now be possible to disambiguate event transitions that occur in the context of different FiniteMachine instances.
Drawbacks
None.
Requirements
masterbranch?