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.
Files changed (106) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +34 -0
  3. data/README.md +564 -569
  4. data/Rakefile +5 -1
  5. data/benchmarks/memory_profile.rb +11 -0
  6. data/benchmarks/memory_usage.rb +16 -9
  7. data/finite_machine.gemspec +10 -3
  8. data/lib/finite_machine.rb +34 -46
  9. data/lib/finite_machine/async_call.rb +5 -21
  10. data/lib/finite_machine/callable.rb +4 -4
  11. data/lib/finite_machine/catchable.rb +4 -2
  12. data/lib/finite_machine/choice_merger.rb +19 -19
  13. data/lib/finite_machine/const.rb +16 -0
  14. data/lib/finite_machine/definition.rb +2 -2
  15. data/lib/finite_machine/dsl.rb +66 -149
  16. data/lib/finite_machine/env.rb +4 -2
  17. data/lib/finite_machine/event_definition.rb +7 -15
  18. data/lib/finite_machine/{events_chain.rb → events_map.rb} +39 -51
  19. data/lib/finite_machine/hook_event.rb +60 -61
  20. data/lib/finite_machine/hooks.rb +44 -36
  21. data/lib/finite_machine/listener.rb +2 -2
  22. data/lib/finite_machine/logger.rb +5 -4
  23. data/lib/finite_machine/message_queue.rb +39 -30
  24. data/lib/finite_machine/observer.rb +55 -37
  25. data/lib/finite_machine/safety.rb +12 -10
  26. data/lib/finite_machine/state_definition.rb +3 -5
  27. data/lib/finite_machine/state_machine.rb +83 -64
  28. data/lib/finite_machine/state_parser.rb +51 -79
  29. data/lib/finite_machine/subscribers.rb +1 -1
  30. data/lib/finite_machine/threadable.rb +3 -1
  31. data/lib/finite_machine/transition.rb +30 -31
  32. data/lib/finite_machine/transition_builder.rb +23 -32
  33. data/lib/finite_machine/transition_event.rb +12 -11
  34. data/lib/finite_machine/two_phase_lock.rb +3 -1
  35. data/lib/finite_machine/undefined_transition.rb +5 -6
  36. data/lib/finite_machine/version.rb +2 -2
  37. data/spec/integration/system_spec.rb +36 -38
  38. data/spec/performance/benchmark_spec.rb +13 -21
  39. data/spec/unit/alias_target_spec.rb +22 -41
  40. data/spec/unit/async_callbacks_spec.rb +8 -13
  41. data/spec/unit/auto_methods_spec.rb +44 -0
  42. data/spec/unit/callable/call_spec.rb +1 -3
  43. data/spec/unit/callbacks_spec.rb +372 -463
  44. data/spec/unit/can_spec.rb +13 -23
  45. data/spec/unit/cancel_callbacks_spec.rb +46 -0
  46. data/spec/unit/choice_spec.rb +105 -141
  47. data/spec/unit/define_spec.rb +31 -31
  48. data/spec/unit/definition_spec.rb +24 -41
  49. data/spec/unit/event_names_spec.rb +6 -10
  50. data/spec/unit/events_map/add_spec.rb +23 -0
  51. data/spec/unit/events_map/choice_transition_spec.rb +25 -0
  52. data/spec/unit/events_map/clear_spec.rb +13 -0
  53. data/spec/unit/events_map/events_spec.rb +16 -0
  54. data/spec/unit/events_map/inspect_spec.rb +22 -0
  55. data/spec/unit/{events_chain → events_map}/match_transition_spec.rb +12 -14
  56. data/spec/unit/{events_chain → events_map}/move_to_spec.rb +14 -17
  57. data/spec/unit/events_map/states_for_spec.rb +17 -0
  58. data/spec/unit/events_spec.rb +91 -160
  59. data/spec/unit/handlers_spec.rb +34 -66
  60. data/spec/unit/hook_event/any_state_or_event_spec.rb +13 -0
  61. data/spec/unit/hook_event/build_spec.rb +1 -3
  62. data/spec/unit/hook_event/eql_spec.rb +1 -3
  63. data/spec/unit/hook_event/initialize_spec.rb +2 -4
  64. data/spec/unit/hook_event/notify_spec.rb +2 -4
  65. data/spec/unit/hooks/clear_spec.rb +1 -1
  66. data/spec/unit/hooks/{call_spec.rb → find_spec.rb} +4 -9
  67. data/spec/unit/hooks/inspect_spec.rb +16 -8
  68. data/spec/unit/hooks/register_spec.rb +4 -9
  69. data/spec/unit/if_unless_spec.rb +76 -115
  70. data/spec/unit/initial_spec.rb +50 -82
  71. data/spec/unit/inspect_spec.rb +14 -9
  72. data/spec/unit/is_spec.rb +12 -18
  73. data/spec/unit/log_transitions_spec.rb +4 -10
  74. data/spec/unit/logger_spec.rb +1 -3
  75. data/spec/unit/{event_queue_spec.rb → message_queue_spec.rb} +15 -8
  76. data/spec/unit/new_spec.rb +50 -0
  77. data/spec/unit/respond_to_spec.rb +2 -6
  78. data/spec/unit/state_parser/parse_spec.rb +9 -12
  79. data/spec/unit/states_spec.rb +12 -18
  80. data/spec/unit/subscribers_spec.rb +1 -3
  81. data/spec/unit/target_spec.rb +60 -93
  82. data/spec/unit/terminated_spec.rb +15 -25
  83. data/spec/unit/transition/check_conditions_spec.rb +16 -15
  84. data/spec/unit/transition/inspect_spec.rb +6 -6
  85. data/spec/unit/transition/matches_spec.rb +5 -7
  86. data/spec/unit/transition/states_spec.rb +5 -7
  87. data/spec/unit/transition/to_state_spec.rb +5 -13
  88. data/spec/unit/trigger_spec.rb +5 -9
  89. data/spec/unit/undefined_transition/eql_spec.rb +1 -3
  90. metadata +86 -49
  91. data/.gitignore +0 -18
  92. data/.rspec +0 -5
  93. data/.travis.yml +0 -27
  94. data/Gemfile +0 -16
  95. data/assets/finite_machine_logo.png +0 -0
  96. data/lib/finite_machine/async_proxy.rb +0 -55
  97. data/spec/unit/async_events_spec.rb +0 -107
  98. data/spec/unit/events_chain/add_spec.rb +0 -25
  99. data/spec/unit/events_chain/cancel_transitions_spec.rb +0 -22
  100. data/spec/unit/events_chain/choice_transition_spec.rb +0 -28
  101. data/spec/unit/events_chain/clear_spec.rb +0 -15
  102. data/spec/unit/events_chain/events_spec.rb +0 -18
  103. data/spec/unit/events_chain/inspect_spec.rb +0 -24
  104. data/spec/unit/events_chain/states_for_spec.rb +0 -17
  105. data/spec/unit/hook_event/infer_default_name_spec.rb +0 -13
  106. 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
- # encoding: utf-8
2
-
3
- require 'spec_helper'
1
+ # frozen_string_literal: true
4
2
 
5
3
  RSpec.describe FiniteMachine::HookEvent, '#build' do
6
4
  it "builds action event" do
@@ -1,6 +1,4 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
1
+ # frozen_string_literal: true
4
2
 
5
3
  RSpec.describe FiniteMachine::HookEvent, 'eql?' do
6
4
  let(:name) { :green }
@@ -1,6 +1,4 @@
1
- # encoding: utf-8
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 { hook_event.name = :red }.to raise_error(RuntimeError)
21
+ expect(hook_event.frozen?).to eq(true)
24
22
  end
25
23
  end
@@ -1,8 +1,6 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
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,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  RSpec.describe FiniteMachine::Hooks, '#clear' do
4
4
  it "clears all registered hooks" do
@@ -1,13 +1,8 @@
1
- # encoding: utf-8
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.call(event_type, :foo) do |callback|
13
+ hooks[event_type][:foo].each do |callback|
19
14
  yielded << callback
20
15
  end
21
16
 
@@ -1,17 +1,25 @@
1
- # encoding: utf-8
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
- collection = {event => {yellow: [hook]}}
19
+ hooks_map = {event => {yellow: [hook]}}
20
+
12
21
  hooks.register(event, :yellow, hook)
13
22
 
14
- expect(hooks.inspect).to eql("<#FiniteMachine::Hooks:0x#{hooks.object_id.to_s(16)} @collection=#{collection}>")
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
- # encoding: utf-8
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.collection).to eq({event_type => {foo: [hook]}})
12
+ expect(hooks[event_type][:foo]).to eq([hook])
18
13
 
19
14
  hooks.unregister(event_type, :foo, hook)
20
- expect(hooks.collection).to eq({event_type => {foo: []}})
15
+ expect(hooks[event_type][:foo]).to eq([])
21
16
  end
22
17
  end
@@ -1,6 +1,4 @@
1
- # encoding: utf-8
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.define do
30
+ fsm = FiniteMachine.new do
33
31
  initial :red
34
32
 
35
- events {
36
- event :go, :red => :green,
37
- if: proc { |context| called << "cond_red_green(#{context})"; true}
38
- event :stop, from: :any do
39
- choice :red,
40
- if: proc { |context| called << "cond_any_red(#{context})"; true }
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.define do
57
+ fsm = FiniteMachine.new do
62
58
  initial :red
63
59
 
64
- events {
65
- event :go, :red => :green,
66
- if: proc { |_, a| called << "cond_red_green(#{a})"; true }
67
- event :stop, from: :any do
68
- choice :red,
69
- if: proc { |_, b| called << "cond_any_red(#{b})"; true }
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.define do
85
+ fsm = FiniteMachine.new do
92
86
  initial :green
93
87
 
94
- events {
95
- event :slow, :green => :yellow, if: -> { return false }
96
- event :stop, :yellow => :red
97
- }
88
+ event :slow, :green => :yellow, if: -> { return false }
89
+ event :stop, :yellow => :red
98
90
 
99
- callbacks {
100
- # generic callbacks
101
- on_enter do |event| called << 'on_enter' end
102
- on_transition do |event| called << 'on_transition' end
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
- # state callbacks
106
- on_enter :green do |event| called << 'on_enter_green' end
107
- on_enter :yellow do |event| called << "on_enter_yellow" end
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
- on_transition :green do |event| called << 'on_transition_green' end
110
- on_transition :yellow do |event| called << "on_transition_yellow" end
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
- on_exit :green do |event| called << 'on_exit_green' end
113
- on_exit :yellow do |event| called << "on_exit_yellow" end
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.define do
117
+ fsm = FiniteMachine.new do
128
118
  initial :green
129
119
 
130
- events {
131
- event :slow, :green => :yellow, unless: -> { true }
132
- event :stop, :yellow => :red
133
- }
120
+ event :slow, :green => :yellow, unless: -> { true }
121
+ event :stop, :yellow => :red
134
122
 
135
- callbacks {
136
- # generic callbacks
137
- on_enter do |event| called << 'on_enter' end
138
- on_transition do |event| called << 'on_transition' end
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
- # state callbacks
142
- on_enter :green do |event| called << 'on_enter_green' end
143
- on_enter :yellow do |event| called << "on_enter_yellow" end
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
- on_transition :green do |event| called << 'on_transition_green' end
146
- on_transition :yellow do |event| called << "on_transition_yellow" end
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
- on_exit :green do |event| called << 'on_exit_green' end
149
- on_exit :yellow do |event| called << "on_exit_yellow" end
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.define do
149
+ fsm = FiniteMachine.new do
164
150
  initial :green
165
151
 
166
- events {
167
- event :slow, :green => :yellow,
168
- if: [ -> { conditions << 'first_if'; return true },
169
- -> { conditions << 'second_if'; return true}],
170
- unless: -> { conditions << 'first_unless'; return true }
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.define do
173
+ fsm = FiniteMachine.new(car) do
190
174
  initial :neutral
191
175
 
192
- target car
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.define do
195
+ fsm = FiniteMachine.new(car) do
216
196
  initial :neutral
217
197
 
218
- target car
219
-
220
- events {
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.define do
215
+ fsm = FiniteMachine.new(car) do
240
216
  initial :neutral
241
217
 
242
- target car
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.define do
239
+ fsm = FiniteMachine.new(car) do
268
240
  initial :neutral
269
241
 
270
- target car
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.define do
262
+ fsm = FiniteMachine.new(bug) do
295
263
  initial :initial
296
264
 
297
- target bug
298
-
299
- events {
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.define do
277
+ fsm = FiniteMachine.new do
314
278
  initial :company_form
315
279
 
316
- events {
317
- event :next, :company_form => :agreement_form, if: -> { false }
318
- event :next, :company_form => :promo_form, if: -> { false }
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.define do
291
+ fsm = FiniteMachine.new do
329
292
  initial :company_form
330
293
 
331
- events {
332
- event :next, :company_form => :agreement_form, if: proc { |_, a| a < 1 }
333
- event :next, :company_form => :promo_form, if: proc { |_, a| a == 1 }
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