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
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe FiniteMachine::HookEvent, '#any_state_or_event' do
|
4
|
+
it "infers default name for state" do
|
5
|
+
hook_event = described_class::Enter
|
6
|
+
expect(described_class.any_state_or_event(hook_event)).to eq(FiniteMachine::ANY_STATE)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "infers default name for event" do
|
10
|
+
hook_event = described_class::Before
|
11
|
+
expect(described_class.any_state_or_event(hook_event)).to eq(FiniteMachine::ANY_EVENT)
|
12
|
+
end
|
13
|
+
end
|
@@ -1,6 +1,4 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
require 'spec_helper'
|
1
|
+
# frozen_string_literal: true
|
4
2
|
|
5
3
|
RSpec.describe FiniteMachine::HookEvent, '#new' do
|
6
4
|
it "reads event name" do
|
@@ -20,6 +18,6 @@ RSpec.describe FiniteMachine::HookEvent, '#new' do
|
|
20
18
|
|
21
19
|
it "freezes object" do
|
22
20
|
hook_event = described_class.new(:green, :go, :green)
|
23
|
-
expect
|
21
|
+
expect(hook_event.frozen?).to eq(true)
|
24
22
|
end
|
25
23
|
end
|
@@ -1,8 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
RSpec.describe FiniteMachine::HookEvent, '.notify' do
|
3
|
+
RSpec.describe FiniteMachine::HookEvent, '#notify' do
|
6
4
|
it "emits event on the subscriber" do
|
7
5
|
subscriber = spy(:subscriber)
|
8
6
|
hook_event = described_class.new(:green, :go, :red)
|
@@ -1,13 +1,8 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe FiniteMachine::Hooks, '#call' do
|
6
|
-
let(:object) { described_class }
|
7
|
-
|
8
|
-
subject(:hooks) { object.new }
|
1
|
+
# frozen_string_literal: true
|
9
2
|
|
3
|
+
RSpec.describe FiniteMachine::Hooks, '#[]' do
|
10
4
|
it "adds and removes a single hook" do
|
5
|
+
hooks = FiniteMachine::Hooks.new
|
11
6
|
expect(hooks).to be_empty
|
12
7
|
|
13
8
|
yielded = []
|
@@ -15,7 +10,7 @@ RSpec.describe FiniteMachine::Hooks, '#call' do
|
|
15
10
|
hook = -> { }
|
16
11
|
hooks.register(event_type, :foo, hook)
|
17
12
|
|
18
|
-
hooks
|
13
|
+
hooks[event_type][:foo].each do |callback|
|
19
14
|
yielded << callback
|
20
15
|
end
|
21
16
|
|
@@ -1,17 +1,25 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
require 'spec_helper'
|
1
|
+
# frozen_string_literal: true
|
4
2
|
|
5
3
|
RSpec.describe FiniteMachine::Hooks, '#inspect' do
|
6
|
-
subject(:hooks) { described_class.new }
|
7
|
-
|
8
4
|
it "displays name and transitions" do
|
5
|
+
hooks = FiniteMachine::Hooks.new
|
6
|
+
hook = -> { }
|
7
|
+
event = FiniteMachine::HookEvent::Enter
|
8
|
+
hooks_map = {event => {yellow: [hook]}}
|
9
|
+
|
10
|
+
hooks.register(event, :yellow, hook)
|
11
|
+
|
12
|
+
expect(hooks.inspect).to eql("<#FiniteMachine::Hooks:0x#{hooks.object_id.to_s(16)} @hooks_map=#{hooks_map}>")
|
13
|
+
end
|
14
|
+
|
15
|
+
it "displays hooks content" do
|
16
|
+
hooks = FiniteMachine::Hooks.new
|
9
17
|
hook = -> { }
|
10
18
|
event = FiniteMachine::HookEvent::Enter
|
11
|
-
|
19
|
+
hooks_map = {event => {yellow: [hook]}}
|
20
|
+
|
12
21
|
hooks.register(event, :yellow, hook)
|
13
22
|
|
14
|
-
expect(hooks.
|
15
|
-
expect(hooks.to_s).to eql(hooks.inspect)
|
23
|
+
expect(hooks.to_s).to eql(hooks_map.to_s)
|
16
24
|
end
|
17
25
|
end
|
@@ -1,22 +1,17 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
require 'spec_helper'
|
1
|
+
# frozen_string_literal: true
|
4
2
|
|
5
3
|
RSpec.describe FiniteMachine::Hooks, '#register' do
|
6
|
-
let(:object) { described_class }
|
7
|
-
|
8
|
-
subject(:hooks) { object.new }
|
9
|
-
|
10
4
|
it "adds and removes a single hook" do
|
5
|
+
hooks = FiniteMachine::Hooks.new
|
11
6
|
expect(hooks).to be_empty
|
12
7
|
|
13
8
|
event_type = FiniteMachine::HookEvent::Before
|
14
9
|
hook = -> { }
|
15
10
|
|
16
11
|
hooks.register(event_type, :foo, hook)
|
17
|
-
expect(hooks
|
12
|
+
expect(hooks[event_type][:foo]).to eq([hook])
|
18
13
|
|
19
14
|
hooks.unregister(event_type, :foo, hook)
|
20
|
-
expect(hooks
|
15
|
+
expect(hooks[event_type][:foo]).to eq([])
|
21
16
|
end
|
22
17
|
end
|
data/spec/unit/if_unless_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, ':if, :unless' do
|
6
4
|
before(:each) {
|
@@ -29,17 +27,15 @@ RSpec.describe FiniteMachine, ':if, :unless' do
|
|
29
27
|
|
30
28
|
it "passes context to conditionals" do
|
31
29
|
called = []
|
32
|
-
fsm = FiniteMachine.
|
30
|
+
fsm = FiniteMachine.new do
|
33
31
|
initial :red
|
34
32
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
42
|
-
}
|
33
|
+
event :go, :red => :green,
|
34
|
+
if: proc { |context| called << "cond_red_green(#{context})"; true}
|
35
|
+
event :stop, from: any_state do
|
36
|
+
choice :red,
|
37
|
+
if: proc { |context| called << "cond_any_red(#{context})"; true }
|
38
|
+
end
|
43
39
|
end
|
44
40
|
|
45
41
|
expect(fsm.current).to eq(:red)
|
@@ -58,17 +54,15 @@ RSpec.describe FiniteMachine, ':if, :unless' do
|
|
58
54
|
|
59
55
|
it "passes context & arguments to conditionals" do
|
60
56
|
called = []
|
61
|
-
fsm = FiniteMachine.
|
57
|
+
fsm = FiniteMachine.new do
|
62
58
|
initial :red
|
63
59
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
end
|
71
|
-
}
|
60
|
+
event :go, :red => :green,
|
61
|
+
if: proc { |_, a| called << "cond_red_green(#{a})"; true }
|
62
|
+
event :stop, from: any_state do
|
63
|
+
choice :red,
|
64
|
+
if: proc { |_, b| called << "cond_any_red(#{b})"; true }
|
65
|
+
end
|
72
66
|
end
|
73
67
|
|
74
68
|
expect(fsm.current).to eq(:red)
|
@@ -88,30 +82,26 @@ RSpec.describe FiniteMachine, ':if, :unless' do
|
|
88
82
|
it "allows to cancel event with :if option" do
|
89
83
|
called = []
|
90
84
|
|
91
|
-
fsm = FiniteMachine.
|
85
|
+
fsm = FiniteMachine.new do
|
92
86
|
initial :green
|
93
87
|
|
94
|
-
|
95
|
-
|
96
|
-
event :stop, :yellow => :red
|
97
|
-
}
|
88
|
+
event :slow, :green => :yellow, if: -> { return false }
|
89
|
+
event :stop, :yellow => :red
|
98
90
|
|
99
|
-
callbacks
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
on_exit do |event| called << 'on_exit' end
|
91
|
+
# generic callbacks
|
92
|
+
on_enter do |event| called << 'on_enter' end
|
93
|
+
on_transition do |event| called << 'on_transition' end
|
94
|
+
on_exit do |event| called << 'on_exit' end
|
104
95
|
|
105
|
-
|
106
|
-
|
107
|
-
|
96
|
+
# state callbacks
|
97
|
+
on_enter :green do |event| called << 'on_enter_green' end
|
98
|
+
on_enter :yellow do |event| called << "on_enter_yellow" end
|
108
99
|
|
109
|
-
|
110
|
-
|
100
|
+
on_transition :green do |event| called << 'on_transition_green' end
|
101
|
+
on_transition :yellow do |event| called << "on_transition_yellow" end
|
111
102
|
|
112
|
-
|
113
|
-
|
114
|
-
}
|
103
|
+
on_exit :green do |event| called << 'on_exit_green' end
|
104
|
+
on_exit :yellow do |event| called << "on_exit_yellow" end
|
115
105
|
end
|
116
106
|
|
117
107
|
expect(fsm.current).to eql(:green)
|
@@ -124,30 +114,26 @@ RSpec.describe FiniteMachine, ':if, :unless' do
|
|
124
114
|
it "allows to cancel event with :unless option" do
|
125
115
|
called = []
|
126
116
|
|
127
|
-
fsm = FiniteMachine.
|
117
|
+
fsm = FiniteMachine.new do
|
128
118
|
initial :green
|
129
119
|
|
130
|
-
|
131
|
-
|
132
|
-
event :stop, :yellow => :red
|
133
|
-
}
|
120
|
+
event :slow, :green => :yellow, unless: -> { true }
|
121
|
+
event :stop, :yellow => :red
|
134
122
|
|
135
|
-
callbacks
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
on_exit do |event| called << 'on_exit' end
|
123
|
+
# generic callbacks
|
124
|
+
on_enter do |event| called << 'on_enter' end
|
125
|
+
on_transition do |event| called << 'on_transition' end
|
126
|
+
on_exit do |event| called << 'on_exit' end
|
140
127
|
|
141
|
-
|
142
|
-
|
143
|
-
|
128
|
+
# state callbacks
|
129
|
+
on_enter :green do |event| called << 'on_enter_green' end
|
130
|
+
on_enter :yellow do |event| called << "on_enter_yellow" end
|
144
131
|
|
145
|
-
|
146
|
-
|
132
|
+
on_transition :green do |event| called << 'on_transition_green' end
|
133
|
+
on_transition :yellow do |event| called << "on_transition_yellow" end
|
147
134
|
|
148
|
-
|
149
|
-
|
150
|
-
}
|
135
|
+
on_exit :green do |event| called << 'on_exit_green' end
|
136
|
+
on_exit :yellow do |event| called << "on_exit_yellow" end
|
151
137
|
end
|
152
138
|
|
153
139
|
expect(fsm.current).to eql(:green)
|
@@ -160,16 +146,14 @@ RSpec.describe FiniteMachine, ':if, :unless' do
|
|
160
146
|
it "allows to combine conditionals" do
|
161
147
|
conditions = []
|
162
148
|
|
163
|
-
fsm = FiniteMachine.
|
149
|
+
fsm = FiniteMachine.new do
|
164
150
|
initial :green
|
165
151
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
event :stop, :yellow => :red
|
172
|
-
}
|
152
|
+
event :slow, :green => :yellow,
|
153
|
+
if: [ -> { conditions << 'first_if'; return true },
|
154
|
+
-> { conditions << 'second_if'; return true}],
|
155
|
+
unless: -> { conditions << 'first_unless'; return true }
|
156
|
+
event :stop, :yellow => :red
|
173
157
|
end
|
174
158
|
|
175
159
|
expect(fsm.current).to eql(:green)
|
@@ -186,15 +170,11 @@ RSpec.describe FiniteMachine, ':if, :unless' do
|
|
186
170
|
it "specifies :if and :unless" do
|
187
171
|
car = Car.new
|
188
172
|
|
189
|
-
fsm = FiniteMachine.
|
173
|
+
fsm = FiniteMachine.new(car) do
|
190
174
|
initial :neutral
|
191
175
|
|
192
|
-
|
193
|
-
|
194
|
-
events {
|
195
|
-
event :start, :neutral => :one, if: proc {|_car| _car.engine_on? }
|
196
|
-
event :shift, :one => :two
|
197
|
-
}
|
176
|
+
event :start, :neutral => :one, if: proc {|_car| _car.engine_on? }
|
177
|
+
event :shift, :one => :two
|
198
178
|
end
|
199
179
|
car.turn_engine_off
|
200
180
|
expect(car.engine_on?).to be false
|
@@ -212,18 +192,14 @@ RSpec.describe FiniteMachine, ':if, :unless' do
|
|
212
192
|
it "passes arguments to the scope" do
|
213
193
|
car = Car.new
|
214
194
|
|
215
|
-
fsm = FiniteMachine.
|
195
|
+
fsm = FiniteMachine.new(car) do
|
216
196
|
initial :neutral
|
217
197
|
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
event :start, :neutral => :one, if: proc { |_car, state|
|
222
|
-
_car.engine_on = state
|
223
|
-
_car.engine_on?
|
224
|
-
}
|
225
|
-
event :shift, :one => :two
|
198
|
+
event :start, :neutral => :one, if: proc { |_car, state|
|
199
|
+
_car.engine_on = state
|
200
|
+
_car.engine_on?
|
226
201
|
}
|
202
|
+
event :shift, :one => :two
|
227
203
|
end
|
228
204
|
fsm.start(false)
|
229
205
|
expect(fsm.current).to eql(:neutral)
|
@@ -236,15 +212,11 @@ RSpec.describe FiniteMachine, ':if, :unless' do
|
|
236
212
|
it "specifies :if and :unless" do
|
237
213
|
car = Car.new
|
238
214
|
|
239
|
-
fsm = FiniteMachine.
|
215
|
+
fsm = FiniteMachine.new(car) do
|
240
216
|
initial :neutral
|
241
217
|
|
242
|
-
|
243
|
-
|
244
|
-
events {
|
245
|
-
event :start, :neutral => :one, if: :engine_on?
|
246
|
-
event :shift, :one => :two
|
247
|
-
}
|
218
|
+
event :start, :neutral => :one, if: :engine_on?
|
219
|
+
event :shift, :one => :two
|
248
220
|
end
|
249
221
|
car.turn_engine_off
|
250
222
|
expect(car.engine_on?).to be false
|
@@ -264,15 +236,11 @@ RSpec.describe FiniteMachine, ':if, :unless' do
|
|
264
236
|
it "specifies :if and :unless" do
|
265
237
|
car = Car.new
|
266
238
|
|
267
|
-
fsm = FiniteMachine.
|
239
|
+
fsm = FiniteMachine.new(car) do
|
268
240
|
initial :neutral
|
269
241
|
|
270
|
-
|
271
|
-
|
272
|
-
events {
|
273
|
-
event :start, :neutral => :one, if: "engine_on?"
|
274
|
-
event :shift, :one => :two
|
275
|
-
}
|
242
|
+
event :start, :neutral => :one, if: "engine_on?"
|
243
|
+
event :shift, :one => :two
|
276
244
|
end
|
277
245
|
car.turn_engine_off
|
278
246
|
expect(car.engine_on?).to be false
|
@@ -291,16 +259,12 @@ RSpec.describe FiniteMachine, ':if, :unless' do
|
|
291
259
|
context 'when same event name' do
|
292
260
|
it "preservers conditions for the same named event" do
|
293
261
|
bug = Bug.new
|
294
|
-
fsm = FiniteMachine.
|
262
|
+
fsm = FiniteMachine.new(bug) do
|
295
263
|
initial :initial
|
296
264
|
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
event :bump, :initial => :low
|
301
|
-
event :bump, :low => :medium, if: :pending?
|
302
|
-
event :bump, :medium => :high
|
303
|
-
}
|
265
|
+
event :bump, :initial => :low
|
266
|
+
event :bump, :low => :medium, if: :pending?
|
267
|
+
event :bump, :medium => :high
|
304
268
|
end
|
305
269
|
expect(fsm.current).to eq(:initial)
|
306
270
|
fsm.bump
|
@@ -310,29 +274,26 @@ RSpec.describe FiniteMachine, ':if, :unless' do
|
|
310
274
|
end
|
311
275
|
|
312
276
|
it "allows for static choice based on branching condition" do
|
313
|
-
fsm = FiniteMachine.
|
277
|
+
fsm = FiniteMachine.new do
|
314
278
|
initial :company_form
|
315
279
|
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
event :next, :company_form => :official_form, if: -> { true }
|
320
|
-
}
|
280
|
+
event :next, :company_form => :agreement_form, if: -> { false }
|
281
|
+
event :next, :company_form => :promo_form, if: -> { false }
|
282
|
+
event :next, :company_form => :official_form, if: -> { true }
|
321
283
|
end
|
284
|
+
|
322
285
|
expect(fsm.current).to eq(:company_form)
|
323
286
|
fsm.next
|
324
287
|
expect(fsm.current).to eq(:official_form)
|
325
288
|
end
|
326
289
|
|
327
290
|
it "allows for dynamic choice based on branching condition" do
|
328
|
-
fsm = FiniteMachine.
|
291
|
+
fsm = FiniteMachine.new do
|
329
292
|
initial :company_form
|
330
293
|
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
event :next, :company_form => :official_form, if: proc { |_, a| a > 1 }
|
335
|
-
}
|
294
|
+
event :next, :company_form => :agreement_form, if: proc { |_, a| a < 1 }
|
295
|
+
event :next, :company_form => :promo_form, if: proc { |_, a| a == 1 }
|
296
|
+
event :next, :company_form => :official_form, if: proc { |_, a| a > 1 }
|
336
297
|
end
|
337
298
|
expect(fsm.current).to eq(:company_form)
|
338
299
|
|