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
@@ -27,29 +27,27 @@ describe StateFu::Binding do
27
27
  before do
28
28
  reset!
29
29
  make_pristine_class('Klass')
30
- Klass.machine(){}
30
+ Klass.state_fu_machine(){}
31
31
  @obj = Klass.new()
32
32
  end
33
33
 
34
34
  describe "constructor" do
35
35
  before do
36
- mock( StateFu::FuSpace ).field_names() do
37
- {
38
- Klass => { :example => :example_field }
39
- }
36
+ mock(Klass).state_fu_field_names.at_most(1) do
37
+ { :example => :example_field }
40
38
  end
41
39
  end
42
40
 
43
41
  it "should create a new Binding given valid arguments" do
44
- b = StateFu::Binding.new( Klass.machine, @obj, :example )
42
+ b = StateFu::Binding.new( Klass.state_fu_machine, @obj, :example )
45
43
  b.should be_kind_of( StateFu::Binding )
46
44
  b.object.should == @obj
47
- b.machine.should == Klass.machine
45
+ b.machine.should == Klass.state_fu_machine
48
46
  b.method_name.should == :example
49
47
  end
50
48
 
51
49
  it "should add any options supplied to the binding" do
52
- b = StateFu::Binding.new( Klass.machine, @obj, :example,
50
+ b = StateFu::Binding.new( Klass.state_fu_machine, @obj, :example,
53
51
  :colour => :red,
54
52
  :style => [:robust, :fruity] )
55
53
  b.options.should == { :colour => :red, :style => [:robust, :fruity] }
@@ -66,23 +64,23 @@ describe StateFu::Binding do
66
64
 
67
65
  describe "when StateFu::Persistence.active_record_column? is true" do
68
66
  before do
69
- mock( StateFu::Persistence ).active_record_column?(Klass, :example_field).times(2) { true }
70
- mock( Klass ).before_save( :state_fu!) { }
67
+ mock( StateFu::Persistence ).active_record_column?(Klass, :example_field).times(1) { true }
68
+ mock( Klass ).before_create( :state_fu!) { }
71
69
  end
72
70
  it "should get an ActiveRecord persister" do
73
71
  mock( StateFu::Persistence::ActiveRecord ).new( anything, :example_field ) { @p }
74
- b = StateFu::Binding.new( Klass.machine, @obj, :example )
72
+ b = StateFu::Binding.new( Klass.state_fu_machine, @obj, :example )
75
73
  b.persister.should == @p
76
74
  end
77
75
  end
78
76
 
79
77
  describe "when StateFu::Persistence.active_record_column? is false" do
80
78
  before do
81
- mock( StateFu::Persistence ).active_record_column?(Klass, :example_field).times(2) { false }
79
+ mock( StateFu::Persistence ).active_record_column?(Klass, :example_field) { false }
82
80
  end
83
81
  it "should get an Attribute persister" do
84
82
  mock( StateFu::Persistence::Attribute ).new( anything, :example_field ) { @p }
85
- b = StateFu::Binding.new( Klass.machine, @obj, :example )
83
+ b = StateFu::Binding.new( Klass.state_fu_machine, @obj, :example )
86
84
  b.persister.should == @p
87
85
  end
88
86
  end
@@ -93,10 +91,10 @@ describe StateFu::Binding do
93
91
  it "should create a new StateFu::Binding with default method-name & field_name" do
94
92
  b = @obj.state_fu()
95
93
  b.should be_kind_of( StateFu::Binding )
96
- b.machine.should == Klass.machine
97
- b.object.should == @obj
98
- b.method_name.should == :state_fu
99
- b.field_name.should == :state_fu_field
94
+ b.machine.should == Klass.state_fu_machine
95
+ b.object.should == @obj
96
+ b.method_name.should == StateFu::DEFAULT
97
+ b.field_name.to_sym.should == StateFu::DEFAULT_FIELD
100
98
  end
101
99
  end
102
100
 
@@ -104,13 +102,13 @@ describe StateFu::Binding do
104
102
  before do
105
103
  reset!
106
104
  make_pristine_class('Klass')
107
- Klass.machine do
105
+ Klass.state_fu_machine do
108
106
  state :new do
109
107
  event :age, :to => :old
110
108
  end
111
109
  state :old
112
110
  end
113
- @machine = Klass.machine()
111
+ @machine = Klass.state_fu_machine()
114
112
  @object = Klass.new()
115
113
  @binding = @object.state_fu()
116
114
  end
@@ -144,9 +142,14 @@ describe StateFu::Binding do
144
142
  before do
145
143
  reset!
146
144
  make_pristine_class("Klass")
147
- @machine = Klass.machine do
145
+ Klass.class_eval do
146
+ def tissue?(*args); "o_O"; end
147
+ end
148
+ @machine = Klass.state_fu_machine do
148
149
  state :snoo do
149
- event :am_fireable, :to => :wizz
150
+ event :am_fireable, :to => :wizz do
151
+ requires :tissue?
152
+ end
150
153
  end
151
154
  state :wizz do
152
155
  event :not_fireable, :to => :pong
@@ -171,7 +174,15 @@ describe StateFu::Binding do
171
174
  end
172
175
 
173
176
  describe "when called with additional arguments after the destination event/state" do
174
- it "should pass the arguments to any requirements to determine transition availability"
177
+
178
+ # This would make very little sense to someone trying to understand how to use the library.
179
+ it "should pass the arguments to any requirements to determine transition availability" do
180
+ pending
181
+ mock(@obj).tissue?() do
182
+ current_transition.should be_kind_of(StateFu::Transition)
183
+ end #{|tr| tr.args.should == [:a,:b] }
184
+ @obj.state_fu.am_fireable?(:a, :b)
185
+ end
175
186
  end
176
187
 
177
188
  end
@@ -86,7 +86,7 @@ describe StateFu::Event do
86
86
  end
87
87
 
88
88
  it "should have the event as the sprocket" do
89
- @lathe.sprocket.should == @event
89
+ @lathe.state_or_event.should == @event
90
90
  end
91
91
 
92
92
  end
@@ -203,31 +203,12 @@ describe StateFu::Event do
203
203
  @event.from?( :a ).should == true
204
204
  end
205
205
 
206
- it "should return false given a symbol which is not the name of a state in @origin" do
206
+ it "should return nil given a symbol which is not the name of a state in @origin" do
207
207
  mock( @event ).origins().times(any_times) { [StateFu::State.new(@machine,:a)] }
208
- @event.from?( :b ).should == false
208
+ @event.from?( :b ).should == nil
209
209
  end
210
210
  end
211
211
 
212
- describe 'complete?' do
213
- it "should be false if either origin / target are nil" do
214
- @event.complete?.should == false
215
- end
216
-
217
- it "should be true when origin / target are both not nil" do
218
- mock( @event ).origins { [:a] }
219
- mock( @event ).targets { [:b] }
220
- @event.complete?.should == true
221
- end
222
-
223
- it "should be false when either origin / target are nil" do
224
- mock( @event ).origins { [:a] }
225
- mock( @event ).targets { nil }
226
- @event.complete?.should == false
227
- end
228
-
229
- end
230
-
231
212
  end # describe instance methods
232
213
  end # describe StateFu::Event
233
214
  end
@@ -18,11 +18,13 @@ describe StateFu::TransitionHalted do
18
18
  end
19
19
 
20
20
  it "should create a TransitionHalted given a transition" do
21
+ pending
21
22
  e = StateFu::TransitionHalted.new( @transition )
22
23
  e.should be_kind_of( StateFu::TransitionHalted )
23
24
  end
24
25
 
25
26
  it "should allow a custom message" do
27
+ pending
26
28
  msg = 'helo'
27
29
  e = StateFu::TransitionHalted.new( @transition, msg )
28
30
  e.should be_kind_of( StateFu::TransitionHalted )
@@ -30,12 +32,14 @@ describe StateFu::TransitionHalted do
30
32
  end
31
33
 
32
34
  it "should allow a message to be omitted" do
35
+ pending
33
36
  e = StateFu::TransitionHalted.new( @transition )
34
37
  e.should be_kind_of( StateFu::TransitionHalted )
35
38
  e.message.should == StateFu::TransitionHalted::DEFAULT_MESSAGE
36
39
  end
37
40
 
38
41
  it "should allow access to the transition" do
42
+ pending
39
43
  e = StateFu::TransitionHalted.new( @transition )
40
44
  e.transition.should == @transition
41
45
  end
@@ -52,12 +56,14 @@ describe StateFu::InvalidTransition do
52
56
 
53
57
  describe "constructor" do
54
58
  it "should create an InvalidTransition given a binding, event, origin & target" do
59
+ pending
55
60
  e = StateFu::InvalidTransition.new( @binding, @event, @origin, @target )
56
61
  e.should be_kind_of( StateFu::InvalidTransition )
57
62
  e.message.should == StateFu::InvalidTransition::DEFAULT_MESSAGE
58
63
  end
59
64
 
60
65
  it "should allow a custom message" do
66
+ pending
61
67
  msg = 'helo'
62
68
  e = StateFu::InvalidTransition.new( @binding, @event, @origin, @target, msg )
63
69
  e.should be_kind_of( StateFu::InvalidTransition )
@@ -65,6 +71,7 @@ describe StateFu::InvalidTransition do
65
71
  end
66
72
 
67
73
  it "should allow access to the binding, event, origin, and target" do
74
+ pending
68
75
  e = StateFu::InvalidTransition.new( @binding, @event, @origin, @target )
69
76
  e.binding.should == @binding
70
77
  e.event.should == @event
@@ -6,7 +6,7 @@ describe StateFu::Lathe do
6
6
  before do
7
7
  reset!
8
8
  make_pristine_class('Klass')
9
- @machine = Object.new()
9
+ @machine = StateFu::Machine.new()
10
10
  @state = Object.new()
11
11
  @event = Object.new()
12
12
 
@@ -23,23 +23,23 @@ describe StateFu::Lathe do
23
23
  lathe = StateFu::Lathe.new( @machine )
24
24
  lathe.should be_kind_of( StateFu::Lathe )
25
25
  lathe.machine.should == @machine
26
- lathe.sprocket.should == nil
26
+ lathe.state_or_event.should == nil
27
27
  lathe.options.should == {}
28
28
  end
29
29
 
30
- it "should accept a sprocket (state / event ) and if given one, be a child" do
30
+ it "should accept a state_or_event (state / event ) and if given one, be a child" do
31
31
  options = {}
32
32
  mock( @state ).apply!( options ) {}
33
33
  lathe = StateFu::Lathe.new( @machine, @state )
34
34
  lathe.should be_kind_of( StateFu::Lathe )
35
35
  lathe.machine.should == @machine
36
- lathe.sprocket.should == @state
36
+ lathe.state_or_event.should == @state
37
37
  lathe.options.should == {}
38
38
  lathe.should be_child
39
39
  end
40
40
  end
41
41
 
42
- describe "lathe instance with no sprocket (master lathe for a machine)" do
42
+ describe "lathe instance with no state_or_event (master lathe for a machine)" do
43
43
  before do
44
44
  end
45
45
 
@@ -351,7 +351,7 @@ describe StateFu::Lathe do
351
351
  @lathe = StateFu::Lathe.new( @machine, @state )
352
352
  end
353
353
 
354
- it "should create a named event from and to the lathe's sprocket (state)" do
354
+ it "should create a named event from and to the lathe's state_or_event (state)" do
355
355
 
356
356
  @machine.events.should be_empty
357
357
  @machine.states.length.should == 1
@@ -380,7 +380,7 @@ describe StateFu::Lathe do
380
380
 
381
381
  describe ".event(:name)" do
382
382
  before do
383
- mock( @machine ).find_or_create_states_by_name( @lathe.sprocket ).at_least(1) { @lathe.sprocket }
383
+ mock( @machine ).find_or_create_states_by_name( @lathe.state_or_event ).at_least(1) { @lathe.state_or_event }
384
384
  end
385
385
 
386
386
  it "should create the named event if it does not exist" do
@@ -16,17 +16,17 @@ describe StateFu::Machine do
16
16
  end
17
17
 
18
18
  describe "Machine.for_class" do
19
- describe "when there's no matching machine in FuSpace" do
19
+ describe "when there's no machine defined for the class" do
20
20
  before do
21
21
  reset!
22
22
  make_pristine_class 'Klass'
23
- mock( StateFu::FuSpace ).class_machines() { { Klass => {} } }
23
+ # mock( Klass ).machines() { {} }
24
24
  end
25
25
 
26
26
  it "should create a new machine and bind! it" do
27
27
  @machine = Object.new
28
28
  mock( @machine ).bind!( Klass, :moose, nil )
29
- mock( StateFu::Machine ).new( :moose, {} ) { @machine }
29
+ mock( StateFu::Machine ).new( {} ) { @machine }
30
30
  StateFu::Machine.for_class( Klass, :moose )
31
31
  end
32
32
 
@@ -34,15 +34,8 @@ describe StateFu::Machine do
34
34
  @m = StateFu::Machine.for_class( Klass, :snoo ) do
35
35
  state :porpoise
36
36
  end
37
- @m.states.map(&:name).should == [:porpoise]
38
- end
39
- end
40
-
41
- describe "when there's a matching machine in FuSpace" do
42
- it "should retrieve the previously created machine" do
43
- @machine = Object.new
44
- mock( StateFu::FuSpace ).class_machines() { { Klass => { :moose => @machine } } }
45
- StateFu::Machine.for_class( Klass, :moose ).should == @machine
37
+ # mock( Klass ).machines() { {} }
38
+ # @m.states.map(&:name).should == [:porpoise]
46
39
  end
47
40
  end
48
41
 
@@ -56,24 +49,23 @@ describe StateFu::Machine do
56
49
  before do
57
50
  reset!
58
51
  make_pristine_class 'Klass'
59
- @mchn = StateFu::Machine.new( :spec_machine, options={} )
52
+ @m = StateFu::Machine.new
60
53
  end
61
54
 
62
55
  describe "helper" do
63
56
  it "should add its arguments to the @@helpers array" do
64
57
  module Foo; FOO = :foo; end
65
58
  module Bar; BAR = :bar; end
66
- @mchn.helper Foo, Bar
67
- @mchn.helpers.should == [Foo, Bar]
59
+ @m.helper Foo, Bar
60
+ @m.helpers.should == [Foo, Bar]
68
61
  end
69
62
 
70
63
  end
71
64
 
72
65
  describe ".initialize" do
73
- it "should require a name" do
74
- lambda do
75
- StateFu::Machine.new()
76
- end.should raise_error( ArgumentError )
66
+ it "should apply options to the machine" do
67
+ @m = StateFu::Machine.new( :colour => "blue")
68
+ @m.options.should == {:colour => "blue" }
77
69
  end
78
70
  end
79
71
 
@@ -82,42 +74,42 @@ describe StateFu::Machine do
82
74
  end
83
75
 
84
76
  describe ".bind!" do
85
- it "should call StateFu::FuSpace.insert! with itself and its arguments" do
77
+ it "should call StateFu::Machine.bind! with itself and its arguments" do
86
78
  field_name = :my_field_name
87
- mock( StateFu::FuSpace ).insert!( Klass, @mchn, :newname, field_name ) {}
88
- @mchn.bind!( Klass, :newname, field_name )
79
+ mock( StateFu::Machine ).bind!( @m, Klass, :newname, field_name ) {}
80
+ @m.bind!( Klass, :newname, field_name )
89
81
  end
90
82
 
91
83
  it "should generate a field name if none is given" do
92
84
  klass = Klass
93
85
  name = :StinkJuice
94
86
  field_name = 'stink_juice_field'
95
- mock( StateFu::FuSpace ).insert!( Klass, @mchn, name, field_name.to_sym ) {}
96
- @mchn.bind!( Klass, name )
87
+ @m.bind!( Klass, name )
88
+ Klass.state_fu_field_names[name].should == 'stink_juice_field'
97
89
  end
98
90
  end
99
91
 
100
92
  describe ".initial_state=" do
101
93
 
102
94
  it "should set @initial_state given a String, Symbol or State for an existing state" do
103
- state = StateFu::State.new( @mchn, :wizzle )
104
- @mchn.states << state
105
- @mchn.initial_state = state
106
- @mchn.initial_state.should == state
95
+ state = StateFu::State.new( @m, :wizzle )
96
+ @m.states << state
97
+ @m.initial_state = state
98
+ @m.initial_state.should == state
107
99
  end
108
100
 
109
101
  it "should create the state if it doesnt exist" do
110
- @mchn.initial_state = :snoo
111
- @mchn.initial_state.should be_kind_of( StateFu::State )
112
- @mchn.initial_state.name.should == :snoo
113
- @mchn.states.should include( @mchn.initial_state )
102
+ @m.initial_state = :snoo
103
+ @m.initial_state.should be_kind_of( StateFu::State )
104
+ @m.initial_state.name.should == :snoo
105
+ @m.states.should include( @m.initial_state )
114
106
  end
115
107
 
116
108
  it "should raise an ArgumentError given a number or an Array" do
117
- lambda do @mchn.initial_state = 6
109
+ lambda do @m.initial_state = 6
118
110
  end.should raise_error( ArgumentError )
119
111
 
120
- lambda do @mchn.initial_state = [:ping]
112
+ lambda do @m.initial_state = [:ping]
121
113
  end.should raise_error( ArgumentError )
122
114
  end
123
115
 
@@ -125,110 +117,110 @@ describe StateFu::Machine do
125
117
 
126
118
  describe ".initial_state" do
127
119
  it "should return nil if there are no states and initial_state= has not been called" do
128
- @mchn.states.should == []
129
- @mchn.initial_state.should == nil
120
+ @m.states.should == []
121
+ @m.initial_state.should == nil
130
122
  end
131
123
 
132
124
  it "should return the first state if one exists" do
133
- stub( @mchn ).states() { [:a, :b, :c] }
134
- @mchn.initial_state.should == :a
125
+ stub( @m ).states() { [:a, :b, :c] }
126
+ @m.initial_state.should == :a
135
127
  end
136
128
 
137
129
  end
138
130
 
139
131
  describe ".states" do
140
132
  it "should return an array extended with StateFu::StateArray" do
141
- @mchn.states.should be_kind_of( Array )
142
- @mchn.states.extended_by.should include( StateFu::StateArray )
133
+ @m.states.should be_kind_of( Array )
134
+ @m.states.extended_by.should include( StateFu::StateArray )
143
135
  end
144
136
  end
145
137
 
146
138
  describe ".state_names" do
147
139
  it "should return a list of symbols of state names" do
148
- @mchn.states << StateFu::State.new( @mchn, :a )
149
- @mchn.states << StateFu::State.new( @mchn, :b )
150
- @mchn.state_names.should == [:a, :b ]
140
+ @m.states << StateFu::State.new( @m, :a )
141
+ @m.states << StateFu::State.new( @m, :b )
142
+ @m.state_names.should == [:a, :b ]
151
143
  end
152
144
  end
153
145
 
154
146
  describe ".events" do
155
147
  it "should return an array extended with StateFu::EventArray" do
156
- @mchn.events.should be_kind_of( Array )
157
- @mchn.events.extended_by.should include( StateFu::EventArray )
148
+ @m.events.should be_kind_of( Array )
149
+ @m.events.extended_by.should include( StateFu::EventArray )
158
150
  end
159
151
  end
160
152
 
161
153
  describe ".event_names" do
162
154
  it "should return a list of symbols of event names" do
163
- @mchn.events << StateFu::Event.new( @mchn, :a )
164
- @mchn.events << StateFu::Event.new( @mchn, :b )
165
- @mchn.event_names.should == [:a, :b ]
155
+ @m.events << StateFu::Event.new( @m, :a )
156
+ @m.events << StateFu::Event.new( @m, :b )
157
+ @m.event_names.should == [:a, :b ]
166
158
  end
167
159
  end
168
160
 
169
161
  describe ".find_or_create_states_by_name" do
170
162
  describe "given an array of symbols" do
171
163
  it "should return the states named by the symbols if they exist" do
172
- a = StateFu::State.new( @mchn, :a )
173
- b = StateFu::State.new( @mchn, :b )
174
- @mchn.states << a
175
- @mchn.states << b
176
- @mchn.find_or_create_states_by_name( :a, :b ).should == [a, b]
177
- @mchn.find_or_create_states_by_name( [:a, :b] ).should == [a, b]
164
+ a = StateFu::State.new( @m, :a )
165
+ b = StateFu::State.new( @m, :b )
166
+ @m.states << a
167
+ @m.states << b
168
+ @m.find_or_create_states_by_name( :a, :b ).should == [a, b]
169
+ @m.find_or_create_states_by_name( [:a, :b] ).should == [a, b]
178
170
  end
179
171
 
180
172
  it "should return the states named by the symbols and create them if they don't exist" do
181
- @mchn.states.should == []
182
- res = @mchn.find_or_create_states_by_name( :a, :b )
173
+ @m.states.should == []
174
+ res = @m.find_or_create_states_by_name( :a, :b )
183
175
  res.should be_kind_of( Array )
184
176
  res.length.should == 2
185
177
  res.all? { |e| e.class == StateFu::State }.should be_true
186
178
  res.map(&:name).should == [ :a, :b ]
187
- @mchn.find_or_create_states_by_name( :a, :b ).should == res
179
+ @m.find_or_create_states_by_name( :a, :b ).should == res
188
180
  end
189
181
  end # arr symbols
190
182
 
191
183
  describe "given an array of states" do
192
184
  it "should return the states if they're in the machine's states array" do
193
- a = StateFu::State.new( @mchn, :a )
194
- b = StateFu::State.new( @mchn, :b )
195
- @mchn.states << a
196
- @mchn.states << b
197
- @mchn.find_or_create_states_by_name( a, b ).should == [a, b]
198
- @mchn.find_or_create_states_by_name( [a, b] ).should == [a, b]
199
- @mchn.find_or_create_states_by_name( [[a, b]] ).should == [a, b]
185
+ a = StateFu::State.new( @m, :a )
186
+ b = StateFu::State.new( @m, :b )
187
+ @m.states << a
188
+ @m.states << b
189
+ @m.find_or_create_states_by_name( a, b ).should == [a, b]
190
+ @m.find_or_create_states_by_name( [a, b] ).should == [a, b]
191
+ @m.find_or_create_states_by_name( [[a, b]] ).should == [a, b]
200
192
  end
201
193
 
202
194
  it "should add the states to the machine's states array if they're absent" do
203
- a = StateFu::State.new( @mchn, :a )
204
- b = StateFu::State.new( @mchn, :b )
205
- @mchn.find_or_create_states_by_name( a, b ).should == [a, b]
206
- @mchn.find_or_create_states_by_name( [a, b] ).should == [a, b]
207
- @mchn.find_or_create_states_by_name( [[a, b]] ).should == [a, b]
195
+ a = StateFu::State.new( @m, :a )
196
+ b = StateFu::State.new( @m, :b )
197
+ @m.find_or_create_states_by_name( a, b ).should == [a, b]
198
+ @m.find_or_create_states_by_name( [a, b] ).should == [a, b]
199
+ @m.find_or_create_states_by_name( [[a, b]] ).should == [a, b]
208
200
  end
209
201
  end # arr states
210
202
  end # find_or_create_states_by_name
211
203
 
212
204
  describe "requirement_messages" do
213
205
  it "should be a hash" do
214
- @mchn.should respond_to(:requirement_messages)
215
- @mchn.requirement_messages.should be_kind_of( Hash )
206
+ @m.should respond_to(:requirement_messages)
207
+ @m.requirement_messages.should be_kind_of( Hash )
216
208
  end
217
209
 
218
210
  it "should be empty by default" do
219
- @mchn.requirement_messages.should be_empty
211
+ @m.requirement_messages.should be_empty
220
212
  end
221
213
 
222
214
  end # requirement_messages
223
215
 
224
216
  describe "named_procs" do
225
217
  it "should be a hash" do
226
- @mchn.should respond_to(:named_procs)
227
- @mchn.named_procs.should be_kind_of( Hash )
218
+ @m.should respond_to(:named_procs)
219
+ @m.named_procs.should be_kind_of( Hash )
228
220
  end
229
221
 
230
222
  it "should be empty by default" do
231
- @mchn.named_procs.should be_empty
223
+ @m.named_procs.should be_empty
232
224
  end
233
225
 
234
226
  end # named_procs