davidlee-state-fu 0.3.1 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. data/README.textile +124 -34
  2. data/Rakefile +36 -30
  3. data/lib/no_stdout.rb +1 -1
  4. data/lib/state-fu.rb +9 -8
  5. data/lib/state_fu/active_support_lite/array/access.rb +12 -5
  6. data/lib/state_fu/active_support_lite/array/conversions.rb +10 -4
  7. data/lib/state_fu/active_support_lite/array/extract_options.rb +5 -4
  8. data/lib/state_fu/active_support_lite/array/grouping.rb +7 -4
  9. data/lib/state_fu/active_support_lite/array/random_access.rb +4 -3
  10. data/lib/state_fu/active_support_lite/array/wrapper.rb +4 -3
  11. data/lib/state_fu/active_support_lite/array.rb +3 -1
  12. data/lib/state_fu/active_support_lite/blank.rb +18 -9
  13. data/lib/state_fu/active_support_lite/cattr_reader.rb +4 -1
  14. data/lib/state_fu/active_support_lite/keys.rb +8 -3
  15. data/lib/state_fu/active_support_lite/misc.rb +6 -4
  16. data/lib/state_fu/active_support_lite/module/delegation.rb +130 -0
  17. data/lib/state_fu/active_support_lite/module.rb +1 -0
  18. data/lib/state_fu/active_support_lite/object.rb +5 -2
  19. data/lib/state_fu/active_support_lite/string.rb +6 -1
  20. data/lib/state_fu/active_support_lite/symbol.rb +2 -1
  21. data/lib/state_fu/applicable.rb +41 -0
  22. data/lib/state_fu/{helper.rb → arrays.rb} +45 -121
  23. data/lib/state_fu/binding.rb +136 -159
  24. data/lib/state_fu/core_ext.rb +78 -10
  25. data/lib/state_fu/event.rb +112 -48
  26. data/lib/state_fu/exceptions.rb +80 -34
  27. data/lib/state_fu/executioner.rb +149 -0
  28. data/lib/state_fu/has_options.rb +16 -0
  29. data/lib/state_fu/hooks.rb +21 -16
  30. data/lib/state_fu/interface.rb +80 -83
  31. data/lib/state_fu/lathe.rb +361 -148
  32. data/lib/state_fu/logger.rb +122 -45
  33. data/lib/state_fu/machine.rb +60 -32
  34. data/lib/state_fu/method_factory.rb +180 -72
  35. data/lib/state_fu/methodical.rb +17 -0
  36. data/lib/state_fu/persistence/active_record.rb +6 -1
  37. data/lib/state_fu/persistence/attribute.rb +1 -0
  38. data/lib/state_fu/persistence/base.rb +8 -6
  39. data/lib/state_fu/persistence.rb +94 -23
  40. data/lib/state_fu/sprocket.rb +26 -11
  41. data/lib/state_fu/state.rb +8 -27
  42. data/lib/state_fu/transition.rb +207 -98
  43. data/lib/state_fu/transition_query.rb +214 -0
  44. data/lib/state_fu.rb +1 -0
  45. data/lib/tasks/spec_last.rake +46 -0
  46. data/lib/tasks/state_fu.rake +57 -0
  47. data/lib/vizier.rb +61 -61
  48. data/spec/custom_formatter.rb +49 -0
  49. data/spec/features/binding_and_transition_helper_mixin_spec.rb +2 -2
  50. data/spec/features/method_missing_only_once_spec.rb +28 -0
  51. data/spec/features/not_requirements_spec.rb +83 -46
  52. data/spec/features/plotter_spec.rb +97 -0
  53. data/spec/features/shared_log_spec.rb +7 -0
  54. data/spec/features/singleton_machine_spec.rb +39 -0
  55. data/spec/features/state_and_array_options_accessor_spec.rb +1 -1
  56. data/spec/features/{transition_boolean_comparison.rb → transition_boolean_comparison_spec.rb} +29 -18
  57. data/spec/helper.rb +6 -117
  58. data/spec/integration/active_record_persistence_spec.rb +18 -4
  59. data/spec/integration/binding_extension_spec.rb +1 -1
  60. data/spec/integration/class_accessor_spec.rb +49 -59
  61. data/spec/integration/event_definition_spec.rb +20 -20
  62. data/spec/integration/example_01_document_spec.rb +13 -8
  63. data/spec/integration/example_02_string_spec.rb +3 -2
  64. data/spec/integration/instance_accessor_spec.rb +16 -19
  65. data/spec/integration/lathe_extension_spec.rb +2 -2
  66. data/spec/integration/machine_duplication_spec.rb +59 -37
  67. data/spec/integration/relaxdb_persistence_spec.rb +6 -3
  68. data/spec/integration/requirement_reflection_spec.rb +66 -57
  69. data/spec/integration/state_definition_spec.rb +72 -66
  70. data/spec/integration/transition_spec.rb +169 -173
  71. data/spec/spec.opts +5 -3
  72. data/spec/spec_helper.rb +132 -0
  73. data/spec/state_fu_spec.rb +870 -0
  74. data/spec/units/binding_spec.rb +33 -22
  75. data/spec/units/event_spec.rb +3 -22
  76. data/spec/units/exceptions_spec.rb +7 -0
  77. data/spec/units/lathe_spec.rb +7 -7
  78. data/spec/units/machine_spec.rb +67 -75
  79. data/spec/units/method_factory_spec.rb +55 -48
  80. data/spec/units/sprocket_spec.rb +5 -7
  81. data/spec/units/state_spec.rb +33 -24
  82. metadata +31 -19
  83. data/lib/state_fu/active_support_lite/inheritable_attributes.rb +0 -1
  84. data/lib/state_fu/fu_space.rb +0 -51
  85. data/lib/state_fu/mock_transition.rb +0 -38
  86. data/spec/BDD/plotter_spec.rb +0 -115
  87. data/spec/integration/dynamic_requirement_spec.rb +0 -160
  88. data/spec/integration/ex_machine_for_accounts_spec.rb +0 -79
  89. data/spec/integration/sanity_spec.rb +0 -31
  90. data/spec/units/fu_space_spec.rb +0 -95
@@ -6,8 +6,17 @@ describe "Transition requirement reflection" do
6
6
 
7
7
  before do
8
8
  reset!
9
- make_pristine_class("Klass")
10
- @machine = Klass.machine do
9
+ make_pristine_class("Klass") do
10
+ def turban?; false end
11
+ def arrest_warrant?; false end
12
+ def papers_in_order?; true end
13
+ def papers_in_order?; true end
14
+ def money_for_bribe?; true end
15
+ def spacesuit?; true end
16
+ def plane_ticket?; true end
17
+ def fuel?; true end
18
+ end
19
+ @machine = Klass.state_fu_machine do
11
20
  state :soviet_russia do
12
21
  requires( :papers_in_order?, :on => [:entry, :exit] )
13
22
  requires( :money_for_bribe?, :on => [:entry, :exit] )
@@ -38,29 +47,23 @@ describe "Transition requirement reflection" do
38
47
 
39
48
  end # machine
40
49
  @obj = Klass.new()
41
- stub( @obj ).papers_in_order? { true }
42
- stub( @obj ).money_for_bribe? { true }
43
- stub( @obj ).no_turban? { true }
44
- stub( @obj ).no_arrest_warrant? { true }
45
- stub( @obj ).spacesuit? { true }
46
- stub( @obj ).plane_ticket? { true }
47
- stub( @obj ).fuel? { true }
48
50
  end # before
49
51
 
50
52
  describe "transition.valid? / transition.requirements_met?" do
51
53
  it "should be true if all requirements are met (return truth)" do
52
- @obj.state_fu.next_states[:moon].entry_requirements.should == [:spacesuit?]
53
- @obj.state_fu.evaluate_requirement_with_args(:spacesuit?).should == true
54
- @obj.fly_spaceship?(:moon).should == true
55
- @obj.fly_spaceship(:moon).requirements_met?.should == true
56
- @obj.fly_spaceship(:moon).should be_valid
54
+ #@obj.state_fu.next_states[:moon].entry_requirements.should == [:spacesuit?]
55
+
56
+ #@obj.state_fu.fireable?([:fly_spaceship,:moon]).should == true
57
+ @obj.can_fly_spaceship?(:moon).should == true
58
+ #@obj.fly_spaceship(:moon).requirements_met?.should == true
59
+ #@obj.fly_spaceship(:moon).should be_valid
57
60
  end
58
61
 
59
62
  it "should be false if not all requirements are met" do
60
63
  stub( @obj ).spacesuit?() { false }
61
64
  @obj.state_fu.next_states[:moon].entry_requirements.should == [:spacesuit?]
62
- @obj.state_fu.evaluate_requirement_with_args(:spacesuit?).should == false
63
- @obj.fly_spaceship?(:moon).should == false
65
+ # @obj.state_fu.evaluate(:spacesuit?).should == false
66
+ @obj.can_fly_spaceship?(:moon).should == false
64
67
  @obj.fly_spaceship(:moon).requirements_met?.should == false
65
68
  @obj.fly_spaceship(:moon).should_not be_valid
66
69
  end
@@ -68,11 +71,11 @@ describe "Transition requirement reflection" do
68
71
 
69
72
  describe "flying from russia to america without one's affairs in order while wearing a turban" do
70
73
  before do
71
- mock( @obj ).us_visa?() { false }
72
- mock( @obj ).no_turban?() { false }
73
- mock( @obj ).no_arrest_warrant?() { false }
74
- mock( @obj ).money_for_bribe?() { false }
75
- mock( @obj ).papers_in_order?() { false }
74
+ mock( @obj ).us_visa?(anything) { false }
75
+ mock( @obj ).no_turban?(anything) { false }
76
+ mock( @obj ).no_arrest_warrant?(anything) { false }
77
+ mock( @obj ).money_for_bribe?(anything) { false }
78
+ mock( @obj ).papers_in_order?(anything) { false }
76
79
  end
77
80
 
78
81
  describe "when no messages are supplied for the requirements" do
@@ -88,14 +91,15 @@ describe "Transition requirement reflection" do
88
91
 
89
92
  describe "given transition.unmet_requirement_messages" do
90
93
  it "should return a list of nils" do
91
- @obj.state_fu.catch_plane(:america).unmet_requirement_messages.should == [nil,nil,nil,nil,nil]
94
+ @obj.state_fu.catch_plane(:america).unmet_requirement_messages.should ==
95
+ [:papers_in_order?, :money_for_bribe?, :no_turban?, :us_visa?, :no_arrest_warrant?]
92
96
  end
93
97
  end # unmet_requirement_messages
94
98
  end
95
99
 
96
100
  describe "when a message is supplied for the money_for_bribe? entry requirement" do
97
101
  before do
98
- Klass.machine do
102
+ Klass.state_fu_machine do
99
103
  state :soviet_russia do
100
104
  requires( :money_for_bribe?, :message => "This guard is thirsty! Do you have anything to declare?" )
101
105
  end
@@ -114,13 +118,15 @@ describe "Transition requirement reflection" do
114
118
 
115
119
  describe "given transition.unmet_requirement_messages" do
116
120
  it "should contain a list of nils plus the requirement message for money_for_bribe? as a string" do
117
- @obj.state_fu.catch_plane(:america).unmet_requirement_messages.should == [ nil,
118
- "This guard is thirsty! Do you have anything to declare?",
119
- nil,
120
- nil,
121
- nil ]
121
+ @obj.state_fu.catch_plane(:america).unmet_requirement_messages.should ==
122
+ [:papers_in_order?,
123
+ "This guard is thirsty! Do you have anything to declare?",
124
+ :no_turban?,
125
+ :us_visa?,
126
+ :no_arrest_warrant?]
122
127
  end
123
128
  end
129
+
124
130
  end
125
131
  end # flying with a turban
126
132
 
@@ -131,8 +137,8 @@ describe "Transition requirement reflection" do
131
137
 
132
138
  describe "when a message is supplied for the requirement" do
133
139
  it "should contain a list of the requirement failure messages as strings" do
134
- mock( @obj ).spacesuit?() { false }
135
- mock( @obj ).fuel?() { false }
140
+ mock( @obj ).spacesuit?(anything) { false }
141
+ mock( @obj ).fuel?(anything) { false }
136
142
  @obj.state_fu.fly_spaceship(:moon).unmet_requirements.should == [:spacesuit?, :fuel?]
137
143
  end
138
144
  end
@@ -154,9 +160,10 @@ describe "Transition requirement reflection" do
154
160
  messages = t.unmet_requirement_messages
155
161
  messages.should be_kind_of( Array )
156
162
  messages.length.should == 2
157
- messages.compact.length.should == 1
158
- messages.compact.first.should be_kind_of( String )
159
- messages.compact.first.should == @msg
163
+ messages.strings.length.should == 1
164
+ messages.symbols.length.should == 1
165
+ messages.strings.first.should == @msg
166
+ messages.symbols.first.should == :fuel?
160
167
  end
161
168
  end
162
169
 
@@ -177,15 +184,16 @@ describe "Transition requirement reflection" do
177
184
  messages = t.unmet_requirement_messages
178
185
  messages.should be_kind_of( Array )
179
186
  messages.length.should == 2
180
- messages.compact.length.should == 1
181
- messages.compact.first.should be_kind_of( String )
182
- messages.compact.first.should == "I am a StateFu::Transition and I fail it"
187
+ messages.strings.length.should == 1
188
+ messages.strings.first.should be_kind_of( String )
189
+ messages.strings.first.should == "I am a StateFu::Transition and I fail it"
190
+ messages.symbols.first.should == :fuel?
183
191
  end
184
192
  end # arity 1
185
193
 
186
194
  describe "when the arity of the proc is 0" do
187
195
  before do
188
- @msg = lambda { "I am a #{self.class} and I fail it" }
196
+ @msg = lambda { "No #{t.target.name} for you!" }
189
197
  @machine.requirement_messages[:spacesuit?] = @msg
190
198
  end
191
199
 
@@ -195,52 +203,53 @@ describe "Transition requirement reflection" do
195
203
  messages = t.unmet_requirement_messages
196
204
  messages.should be_kind_of( Array )
197
205
  messages.length.should == 2
198
- messages.compact.length.should == 1
199
- messages.compact.first.should be_kind_of( String )
200
- messages.compact.first.should == "I am a StateFu::Transition and I fail it"
206
+ messages.strings.length.should == 1
207
+ messages.strings.first.should be_kind_of( String )
208
+ messages.strings.first.should == "No moon for you!"
209
+ messages.symbols.first.should == :fuel?
201
210
  end
202
211
  end # arity 1
203
212
 
204
213
  end # 1 proc msg of 2
205
214
  describe "when a symbol message is defined for one of two unmet_requirements" do
206
215
  before do
207
- stub( @obj ).spacesuit?() { false }
208
- stub( @obj ).fuel?() { false }
216
+
209
217
  @machine.requirement_messages[:spacesuit?] = :no_spacesuit_msg_method
210
218
  Klass.class_eval do
211
219
  attr_accessor :arg
212
-
213
- def no_spacesuit_msg_method( t )
214
- self.arg = t
215
- raise ArgumentError unless t.is_a?( StateFu::Transition )
220
+ def spacesuit?; false end
221
+ def fuel?; false end
222
+
223
+ def no_spacesuit_msg_method(t)
216
224
  "You can't go to the #{t.target.name} without a spacesuit!"
217
225
  end
226
+
218
227
  end
219
228
  end
220
229
 
221
230
  describe "when there is no named proc on the machine matching the symbol" do
222
231
 
223
- it "should call the method on @obj given transition.evaluate_named_proc_or_method() with the method name" do
224
- @obj.method( :no_spacesuit_msg_method ).arity.should == 1
232
+ it "should call the method on @obj given transition.evaluate() with the method name" do
225
233
  t = @obj.state_fu.fly_spaceship(:moon)
226
- x = @obj.state_fu.evaluate_named_proc_or_method(:no_spacesuit_msg_method, t)
227
- @obj.arg.should == t
228
- x.should =~ /You can't go to the moon/
234
+ @obj.arg.should == nil
235
+ t.unmet_requirement_messages.should == ["You can't go to the moon without a spacesuit!", :fuel?]
229
236
  end
230
237
 
231
238
  it "should call t.evaluate_named_proc_or_method(:no_spacesuit_msg_method)" do
232
239
  t = @obj.state_fu.fly_spaceship(:moon)
233
240
  t.unmet_requirements.length.should == 2
234
- mock( t ).evaluate_named_proc_or_method(:no_spacesuit_msg_method, t) { :my_string }
241
+ stub( t ).evaluate( anything) { false }
242
+
243
+ mock( t ).evaluate(:no_spacesuit_msg_method){ ":)" }
235
244
  messages = t.unmet_requirement_messages
236
- messages.should include(:my_string )
245
+ messages.should include( ":)" )
237
246
  end
238
247
 
239
248
  it "should call the method on @obj with the name of the symbol, passing it a transition" do
240
249
  t = @obj.state_fu.fly_spaceship(:moon)
241
250
  t.unmet_requirements.length.should == 2
242
251
  messages = t.unmet_requirement_messages
243
- @obj.arg.should == t
252
+ @obj.arg.should == nil
244
253
  end
245
254
 
246
255
  it "should return the result of the method execution as the message" do
@@ -248,9 +257,9 @@ describe "Transition requirement reflection" do
248
257
  t.unmet_requirements.length.should == 2
249
258
  messages = t.unmet_requirement_messages
250
259
  messages.length.should == 2
251
- messages.compact.length.should == 1
252
- @obj.arg.should == t
253
- messages.compact[0].should == "You can't go to the moon without a spacesuit!"
260
+ messages.strings.length.should == 1
261
+ #@obj.arg.should == t
262
+ messages.strings[0].should == "You can't go to the moon without a spacesuit!"
254
263
  end
255
264
  end # no named proc
256
265
  end # symbol message
@@ -14,37 +14,37 @@ describe "Adding states to a Machine" do
14
14
  end
15
15
 
16
16
  it "should allow me to call machine() { state(:egg) }" do
17
- lambda {Klass.machine(){ state :egg } }.should_not raise_error()
17
+ lambda {Klass.state_fu_machine(){ state :egg } }.should_not raise_error()
18
18
  end
19
19
 
20
20
  describe "having called machine() { state(:egg) }" do
21
21
 
22
22
  before(:each) do
23
- Klass.machine(){ state :egg }
23
+ Klass.state_fu_machine(){ state :egg }
24
24
  end
25
25
 
26
26
  it "should return [:egg] given machine.state_names" do
27
- Klass.machine.should respond_to(:state_names)
28
- Klass.machine.state_names.should == [:egg]
27
+ Klass.state_fu_machine.should respond_to(:state_names)
28
+ Klass.state_fu_machine.state_names.should == [:egg]
29
29
  end
30
30
 
31
31
  it "should return [<StateFu::State @name=:egg>] given machine.states" do
32
- Klass.machine.should respond_to(:states)
33
- Klass.machine.states.length.should == 1
34
- Klass.machine.states.first.should be_kind_of( StateFu::State )
35
- Klass.machine.states.first.name.should == :egg
32
+ Klass.state_fu_machine.should respond_to(:states)
33
+ Klass.state_fu_machine.states.length.should == 1
34
+ Klass.state_fu_machine.states.first.should be_kind_of( StateFu::State )
35
+ Klass.state_fu_machine.states.first.name.should == :egg
36
36
  end
37
37
 
38
38
  it "should return :egg given machine.states.first.name" do
39
- Klass.machine.should respond_to(:states)
40
- Klass.machine.states.length.should == 1
41
- Klass.machine.states.first.should respond_to(:name)
42
- Klass.machine.states.first.name.should == :egg
39
+ Klass.state_fu_machine.should respond_to(:states)
40
+ Klass.state_fu_machine.states.length.should == 1
41
+ Klass.state_fu_machine.states.first.should respond_to(:name)
42
+ Klass.state_fu_machine.states.first.name.should == :egg
43
43
  end
44
44
 
45
45
  it "should return a <StateFu::State @name=:egg> given machine.states[:egg]" do
46
- Klass.machine.should respond_to(:states)
47
- result = Klass.machine.states[:egg]
46
+ Klass.state_fu_machine.should respond_to(:states)
47
+ result = Klass.state_fu_machine.states[:egg]
48
48
  result.should_not be_nil
49
49
  result.should be_kind_of( StateFu::State )
50
50
  result.name.should == :egg
@@ -52,22 +52,22 @@ describe "Adding states to a Machine" do
52
52
 
53
53
 
54
54
  it "should allow me to call machine(){ state(:chick) }" do
55
- lambda {Klass.machine(){ state :chick } }.should_not raise_error()
55
+ lambda {Klass.state_fu_machine(){ state :chick } }.should_not raise_error()
56
56
  end
57
57
 
58
58
  describe "having called machine() { state(:chick) }" do
59
59
  before do
60
- Klass.machine() { state :chick }
60
+ Klass.state_fu_machine() { state :chick }
61
61
  end
62
62
 
63
63
  it "should return [:egg] given machine.state_names" do
64
- Klass.machine.should respond_to(:state_names)
65
- Klass.machine.state_names.should == [:egg, :chick]
64
+ Klass.state_fu_machine.should respond_to(:state_names)
65
+ Klass.state_fu_machine.state_names.should == [:egg, :chick]
66
66
  end
67
67
 
68
68
  it "should return a <StateFu::State @name=:chick> given machine.states[:egg]" do
69
- Klass.machine.should respond_to(:states)
70
- result = Klass.machine.states[:chick]
69
+ Klass.state_fu_machine.should respond_to(:states)
70
+ result = Klass.state_fu_machine.states[:chick]
71
71
  result.should_not be_nil
72
72
  result.should be_kind_of( StateFu::State )
73
73
  result.name.should == :chick
@@ -79,7 +79,7 @@ describe "Adding states to a Machine" do
79
79
 
80
80
  it "should yield the state to the block as |s|" do
81
81
  state = nil
82
- Klass.machine() do
82
+ Klass.state_fu_machine() do
83
83
  state(:bird) do |s|
84
84
  state = s
85
85
  end
@@ -94,14 +94,14 @@ describe "Adding states to a Machine" do
94
94
 
95
95
  it "should instance_eval the block as a StateFu::Lathe" do
96
96
  lathe = nil
97
- Klass.machine() do
97
+ Klass.state_fu_machine() do
98
98
  state(:bird) do
99
99
  lathe = self
100
100
  end
101
101
  end
102
102
  lathe.should be_kind_of(StateFu::Lathe)
103
- lathe.sprocket.should be_kind_of(StateFu::State)
104
- lathe.sprocket.name.should == :bird
103
+ lathe.state_or_event.should be_kind_of(StateFu::State)
104
+ lathe.state_or_event.name.should == :bird
105
105
  end
106
106
 
107
107
  end
@@ -109,10 +109,10 @@ describe "Adding states to a Machine" do
109
109
  describe "calling state(:bird) consecutive times" do
110
110
 
111
111
  it "should yield the same state each time" do
112
- Klass.machine() { state :bird }
113
- bird_1 = Klass.machine.states[:bird]
114
- Klass.machine() { state :bird }
115
- bird_2 = Klass.machine.states[:bird]
112
+ Klass.state_fu_machine() { state :bird }
113
+ bird_1 = Klass.state_fu_machine.states[:bird]
114
+ Klass.state_fu_machine() { state :bird }
115
+ bird_2 = Klass.state_fu_machine.states[:bird]
116
116
  bird_1.should == bird_2
117
117
  end
118
118
 
@@ -122,56 +122,62 @@ describe "Adding states to a Machine" do
122
122
  describe "calling machine() { states(:egg, :chick, :bird, :poultry => true) }" do
123
123
 
124
124
  it "should create 3 states" do
125
- Klass.machine().should be_empty
126
- Klass.machine() { states(:egg, :chick, :bird, :poultry => true) }
127
- Klass.machine().state_names().should == [:egg, :chick, :bird]
128
- Klass.machine().states.length.should == 3
129
- Klass.machine().states.map(&:name).should == [:egg, :chick, :bird]
130
- Klass.machine().states().each do |s|
125
+ Klass.state_fu_machine().should be_empty
126
+ Klass.state_fu_machine() { states(:egg, :chick, :bird, :poultry => true) }
127
+ Klass.state_fu_machine().state_names().should == [:egg, :chick, :bird]
128
+ Klass.state_fu_machine().states.length.should == 3
129
+ Klass.state_fu_machine().states.map(&:name).should == [:egg, :chick, :bird]
130
+ Klass.state_fu_machine().states().each do |s|
131
131
  s.options[:poultry].should be_true
132
132
  s.should be_kind_of(StateFu::State)
133
133
  end
134
+ end
134
135
 
135
- describe "merging options" do
136
- it "should merge options when states are mentioned more than once" do
137
- StateFu::FuSpace.reset!
138
- Klass.machine() { states(:egg, :chick, :bird, :poultry => true) }
139
- machine = Klass.machine
140
- machine.states.length.should == 3
141
-
142
- # make sure they're the same states
143
- states_1 = machine.states
144
- Klass.machine(){ states( :egg, :chick, :bird, :covering => 'feathers')}
145
- states_1.should == machine.states
146
-
147
- # ensure options were merged
148
- machine.states().each do |s|
149
- s.options[:poultry].should be_true
150
- s.options[:covering].should == 'feathers'
151
- s.should be_kind_of(StateFu::State)
152
- end
136
+ describe "merging options" do
137
+ before do
138
+ make_pristine_class('Klass')
139
+ end
140
+ it "should merge options when states are mentioned more than once" do
141
+ # reset!
142
+ machine = Klass.state_fu_machine
143
+ machine.states.length.should == 0
144
+ Klass.state_fu_machine() { states(:egg, :chick, :bird, :poultry => true) }
145
+ machine = Klass.state_fu_machine
146
+ machine.states.length.should == 3
147
+
148
+ # make sure they're the same states
149
+ states_1 = machine.states
150
+ Klass.state_fu_machine(){ states( :egg, :chick, :bird, :covering => 'feathers')}
151
+ states_1.should == machine.states
152
+
153
+ # ensure options were merged
154
+ machine.states().each do |s|
155
+ s.options[:poultry].should be_true
156
+ s.options[:covering].should == 'feathers'
157
+ s.should be_kind_of(StateFu::State)
153
158
  end
154
159
  end
155
160
  end
156
161
  end
162
+ end
157
163
 
158
- describe "adding events inside a state block" do
159
- before do
160
- @lambda = lambda{ Klass.machine(){ state(:egg){ event(:hatch, :to => :chick) }}}
161
- end
164
+ describe "adding events inside a state block" do
165
+ before do
166
+ @lambda = lambda{ Klass.state_fu_machine(){ state(:egg){ event(:hatch, :to => :chick) }}}
167
+ end
162
168
 
163
- it "should not throw an error" do
164
- @lambda.should_not raise_error
165
- end
169
+ it "should not throw an error" do
170
+ @lambda.should_not raise_error
171
+ end
166
172
 
167
- describe "Klass.machine(){ state(:egg){ event(:hatch, :to => :chick) }}}" do
168
- before() do
169
- Klass.machine(){ state(:egg){ event(:hatch, :to => :chick) }}
170
- end
171
- it "should add an event :hatch to the machine" do
172
- end
173
+ describe "Klass.state_fu_machine(){ state(:egg){ event(:hatch, :to => :chick) }}}" do
174
+ before() do
175
+ Klass.state_fu_machine(){ state(:egg){ event(:hatch, :to => :chick) }}
176
+ end
177
+ it "should add an event :hatch to the machine" do
173
178
  end
174
179
  end
175
-
176
180
  end
177
181
 
182
+
183
+