finite_machine 0.11.3 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +34 -0
- data/README.md +564 -569
- data/Rakefile +5 -1
- data/benchmarks/memory_profile.rb +11 -0
- data/benchmarks/memory_usage.rb +16 -9
- data/finite_machine.gemspec +10 -3
- data/lib/finite_machine.rb +34 -46
- data/lib/finite_machine/async_call.rb +5 -21
- data/lib/finite_machine/callable.rb +4 -4
- data/lib/finite_machine/catchable.rb +4 -2
- data/lib/finite_machine/choice_merger.rb +19 -19
- data/lib/finite_machine/const.rb +16 -0
- data/lib/finite_machine/definition.rb +2 -2
- data/lib/finite_machine/dsl.rb +66 -149
- data/lib/finite_machine/env.rb +4 -2
- data/lib/finite_machine/event_definition.rb +7 -15
- data/lib/finite_machine/{events_chain.rb → events_map.rb} +39 -51
- data/lib/finite_machine/hook_event.rb +60 -61
- data/lib/finite_machine/hooks.rb +44 -36
- data/lib/finite_machine/listener.rb +2 -2
- data/lib/finite_machine/logger.rb +5 -4
- data/lib/finite_machine/message_queue.rb +39 -30
- data/lib/finite_machine/observer.rb +55 -37
- data/lib/finite_machine/safety.rb +12 -10
- data/lib/finite_machine/state_definition.rb +3 -5
- data/lib/finite_machine/state_machine.rb +83 -64
- data/lib/finite_machine/state_parser.rb +51 -79
- data/lib/finite_machine/subscribers.rb +1 -1
- data/lib/finite_machine/threadable.rb +3 -1
- data/lib/finite_machine/transition.rb +30 -31
- data/lib/finite_machine/transition_builder.rb +23 -32
- data/lib/finite_machine/transition_event.rb +12 -11
- data/lib/finite_machine/two_phase_lock.rb +3 -1
- data/lib/finite_machine/undefined_transition.rb +5 -6
- data/lib/finite_machine/version.rb +2 -2
- data/spec/integration/system_spec.rb +36 -38
- data/spec/performance/benchmark_spec.rb +13 -21
- data/spec/unit/alias_target_spec.rb +22 -41
- data/spec/unit/async_callbacks_spec.rb +8 -13
- data/spec/unit/auto_methods_spec.rb +44 -0
- data/spec/unit/callable/call_spec.rb +1 -3
- data/spec/unit/callbacks_spec.rb +372 -463
- data/spec/unit/can_spec.rb +13 -23
- data/spec/unit/cancel_callbacks_spec.rb +46 -0
- data/spec/unit/choice_spec.rb +105 -141
- data/spec/unit/define_spec.rb +31 -31
- data/spec/unit/definition_spec.rb +24 -41
- data/spec/unit/event_names_spec.rb +6 -10
- data/spec/unit/events_map/add_spec.rb +23 -0
- data/spec/unit/events_map/choice_transition_spec.rb +25 -0
- data/spec/unit/events_map/clear_spec.rb +13 -0
- data/spec/unit/events_map/events_spec.rb +16 -0
- data/spec/unit/events_map/inspect_spec.rb +22 -0
- data/spec/unit/{events_chain → events_map}/match_transition_spec.rb +12 -14
- data/spec/unit/{events_chain → events_map}/move_to_spec.rb +14 -17
- data/spec/unit/events_map/states_for_spec.rb +17 -0
- data/spec/unit/events_spec.rb +91 -160
- data/spec/unit/handlers_spec.rb +34 -66
- data/spec/unit/hook_event/any_state_or_event_spec.rb +13 -0
- data/spec/unit/hook_event/build_spec.rb +1 -3
- data/spec/unit/hook_event/eql_spec.rb +1 -3
- data/spec/unit/hook_event/initialize_spec.rb +2 -4
- data/spec/unit/hook_event/notify_spec.rb +2 -4
- data/spec/unit/hooks/clear_spec.rb +1 -1
- data/spec/unit/hooks/{call_spec.rb → find_spec.rb} +4 -9
- data/spec/unit/hooks/inspect_spec.rb +16 -8
- data/spec/unit/hooks/register_spec.rb +4 -9
- data/spec/unit/if_unless_spec.rb +76 -115
- data/spec/unit/initial_spec.rb +50 -82
- data/spec/unit/inspect_spec.rb +14 -9
- data/spec/unit/is_spec.rb +12 -18
- data/spec/unit/log_transitions_spec.rb +4 -10
- data/spec/unit/logger_spec.rb +1 -3
- data/spec/unit/{event_queue_spec.rb → message_queue_spec.rb} +15 -8
- data/spec/unit/new_spec.rb +50 -0
- data/spec/unit/respond_to_spec.rb +2 -6
- data/spec/unit/state_parser/parse_spec.rb +9 -12
- data/spec/unit/states_spec.rb +12 -18
- data/spec/unit/subscribers_spec.rb +1 -3
- data/spec/unit/target_spec.rb +60 -93
- data/spec/unit/terminated_spec.rb +15 -25
- data/spec/unit/transition/check_conditions_spec.rb +16 -15
- data/spec/unit/transition/inspect_spec.rb +6 -6
- data/spec/unit/transition/matches_spec.rb +5 -7
- data/spec/unit/transition/states_spec.rb +5 -7
- data/spec/unit/transition/to_state_spec.rb +5 -13
- data/spec/unit/trigger_spec.rb +5 -9
- data/spec/unit/undefined_transition/eql_spec.rb +1 -3
- metadata +86 -49
- data/.gitignore +0 -18
- data/.rspec +0 -5
- data/.travis.yml +0 -27
- data/Gemfile +0 -16
- data/assets/finite_machine_logo.png +0 -0
- data/lib/finite_machine/async_proxy.rb +0 -55
- data/spec/unit/async_events_spec.rb +0 -107
- data/spec/unit/events_chain/add_spec.rb +0 -25
- data/spec/unit/events_chain/cancel_transitions_spec.rb +0 -22
- data/spec/unit/events_chain/choice_transition_spec.rb +0 -28
- data/spec/unit/events_chain/clear_spec.rb +0 -15
- data/spec/unit/events_chain/events_spec.rb +0 -18
- data/spec/unit/events_chain/inspect_spec.rb +0 -24
- data/spec/unit/events_chain/states_for_spec.rb +0 -17
- data/spec/unit/hook_event/infer_default_name_spec.rb +0 -13
- data/spec/unit/state_parser/inspect_spec.rb +0 -25
data/spec/unit/can_spec.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
require 'spec_helper'
|
1
|
+
# frozen_string_literal: true
|
4
2
|
|
5
3
|
RSpec.describe FiniteMachine, 'can?' do
|
6
4
|
before(:each) {
|
@@ -12,15 +10,13 @@ RSpec.describe FiniteMachine, 'can?' do
|
|
12
10
|
}
|
13
11
|
|
14
12
|
it "allows to check if event can be fired" do
|
15
|
-
fsm = FiniteMachine.
|
13
|
+
fsm = FiniteMachine.new do
|
16
14
|
initial :green
|
17
15
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
event :go, :yellow => :green
|
23
|
-
}
|
16
|
+
event :slow, :green => :yellow
|
17
|
+
event :stop, :yellow => :red
|
18
|
+
event :ready, :red => :yellow
|
19
|
+
event :go, :yellow => :green
|
24
20
|
end
|
25
21
|
|
26
22
|
expect(fsm.current).to eql(:green)
|
@@ -57,13 +53,11 @@ RSpec.describe FiniteMachine, 'can?' do
|
|
57
53
|
|
58
54
|
context 'with conditionl transition' do
|
59
55
|
it "evalutes condition with parameters" do
|
60
|
-
fsm = FiniteMachine.
|
56
|
+
fsm = FiniteMachine.new do
|
61
57
|
initial :green
|
62
58
|
|
63
|
-
|
64
|
-
|
65
|
-
event :stop, :yellow => :red, if: proc { |_, state| state }
|
66
|
-
}
|
59
|
+
event :slow, :green => :yellow
|
60
|
+
event :stop, :yellow => :red, if: proc { |_, state| state }
|
67
61
|
end
|
68
62
|
expect(fsm.current).to eq(:green)
|
69
63
|
expect(fsm.can?(:slow)).to be(true)
|
@@ -77,16 +71,12 @@ RSpec.describe FiniteMachine, 'can?' do
|
|
77
71
|
|
78
72
|
it "checks against target and grouped events" do
|
79
73
|
bug = Bug.new
|
80
|
-
fsm = FiniteMachine.
|
74
|
+
fsm = FiniteMachine.new(bug) do
|
81
75
|
initial :initial
|
82
76
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
event :bump, :initial => :low
|
87
|
-
event :bump, :low => :medium, if: :pending?
|
88
|
-
event :bump, :medium => :high
|
89
|
-
}
|
77
|
+
event :bump, :initial => :low
|
78
|
+
event :bump, :low => :medium, if: :pending?
|
79
|
+
event :bump, :medium => :high
|
90
80
|
end
|
91
81
|
expect(fsm.current).to eq(:initial)
|
92
82
|
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe FiniteMachine, '#cancel_event' do
|
4
|
+
it "cancels transition on event callback" do
|
5
|
+
fsm = FiniteMachine.new do
|
6
|
+
initial :green
|
7
|
+
|
8
|
+
event :slow, :green => :yellow
|
9
|
+
event :go, :yellow => :green
|
10
|
+
|
11
|
+
on_exit :green do |event|
|
12
|
+
cancel_event(event)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
expect(fsm.current).to eql(:green)
|
17
|
+
fsm.slow
|
18
|
+
expect(fsm.current).to eql(:green)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "stops executing callbacks when cancelled" do
|
22
|
+
called = []
|
23
|
+
|
24
|
+
fsm = FiniteMachine.new do
|
25
|
+
initial :initial
|
26
|
+
|
27
|
+
event :bump, initial: :low
|
28
|
+
|
29
|
+
on_before do |event|
|
30
|
+
called << "enter_#{event.name}_#{event.from}_#{event.to}"
|
31
|
+
|
32
|
+
cancel_event(event)
|
33
|
+
end
|
34
|
+
|
35
|
+
on_exit :initial do |event| called << "exit_initial" end
|
36
|
+
on_exit do |event| called << "exit_any" end
|
37
|
+
on_enter :low do |event| called << "enter_low" end
|
38
|
+
on_after :bump do |event| called << "after_#{event.name}" end
|
39
|
+
on_after do |event| called << "after_any" end
|
40
|
+
end
|
41
|
+
|
42
|
+
fsm.bump
|
43
|
+
|
44
|
+
expect(called).to eq(['enter_bump_initial_low'])
|
45
|
+
end
|
46
|
+
end
|
data/spec/unit/choice_spec.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
require 'spec_helper'
|
1
|
+
# frozen_string_literal: true
|
4
2
|
|
5
3
|
RSpec.describe FiniteMachine, '#choice' do
|
6
4
|
before(:each) {
|
@@ -13,21 +11,17 @@ RSpec.describe FiniteMachine, '#choice' do
|
|
13
11
|
|
14
12
|
it "allows for static choice based on conditional branching" do
|
15
13
|
called = []
|
16
|
-
fsm = FiniteMachine.
|
14
|
+
fsm = FiniteMachine.new do
|
17
15
|
initial :company_form
|
18
16
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
}
|
26
|
-
|
27
|
-
callbacks {
|
28
|
-
on_exit do |event| called << "on_exit_#{event.from}" end
|
29
|
-
on_enter do |event| called << "on_enter_#{event.to}" end
|
30
|
-
}
|
17
|
+
event :next, from: :company_form do
|
18
|
+
choice :agreement_form, if: -> { false }
|
19
|
+
choice :promo_form, if: -> { false }
|
20
|
+
choice :official_form, if: -> { true }
|
21
|
+
end
|
22
|
+
|
23
|
+
on_exit do |event| called << "on_exit_#{event.from}" end
|
24
|
+
on_enter do |event| called << "on_enter_#{event.to}" end
|
31
25
|
end
|
32
26
|
expect(fsm.current).to eq(:company_form)
|
33
27
|
fsm.next
|
@@ -39,16 +33,14 @@ RSpec.describe FiniteMachine, '#choice' do
|
|
39
33
|
end
|
40
34
|
|
41
35
|
it "allows for dynamic choice based on conditional branching" do
|
42
|
-
fsm = FiniteMachine.
|
36
|
+
fsm = FiniteMachine.new do
|
43
37
|
initial :company_form
|
44
38
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
end
|
51
|
-
}
|
39
|
+
event :next, from: :company_form do
|
40
|
+
choice :agreement_form, if: proc { |_, a| a < 1 }
|
41
|
+
choice :promo_form, if: proc { |_, a| a == 1 }
|
42
|
+
choice :official_form, if: proc { |_, a| a > 1 }
|
43
|
+
end
|
52
44
|
end
|
53
45
|
expect(fsm.current).to eq(:company_form)
|
54
46
|
fsm.next(0)
|
@@ -65,17 +57,13 @@ RSpec.describe FiniteMachine, '#choice' do
|
|
65
57
|
|
66
58
|
it "allows for dynamic choice based on conditional branching and target" do
|
67
59
|
user = User.new
|
68
|
-
fsm = FiniteMachine.
|
60
|
+
fsm = FiniteMachine.new(user) do
|
69
61
|
initial :company_form
|
70
62
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
choice :agreement_form, if: proc { |_user, token| _user.promo?(token) }
|
76
|
-
choice :promo_form, unless: proc { |_user, token| _user.promo?(token) }
|
77
|
-
end
|
78
|
-
}
|
63
|
+
event :next, from: :company_form do
|
64
|
+
choice :agreement_form, if: proc { |_user, token| _user.promo?(token) }
|
65
|
+
choice :promo_form, unless: proc { |_user, token| _user.promo?(token) }
|
66
|
+
end
|
79
67
|
end
|
80
68
|
expect(fsm.current).to eq(:company_form)
|
81
69
|
fsm.next(:no)
|
@@ -86,16 +74,14 @@ RSpec.describe FiniteMachine, '#choice' do
|
|
86
74
|
end
|
87
75
|
|
88
76
|
it "chooses state when skipped if/unless" do
|
89
|
-
fsm = FiniteMachine.
|
77
|
+
fsm = FiniteMachine.new do
|
90
78
|
initial :company_form
|
91
79
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
end
|
98
|
-
}
|
80
|
+
event :next, from: :company_form do
|
81
|
+
choice :agreement_form, if: -> { false }
|
82
|
+
choice :promo_form
|
83
|
+
choice :official_form, if: -> { true }
|
84
|
+
end
|
99
85
|
end
|
100
86
|
expect(fsm.current).to eq(:company_form)
|
101
87
|
fsm.next
|
@@ -103,16 +89,14 @@ RSpec.describe FiniteMachine, '#choice' do
|
|
103
89
|
end
|
104
90
|
|
105
91
|
it "chooses default state when branching conditions don't match" do
|
106
|
-
fsm = FiniteMachine.
|
92
|
+
fsm = FiniteMachine.new do
|
107
93
|
initial :company_form
|
108
94
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
end
|
115
|
-
}
|
95
|
+
event :next, from: :company_form do
|
96
|
+
choice :agreement_form, if: -> { false }
|
97
|
+
choice :promo_form, if: -> { false }
|
98
|
+
default :official_form
|
99
|
+
end
|
116
100
|
end
|
117
101
|
expect(fsm.current).to eq(:company_form)
|
118
102
|
fsm.next
|
@@ -120,15 +104,13 @@ RSpec.describe FiniteMachine, '#choice' do
|
|
120
104
|
end
|
121
105
|
|
122
106
|
it "fails to transition when no condition matches without default state" do
|
123
|
-
fsm = FiniteMachine.
|
107
|
+
fsm = FiniteMachine.new do
|
124
108
|
initial :company_form
|
125
109
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
end
|
131
|
-
}
|
110
|
+
event :next, from: :company_form do
|
111
|
+
choice :agreement_form, if: -> { false }
|
112
|
+
choice :promo_form, if: -> { false }
|
113
|
+
end
|
132
114
|
end
|
133
115
|
expect(fsm.current).to eq(:company_form)
|
134
116
|
fsm.next
|
@@ -136,7 +118,7 @@ RSpec.describe FiniteMachine, '#choice' do
|
|
136
118
|
end
|
137
119
|
|
138
120
|
it "allows to transition from multiple states to choice pseudostate" do
|
139
|
-
fsm = FiniteMachine.
|
121
|
+
fsm = FiniteMachine.new do
|
140
122
|
initial :red
|
141
123
|
|
142
124
|
event :go, from: [:yellow, :red] do
|
@@ -154,10 +136,10 @@ RSpec.describe FiniteMachine, '#choice' do
|
|
154
136
|
end
|
155
137
|
|
156
138
|
it "allows to transition from any state to choice pseudo state" do
|
157
|
-
fsm = FiniteMachine.
|
139
|
+
fsm = FiniteMachine.new do
|
158
140
|
initial :red
|
159
141
|
|
160
|
-
event :go, from:
|
142
|
+
event :go, from: any_state do
|
161
143
|
choice :pink, if: -> { false }
|
162
144
|
choice :green
|
163
145
|
end
|
@@ -168,7 +150,7 @@ RSpec.describe FiniteMachine, '#choice' do
|
|
168
150
|
end
|
169
151
|
|
170
152
|
it "groups correctly events under the same name" do
|
171
|
-
fsm = FiniteMachine.
|
153
|
+
fsm = FiniteMachine.new do
|
172
154
|
initial :red
|
173
155
|
|
174
156
|
event :next, from: :yellow, to: :green
|
@@ -187,24 +169,20 @@ RSpec.describe FiniteMachine, '#choice' do
|
|
187
169
|
|
188
170
|
it "performs matching transitions for multiple event definitions with the same name" do
|
189
171
|
ticket = double(:ticket, :pending? => true, :finished? => true)
|
190
|
-
fsm = FiniteMachine.
|
172
|
+
fsm = FiniteMachine.new(ticket) do
|
191
173
|
initial :inactive
|
192
174
|
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
event :advance, from: [:inactive, :paused, :fulfilled] do
|
197
|
-
choice :active, if: proc { |_ticket| !_ticket.pending? }
|
198
|
-
end
|
175
|
+
event :advance, from: [:inactive, :paused, :fulfilled] do
|
176
|
+
choice :active, if: proc { |_ticket| !_ticket.pending? }
|
177
|
+
end
|
199
178
|
|
200
|
-
|
201
|
-
|
202
|
-
|
179
|
+
event :advance, from: [:inactive, :active, :fulfilled] do
|
180
|
+
choice :paused, if: proc { |_ticket| _ticket.pending? }
|
181
|
+
end
|
203
182
|
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
}
|
183
|
+
event :advance, from: [:inactive, :active, :paused] do
|
184
|
+
choice :fulfilled, if: proc { |_ticket| _ticket.finished? }
|
185
|
+
end
|
208
186
|
end
|
209
187
|
expect(fsm.current).to eq(:inactive)
|
210
188
|
fsm.advance
|
@@ -216,29 +194,23 @@ RSpec.describe FiniteMachine, '#choice' do
|
|
216
194
|
it "does not transition when no matching choice for multiple event definitions" do
|
217
195
|
ticket = double(:ticket, :pending? => true, :finished? => false)
|
218
196
|
called = []
|
219
|
-
fsm = FiniteMachine.
|
197
|
+
fsm = FiniteMachine.new(ticket) do
|
220
198
|
initial :inactive
|
221
199
|
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
event :advance, from: [:inactive, :paused, :fulfilled] do
|
226
|
-
choice :active, if: proc { |_ticket| !_ticket.pending? }
|
227
|
-
end
|
200
|
+
event :advance, from: [:inactive, :paused, :fulfilled] do
|
201
|
+
choice :active, if: proc { |_ticket| !_ticket.pending? }
|
202
|
+
end
|
228
203
|
|
229
|
-
|
230
|
-
|
231
|
-
|
204
|
+
event :advance, from: [:inactive, :active, :fulfilled] do
|
205
|
+
choice :paused, if: proc { |_ticket| _ticket.pending? }
|
206
|
+
end
|
232
207
|
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
}
|
208
|
+
event :advance, from: [:inactive, :active, :paused] do
|
209
|
+
choice :fulfilled, if: proc { |_ticket| _ticket.finished? }
|
210
|
+
end
|
237
211
|
|
238
|
-
|
239
|
-
|
240
|
-
on_after(:advance) { called << 'on_after_advance' }
|
241
|
-
}
|
212
|
+
on_before(:advance) { called << 'on_before_advance' }
|
213
|
+
on_after(:advance) { called << 'on_after_advance' }
|
242
214
|
end
|
243
215
|
expect(fsm.current).to eq(:inactive)
|
244
216
|
fsm.advance
|
@@ -265,57 +237,49 @@ RSpec.describe FiniteMachine, '#choice' do
|
|
265
237
|
target.expect(c).to target.eql(expected[:c])
|
266
238
|
}
|
267
239
|
|
268
|
-
|
269
|
-
|
270
|
-
fsm = FiniteMachine.define do
|
240
|
+
fsm = FiniteMachine.new(self) do
|
271
241
|
initial :red
|
272
242
|
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
on_exit :red, &callback
|
314
|
-
|
315
|
-
# event callbacks
|
316
|
-
on_before :next, &callback
|
317
|
-
on_after :next, &callback
|
318
|
-
}
|
243
|
+
event :next, from: :red do
|
244
|
+
choice :green, if: -> { false }
|
245
|
+
choice :yellow
|
246
|
+
end
|
247
|
+
|
248
|
+
event :next, from: :yellow do
|
249
|
+
choice :green, if: -> { true }
|
250
|
+
choice :yellow
|
251
|
+
end
|
252
|
+
|
253
|
+
event :finish, from: any_state do
|
254
|
+
choice :green, if: -> { false }
|
255
|
+
choice :red
|
256
|
+
end
|
257
|
+
|
258
|
+
# generic state callbacks
|
259
|
+
on_enter(&callback)
|
260
|
+
on_transition(&callback)
|
261
|
+
on_exit(&callback)
|
262
|
+
|
263
|
+
# generic event callbacks
|
264
|
+
on_before(&callback)
|
265
|
+
on_after(&callback)
|
266
|
+
|
267
|
+
# state callbacks
|
268
|
+
on_enter :green, &callback
|
269
|
+
on_enter :yellow, &callback
|
270
|
+
on_enter :red, &callback
|
271
|
+
|
272
|
+
on_transition :green, &callback
|
273
|
+
on_transition :yellow, &callback
|
274
|
+
on_transition :red, &callback
|
275
|
+
|
276
|
+
on_exit :green, &callback
|
277
|
+
on_exit :yellow, &callback
|
278
|
+
on_exit :red, &callback
|
279
|
+
|
280
|
+
# event callbacks
|
281
|
+
on_before :next, &callback
|
282
|
+
on_after :next, &callback
|
319
283
|
end
|
320
284
|
expect(fsm.current).to eq(:red)
|
321
285
|
|