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.
- data/README.textile +124 -34
- data/Rakefile +36 -30
- data/lib/no_stdout.rb +1 -1
- data/lib/state-fu.rb +9 -8
- data/lib/state_fu/active_support_lite/array/access.rb +12 -5
- data/lib/state_fu/active_support_lite/array/conversions.rb +10 -4
- data/lib/state_fu/active_support_lite/array/extract_options.rb +5 -4
- data/lib/state_fu/active_support_lite/array/grouping.rb +7 -4
- data/lib/state_fu/active_support_lite/array/random_access.rb +4 -3
- data/lib/state_fu/active_support_lite/array/wrapper.rb +4 -3
- data/lib/state_fu/active_support_lite/array.rb +3 -1
- data/lib/state_fu/active_support_lite/blank.rb +18 -9
- data/lib/state_fu/active_support_lite/cattr_reader.rb +4 -1
- data/lib/state_fu/active_support_lite/keys.rb +8 -3
- data/lib/state_fu/active_support_lite/misc.rb +6 -4
- data/lib/state_fu/active_support_lite/module/delegation.rb +130 -0
- data/lib/state_fu/active_support_lite/module.rb +1 -0
- data/lib/state_fu/active_support_lite/object.rb +5 -2
- data/lib/state_fu/active_support_lite/string.rb +6 -1
- data/lib/state_fu/active_support_lite/symbol.rb +2 -1
- data/lib/state_fu/applicable.rb +41 -0
- data/lib/state_fu/{helper.rb → arrays.rb} +45 -121
- data/lib/state_fu/binding.rb +136 -159
- data/lib/state_fu/core_ext.rb +78 -10
- data/lib/state_fu/event.rb +112 -48
- data/lib/state_fu/exceptions.rb +80 -34
- data/lib/state_fu/executioner.rb +149 -0
- data/lib/state_fu/has_options.rb +16 -0
- data/lib/state_fu/hooks.rb +21 -16
- data/lib/state_fu/interface.rb +80 -83
- data/lib/state_fu/lathe.rb +361 -148
- data/lib/state_fu/logger.rb +122 -45
- data/lib/state_fu/machine.rb +60 -32
- data/lib/state_fu/method_factory.rb +180 -72
- data/lib/state_fu/methodical.rb +17 -0
- data/lib/state_fu/persistence/active_record.rb +6 -1
- data/lib/state_fu/persistence/attribute.rb +1 -0
- data/lib/state_fu/persistence/base.rb +8 -6
- data/lib/state_fu/persistence.rb +94 -23
- data/lib/state_fu/sprocket.rb +26 -11
- data/lib/state_fu/state.rb +8 -27
- data/lib/state_fu/transition.rb +207 -98
- data/lib/state_fu/transition_query.rb +214 -0
- data/lib/state_fu.rb +1 -0
- data/lib/tasks/spec_last.rake +46 -0
- data/lib/tasks/state_fu.rake +57 -0
- data/lib/vizier.rb +61 -61
- data/spec/custom_formatter.rb +49 -0
- data/spec/features/binding_and_transition_helper_mixin_spec.rb +2 -2
- data/spec/features/method_missing_only_once_spec.rb +28 -0
- data/spec/features/not_requirements_spec.rb +83 -46
- data/spec/features/plotter_spec.rb +97 -0
- data/spec/features/shared_log_spec.rb +7 -0
- data/spec/features/singleton_machine_spec.rb +39 -0
- data/spec/features/state_and_array_options_accessor_spec.rb +1 -1
- data/spec/features/{transition_boolean_comparison.rb → transition_boolean_comparison_spec.rb} +29 -18
- data/spec/helper.rb +6 -117
- data/spec/integration/active_record_persistence_spec.rb +18 -4
- data/spec/integration/binding_extension_spec.rb +1 -1
- data/spec/integration/class_accessor_spec.rb +49 -59
- data/spec/integration/event_definition_spec.rb +20 -20
- data/spec/integration/example_01_document_spec.rb +13 -8
- data/spec/integration/example_02_string_spec.rb +3 -2
- data/spec/integration/instance_accessor_spec.rb +16 -19
- data/spec/integration/lathe_extension_spec.rb +2 -2
- data/spec/integration/machine_duplication_spec.rb +59 -37
- data/spec/integration/relaxdb_persistence_spec.rb +6 -3
- data/spec/integration/requirement_reflection_spec.rb +66 -57
- data/spec/integration/state_definition_spec.rb +72 -66
- data/spec/integration/transition_spec.rb +169 -173
- data/spec/spec.opts +5 -3
- data/spec/spec_helper.rb +132 -0
- data/spec/state_fu_spec.rb +870 -0
- data/spec/units/binding_spec.rb +33 -22
- data/spec/units/event_spec.rb +3 -22
- data/spec/units/exceptions_spec.rb +7 -0
- data/spec/units/lathe_spec.rb +7 -7
- data/spec/units/machine_spec.rb +67 -75
- data/spec/units/method_factory_spec.rb +55 -48
- data/spec/units/sprocket_spec.rb +5 -7
- data/spec/units/state_spec.rb +33 -24
- metadata +31 -19
- data/lib/state_fu/active_support_lite/inheritable_attributes.rb +0 -1
- data/lib/state_fu/fu_space.rb +0 -51
- data/lib/state_fu/mock_transition.rb +0 -38
- data/spec/BDD/plotter_spec.rb +0 -115
- data/spec/integration/dynamic_requirement_spec.rb +0 -160
- data/spec/integration/ex_machine_for_accounts_spec.rb +0 -79
- data/spec/integration/sanity_spec.rb +0 -31
- data/spec/units/fu_space_spec.rb +0 -95
|
@@ -13,17 +13,30 @@ describe StateFu::MethodFactory do
|
|
|
13
13
|
describe "defined on the stateful instance / object before state_fu has been called" do
|
|
14
14
|
|
|
15
15
|
before do
|
|
16
|
-
@machine = Klass.
|
|
16
|
+
@machine = Klass.state_fu_machine do
|
|
17
17
|
event( :simple_event,
|
|
18
18
|
:from => { [:a, :b] => :targ } )
|
|
19
|
-
|
|
20
|
-
state( :a ) { cycle }
|
|
19
|
+
state( :a ) { cycle }
|
|
21
20
|
end # machine
|
|
22
21
|
@obj = Klass.new
|
|
23
22
|
end
|
|
24
23
|
|
|
25
24
|
describe "when there is a method_missing already defined for the class" do
|
|
26
|
-
|
|
25
|
+
before do
|
|
26
|
+
reset!
|
|
27
|
+
make_pristine_class('Klass')
|
|
28
|
+
Klass.class_eval do
|
|
29
|
+
def method_missing method_name, *args
|
|
30
|
+
callme
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
Klass.state_fu_machine(){}
|
|
34
|
+
end
|
|
35
|
+
it "should call the original method_missing on an unexpected method call" do
|
|
36
|
+
@k = Klass.new
|
|
37
|
+
mock(@k).callme
|
|
38
|
+
@k.whut?
|
|
39
|
+
end
|
|
27
40
|
end
|
|
28
41
|
|
|
29
42
|
describe "event creation methods" do
|
|
@@ -33,8 +46,13 @@ describe StateFu::MethodFactory do
|
|
|
33
46
|
end
|
|
34
47
|
|
|
35
48
|
it "should call state_fu!" do
|
|
36
|
-
mock.proxy( StateFu::Binding ).new( Klass.
|
|
49
|
+
mock.proxy( StateFu::Binding ).new( Klass.state_fu_machine, @obj, StateFu::DEFAULT )
|
|
50
|
+
@obj
|
|
51
|
+
@obj.private_methods.map(&:to_sym).should include(:state_fu_field)
|
|
52
|
+
#@obj.should respond_to StateFu::DEFAULT_FIELD
|
|
53
|
+
@obj.state_fu.machine.events.should_not be_empty
|
|
37
54
|
@obj.simple_event!
|
|
55
|
+
|
|
38
56
|
# @obj.should_have_received( :state_fu! )
|
|
39
57
|
end
|
|
40
58
|
|
|
@@ -42,14 +60,9 @@ describe StateFu::MethodFactory do
|
|
|
42
60
|
lambda { @obj.simple_event! }.should_not raise_error( NoMethodError )
|
|
43
61
|
end
|
|
44
62
|
|
|
45
|
-
it "should call binding.fire!( :simple_event ... ) with no args" do
|
|
46
|
-
mock.instance_of( StateFu::Binding ).fire!( is_a(StateFu::Event) )
|
|
47
|
-
t = @obj.simple_event!
|
|
48
|
-
end
|
|
49
|
-
|
|
50
63
|
it "should call binding.fire!( :simple_event ... ) with any specified args" do
|
|
51
|
-
mock.instance_of( StateFu::Binding ).fire!(
|
|
52
|
-
t = @obj.simple_event!( :a, :b, :c => "d" )
|
|
64
|
+
mock.instance_of( StateFu::Binding ).fire!( anything, :a, :b, {:c => "d"} )
|
|
65
|
+
t = @obj.simple_event!( nil, :a, :b, :c => "d" )
|
|
53
66
|
end
|
|
54
67
|
|
|
55
68
|
it "should fire the transition" do
|
|
@@ -58,13 +71,6 @@ describe StateFu::MethodFactory do
|
|
|
58
71
|
t.should be_accepted
|
|
59
72
|
@obj.send(:state_fu_field).should == 'targ'
|
|
60
73
|
end
|
|
61
|
-
|
|
62
|
-
it "should accept a block and pass it to the method on the binding" do
|
|
63
|
-
block = lambda { }
|
|
64
|
-
mock.instance_of( StateFu::Binding ).fire!( is_a(StateFu::Event) )
|
|
65
|
-
@obj.simple_event! &block
|
|
66
|
-
pending "don't know how to mock this"
|
|
67
|
-
end
|
|
68
74
|
end
|
|
69
75
|
end
|
|
70
76
|
|
|
@@ -72,7 +78,7 @@ describe StateFu::MethodFactory do
|
|
|
72
78
|
describe "defined on the binding" do
|
|
73
79
|
describe "when the event is simple (has only one possible target)" do
|
|
74
80
|
before do
|
|
75
|
-
@machine = Klass.
|
|
81
|
+
@machine = Klass.state_fu_machine do
|
|
76
82
|
event( :simple_event,
|
|
77
83
|
:from => { [:a, :b] => :targ } )
|
|
78
84
|
end # machine
|
|
@@ -101,28 +107,28 @@ describe StateFu::MethodFactory do
|
|
|
101
107
|
end
|
|
102
108
|
|
|
103
109
|
it "should add any arguments / options it is called with to the transition" do
|
|
104
|
-
t = @binding.simple_event
|
|
105
|
-
t.should be_kind_of( StateFu::Transition )
|
|
106
|
-
t.target.should
|
|
107
|
-
t.event.should
|
|
108
|
-
t.args.should
|
|
110
|
+
t = @binding.simple_event nil, :a, :b, :c, {'d' => 'e'}
|
|
111
|
+
#t.should be_kind_of( StateFu::Transition )
|
|
112
|
+
#t.target.should == @machine.states[:targ]
|
|
113
|
+
#t.event.should == @machine.events[:simple_event]
|
|
114
|
+
t.args.should == [:a,:b,:c,{'d' => 'e'}]
|
|
109
115
|
t.options.should == {:d => 'e'}
|
|
110
116
|
end
|
|
111
117
|
end # transition builder
|
|
112
118
|
|
|
113
119
|
describe "method which tests if the event is fireable?" do
|
|
114
120
|
it "should have the name of the event suffixed with ?" do
|
|
115
|
-
@binding.should respond_to(:
|
|
121
|
+
@binding.should respond_to(:can_simple_event?)
|
|
116
122
|
end
|
|
117
123
|
|
|
118
124
|
it "should be true when the binding says it\'s fireable?" do
|
|
119
125
|
@binding.fireable?( :simple_event ).should == true
|
|
120
|
-
@binding.
|
|
126
|
+
@binding.can_simple_event?.should == true
|
|
121
127
|
end
|
|
122
128
|
|
|
123
129
|
it "should be false when the binding says it\'s not fireable?" do
|
|
124
130
|
mock( @binding ).fireable?( anything ) { false }
|
|
125
|
-
@binding.
|
|
131
|
+
@binding.can_simple_event?.should == false
|
|
126
132
|
end
|
|
127
133
|
end # fireable?
|
|
128
134
|
|
|
@@ -138,9 +144,9 @@ describe StateFu::MethodFactory do
|
|
|
138
144
|
end
|
|
139
145
|
|
|
140
146
|
it "should pass any arguments to the transition as args / options" do
|
|
141
|
-
t = @binding.simple_event!( :a, :b, {'c' => :d } )
|
|
147
|
+
t = @binding.simple_event!( nil, :a, :b, {'c' => :d } )
|
|
142
148
|
t.should be_kind_of( StateFu::Transition )
|
|
143
|
-
t.args.should == [:a, :b ]
|
|
149
|
+
t.args.should == [:a, :b, {'c' => :d} ]
|
|
144
150
|
t.options.should == { :c => :d }
|
|
145
151
|
end
|
|
146
152
|
end # bang!
|
|
@@ -148,7 +154,7 @@ describe StateFu::MethodFactory do
|
|
|
148
154
|
|
|
149
155
|
describe "when the event is complex (has more than one possible target)" do
|
|
150
156
|
before do
|
|
151
|
-
@machine = Klass.
|
|
157
|
+
@machine = Klass.state_fu_machine do
|
|
152
158
|
state :orphan
|
|
153
159
|
event( :complex_event,
|
|
154
160
|
:from => :home,
|
|
@@ -172,11 +178,11 @@ describe StateFu::MethodFactory do
|
|
|
172
178
|
end
|
|
173
179
|
|
|
174
180
|
it "should raise an error if called without any arguments" do
|
|
175
|
-
lambda { @binding.complex_event() }.should raise_error(
|
|
181
|
+
lambda { @binding.complex_event() }.should raise_error( StateFu::UnknownTarget )
|
|
176
182
|
end
|
|
177
183
|
|
|
178
184
|
it "should raise an ArgumentError if called with a nonexistent target state" do
|
|
179
|
-
lambda { @binding.complex_event(:nonexistent) }.should raise_error(
|
|
185
|
+
lambda { @binding.complex_event(:nonexistent) }.should raise_error( StateFu::UnknownTarget )
|
|
180
186
|
end
|
|
181
187
|
|
|
182
188
|
it "should raise an InvalidTransition if called with an invalid target state" do
|
|
@@ -193,31 +199,31 @@ describe StateFu::MethodFactory do
|
|
|
193
199
|
t = @binding.complex_event(:x,
|
|
194
200
|
:a, :b, :c, {'d' => 'e'})
|
|
195
201
|
t.should be_kind_of( StateFu::Transition )
|
|
196
|
-
t.args.should == [:a,:b,:c]
|
|
202
|
+
t.args.should == [:a,:b,:c,{'d' =>'e'}]
|
|
197
203
|
t.options.should == {:d => 'e'}
|
|
198
204
|
end
|
|
199
205
|
end # transition builder
|
|
200
206
|
|
|
201
207
|
describe "method which tests if the event is fireable?" do
|
|
202
208
|
it "should have the name of the event suffixed with ?" do
|
|
203
|
-
@binding.should respond_to(:
|
|
209
|
+
@binding.should respond_to(:can_complex_event?)
|
|
204
210
|
end
|
|
205
211
|
|
|
206
212
|
it "should require a valid state name" do
|
|
207
|
-
lambda { @binding.
|
|
208
|
-
lambda { @binding.
|
|
209
|
-
@binding.
|
|
210
|
-
lambda { @binding.
|
|
213
|
+
lambda { @binding.can_complex_event?(:nonexistent) }.should raise_error( StateFu::UnknownTarget )
|
|
214
|
+
lambda { @binding.can_complex_event?(:orphan) }.should_not raise_error()
|
|
215
|
+
@binding.can_complex_event?(:orphan).should == nil
|
|
216
|
+
lambda { @binding.can_complex_event?(:x) }.should_not raise_error
|
|
211
217
|
end
|
|
212
218
|
|
|
213
219
|
it "should be true when the binding says the event is fireable? " do
|
|
214
220
|
@binding.fireable?( [:complex_event, :x] ).should == true
|
|
215
|
-
@binding.
|
|
221
|
+
@binding.can_complex_event?(:x).should == true
|
|
216
222
|
end
|
|
217
223
|
|
|
218
224
|
it "should be false when the binding says the event is not fireable?" do
|
|
219
225
|
mock( @binding ).fireable?( anything ) { false }
|
|
220
|
-
@binding.
|
|
226
|
+
@binding.can_complex_event?(:x).should == false
|
|
221
227
|
end
|
|
222
228
|
end # fireable?
|
|
223
229
|
|
|
@@ -227,7 +233,7 @@ describe StateFu::MethodFactory do
|
|
|
227
233
|
end
|
|
228
234
|
|
|
229
235
|
it "should require a valid state name" do
|
|
230
|
-
lambda { @binding.complex_event!(:nonexistent) }.should raise_error(
|
|
236
|
+
lambda { @binding.complex_event!(:nonexistent) }.should raise_error( StateFu::UnknownTarget )
|
|
231
237
|
lambda { @binding.complex_event!(:orphan) }.should raise_error( StateFu::InvalidTransition )
|
|
232
238
|
lambda { @binding.complex_event!(:x) }.should_not raise_error
|
|
233
239
|
end
|
|
@@ -244,7 +250,7 @@ describe StateFu::MethodFactory do
|
|
|
244
250
|
:a, :b, {'c' => :d } )
|
|
245
251
|
t.should be_kind_of( StateFu::Transition )
|
|
246
252
|
t.target.should == @machine.states[:x]
|
|
247
|
-
t.args.should == [:a, :b ]
|
|
253
|
+
t.args.should == [:a, :b,{'c' =>:d} ]
|
|
248
254
|
t.options.should == { :c => :d }
|
|
249
255
|
end
|
|
250
256
|
end # bang!
|
|
@@ -254,7 +260,7 @@ describe StateFu::MethodFactory do
|
|
|
254
260
|
describe "cycle and next_state methods" do
|
|
255
261
|
describe "when there is a valid transition available for cycle and next_state" do
|
|
256
262
|
before do
|
|
257
|
-
@machine = Klass.
|
|
263
|
+
@machine = Klass.state_fu_machine do
|
|
258
264
|
initial_state :groundhog_day
|
|
259
265
|
|
|
260
266
|
state(:groundhog_day) do
|
|
@@ -299,7 +305,7 @@ describe StateFu::MethodFactory do
|
|
|
299
305
|
|
|
300
306
|
describe "when the machine is empty" do
|
|
301
307
|
before do
|
|
302
|
-
@machine = Klass.
|
|
308
|
+
@machine = Klass.state_fu_machine() {}
|
|
303
309
|
@obj = Klass.new
|
|
304
310
|
@binding = @obj.state_fu
|
|
305
311
|
end
|
|
@@ -323,8 +329,8 @@ describe StateFu::MethodFactory do
|
|
|
323
329
|
end
|
|
324
330
|
|
|
325
331
|
describe "cycle!" do
|
|
326
|
-
it "should raise_error(
|
|
327
|
-
lambda { @binding.cycle!.should == nil }.should raise_error( StateFu::
|
|
332
|
+
it "should raise_error( TransitionNotFound )" do
|
|
333
|
+
lambda { @binding.cycle!.should == nil }.should raise_error( StateFu::TransitionNotFound )
|
|
328
334
|
end
|
|
329
335
|
end
|
|
330
336
|
end # cycle
|
|
@@ -338,13 +344,14 @@ describe StateFu::MethodFactory do
|
|
|
338
344
|
|
|
339
345
|
describe "next_state?" do
|
|
340
346
|
it "should return nil" do
|
|
347
|
+
pending
|
|
341
348
|
@binding.next_state?.should == nil
|
|
342
349
|
end
|
|
343
350
|
end
|
|
344
351
|
|
|
345
352
|
describe "next_state!" do
|
|
346
353
|
it "should raise_error( InvalidTransition )" do
|
|
347
|
-
lambda { @binding.next_state! }.should raise_error( StateFu::
|
|
354
|
+
lambda { @binding.next_state! }.should raise_error( StateFu::TransitionNotFound )
|
|
348
355
|
end
|
|
349
356
|
end
|
|
350
357
|
end # next_state
|
data/spec/units/sprocket_spec.rb
CHANGED
|
@@ -9,7 +9,7 @@ describe "Common features / functionality for StateFu::State & StateFu::Event" d
|
|
|
9
9
|
include MySpecHelper
|
|
10
10
|
Sprocket = StateFu::Sprocket
|
|
11
11
|
before do
|
|
12
|
-
@machine =
|
|
12
|
+
@machine = StateFu::Machine.new
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
describe "calling Sprocket.new" do
|
|
@@ -40,24 +40,22 @@ describe "Common features / functionality for StateFu::State & StateFu::Event" d
|
|
|
40
40
|
@sprocket.apply!{ yielded = self }
|
|
41
41
|
yielded.should == @sprocket
|
|
42
42
|
end
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
describe "update!" do
|
|
43
|
+
|
|
46
44
|
it "should merge any options passed into .options" do
|
|
47
45
|
opts = @sprocket.options
|
|
48
46
|
newopts = { :size => "huge", :colour => "orange" }
|
|
49
|
-
@sprocket.
|
|
47
|
+
@sprocket.apply!( newopts )
|
|
50
48
|
@sprocket.options.should == opts.merge(newopts)
|
|
51
49
|
end
|
|
52
50
|
|
|
53
51
|
it "should instance_eval the block if one is passed" do
|
|
54
52
|
ref = nil
|
|
55
|
-
@sprocket.
|
|
53
|
+
@sprocket.apply!(){ ref = self }
|
|
56
54
|
ref.should == @sprocket
|
|
57
55
|
end
|
|
58
56
|
|
|
59
57
|
it "should return itself" do
|
|
60
|
-
@sprocket.
|
|
58
|
+
@sprocket.apply!.should == @sprocket
|
|
61
59
|
end
|
|
62
60
|
end
|
|
63
61
|
|
data/spec/units/state_spec.rb
CHANGED
|
@@ -7,44 +7,53 @@ require File.expand_path("#{File.dirname(__FILE__)}/../helper")
|
|
|
7
7
|
describe StateFu::State do
|
|
8
8
|
include MySpecHelper
|
|
9
9
|
|
|
10
|
-
before do
|
|
10
|
+
before(:each) do
|
|
11
11
|
@machine = Object.new
|
|
12
|
+
@state = StateFu::State.new( @machine, :flux, {:meta => "wibble"} )
|
|
12
13
|
end
|
|
13
14
|
|
|
14
15
|
describe "instance methods" do
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
|
|
17
|
+
describe "#after?(other_state)" do
|
|
18
|
+
|
|
19
|
+
it "should be true when the other state is is after? this one" do
|
|
20
|
+
m = StateFu::Machine.new do
|
|
21
|
+
states :red, :green, :yellow
|
|
22
|
+
end
|
|
23
|
+
m.states[:green].after?(:red).should be_true
|
|
24
|
+
m.states[:green].after?(:yellow).should be_false
|
|
25
|
+
m.states[:green].after?(:green).should be_false
|
|
26
|
+
m.states[:green].after?(m.states[:red]).should be_true
|
|
27
|
+
m.states[:green].after?(m.states[:yellow]).should be_false
|
|
28
|
+
m.states[:green].after?(m.states[:green]).should be_false
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
describe "##before?(other_state)" do
|
|
33
|
+
|
|
34
|
+
it "should be true when the other state is is before this one" do
|
|
35
|
+
m = StateFu::Machine.new do
|
|
36
|
+
states :red, :green, :yellow
|
|
37
|
+
end
|
|
38
|
+
m.states[:green].before?(:red).should be_false
|
|
39
|
+
m.states[:green].before?(:yellow).should be_true
|
|
40
|
+
m.states[:green].after?(:green).should be_false
|
|
41
|
+
m.states[:green].before?(m.states[:red]).should be_false
|
|
42
|
+
m.states[:green].before?(m.states[:yellow]).should be_true
|
|
43
|
+
m.states[:green].after?(m.states[:green]).should be_false
|
|
44
|
+
end
|
|
17
45
|
end
|
|
18
46
|
|
|
19
|
-
describe "
|
|
47
|
+
describe "#events" do
|
|
20
48
|
|
|
21
49
|
it "should call machine.events.from(self)" do
|
|
22
50
|
machine_events = Object.new
|
|
23
|
-
mock( @machine ).events { machine_events }
|
|
51
|
+
mock( @machine ).events { machine_events }
|
|
24
52
|
mock( machine_events ).from( @state ) { nil }
|
|
25
53
|
@state.events
|
|
26
54
|
end
|
|
27
55
|
|
|
28
56
|
end
|
|
29
57
|
|
|
30
|
-
describe ".event" do
|
|
31
|
-
|
|
32
|
-
it "should act as a proxy for lathe.event without a block" do
|
|
33
|
-
lathe = Object.new
|
|
34
|
-
mock( @state ).lathe { lathe }
|
|
35
|
-
mock( lathe ).event( :evt_name, :from => :old, :to => :new ) { nil }
|
|
36
|
-
@state.event( :evt_name, :from => :old, :to => :new )
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
it "should act as a proxy for lathe.event with a block" do
|
|
40
|
-
lathe = Object.new
|
|
41
|
-
block = lambda{}
|
|
42
|
-
stub( @state ).lathe { lathe }
|
|
43
|
-
args = [:evt_name, {:from => :old, :to => :new}]
|
|
44
|
-
mock( lathe ).event( *args ) {}
|
|
45
|
-
@state.event( *args ){ puts "TODO: can't find a way to test the block is passed" }
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
end
|
|
49
58
|
end
|
|
50
59
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: davidlee-state-fu
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.10.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- David Lee
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2009-
|
|
12
|
+
date: 2009-08-25 00:00:00 -07:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies: []
|
|
15
15
|
|
|
@@ -26,6 +26,7 @@ files:
|
|
|
26
26
|
- Rakefile
|
|
27
27
|
- lib/no_stdout.rb
|
|
28
28
|
- lib/state-fu.rb
|
|
29
|
+
- lib/state_fu.rb
|
|
29
30
|
- lib/state_fu/active_support_lite/array.rb
|
|
30
31
|
- lib/state_fu/active_support_lite/array/access.rb
|
|
31
32
|
- lib/state_fu/active_support_lite/array/conversions.rb
|
|
@@ -35,25 +36,28 @@ files:
|
|
|
35
36
|
- lib/state_fu/active_support_lite/array/wrapper.rb
|
|
36
37
|
- lib/state_fu/active_support_lite/blank.rb
|
|
37
38
|
- lib/state_fu/active_support_lite/cattr_reader.rb
|
|
38
|
-
- lib/state_fu/active_support_lite/inheritable_attributes.rb
|
|
39
39
|
- lib/state_fu/active_support_lite/keys.rb
|
|
40
40
|
- lib/state_fu/active_support_lite/misc.rb
|
|
41
|
+
- lib/state_fu/active_support_lite/module.rb
|
|
42
|
+
- lib/state_fu/active_support_lite/module/delegation.rb
|
|
41
43
|
- lib/state_fu/active_support_lite/object.rb
|
|
42
44
|
- lib/state_fu/active_support_lite/string.rb
|
|
43
45
|
- lib/state_fu/active_support_lite/symbol.rb
|
|
46
|
+
- lib/state_fu/applicable.rb
|
|
47
|
+
- lib/state_fu/arrays.rb
|
|
44
48
|
- lib/state_fu/binding.rb
|
|
45
49
|
- lib/state_fu/core_ext.rb
|
|
46
50
|
- lib/state_fu/event.rb
|
|
47
51
|
- lib/state_fu/exceptions.rb
|
|
48
|
-
- lib/state_fu/
|
|
49
|
-
- lib/state_fu/
|
|
52
|
+
- lib/state_fu/executioner.rb
|
|
53
|
+
- lib/state_fu/has_options.rb
|
|
50
54
|
- lib/state_fu/hooks.rb
|
|
51
55
|
- lib/state_fu/interface.rb
|
|
52
56
|
- lib/state_fu/lathe.rb
|
|
53
57
|
- lib/state_fu/logger.rb
|
|
54
58
|
- lib/state_fu/machine.rb
|
|
55
59
|
- lib/state_fu/method_factory.rb
|
|
56
|
-
- lib/state_fu/
|
|
60
|
+
- lib/state_fu/methodical.rb
|
|
57
61
|
- lib/state_fu/persistence.rb
|
|
58
62
|
- lib/state_fu/persistence/active_record.rb
|
|
59
63
|
- lib/state_fu/persistence/attribute.rb
|
|
@@ -64,19 +68,24 @@ files:
|
|
|
64
68
|
- lib/state_fu/sprocket.rb
|
|
65
69
|
- lib/state_fu/state.rb
|
|
66
70
|
- lib/state_fu/transition.rb
|
|
71
|
+
- lib/state_fu/transition_query.rb
|
|
72
|
+
- lib/tasks/spec_last.rake
|
|
73
|
+
- lib/tasks/state_fu.rake
|
|
67
74
|
- lib/vizier.rb
|
|
68
|
-
- spec/
|
|
75
|
+
- spec/custom_formatter.rb
|
|
69
76
|
- spec/features/binding_and_transition_helper_mixin_spec.rb
|
|
77
|
+
- spec/features/method_missing_only_once_spec.rb
|
|
70
78
|
- spec/features/not_requirements_spec.rb
|
|
79
|
+
- spec/features/plotter_spec.rb
|
|
80
|
+
- spec/features/shared_log_spec.rb
|
|
81
|
+
- spec/features/singleton_machine_spec.rb
|
|
71
82
|
- spec/features/state_and_array_options_accessor_spec.rb
|
|
72
|
-
- spec/features/
|
|
83
|
+
- spec/features/transition_boolean_comparison_spec.rb
|
|
73
84
|
- spec/helper.rb
|
|
74
85
|
- spec/integration/active_record_persistence_spec.rb
|
|
75
86
|
- spec/integration/binding_extension_spec.rb
|
|
76
87
|
- spec/integration/class_accessor_spec.rb
|
|
77
|
-
- spec/integration/dynamic_requirement_spec.rb
|
|
78
88
|
- spec/integration/event_definition_spec.rb
|
|
79
|
-
- spec/integration/ex_machine_for_accounts_spec.rb
|
|
80
89
|
- spec/integration/example_01_document_spec.rb
|
|
81
90
|
- spec/integration/example_02_string_spec.rb
|
|
82
91
|
- spec/integration/instance_accessor_spec.rb
|
|
@@ -84,14 +93,14 @@ files:
|
|
|
84
93
|
- spec/integration/machine_duplication_spec.rb
|
|
85
94
|
- spec/integration/relaxdb_persistence_spec.rb
|
|
86
95
|
- spec/integration/requirement_reflection_spec.rb
|
|
87
|
-
- spec/integration/sanity_spec.rb
|
|
88
96
|
- spec/integration/state_definition_spec.rb
|
|
89
97
|
- spec/integration/transition_spec.rb
|
|
90
98
|
- spec/spec.opts
|
|
99
|
+
- spec/spec_helper.rb
|
|
100
|
+
- spec/state_fu_spec.rb
|
|
91
101
|
- spec/units/binding_spec.rb
|
|
92
102
|
- spec/units/event_spec.rb
|
|
93
103
|
- spec/units/exceptions_spec.rb
|
|
94
|
-
- spec/units/fu_space_spec.rb
|
|
95
104
|
- spec/units/lathe_spec.rb
|
|
96
105
|
- spec/units/machine_spec.rb
|
|
97
106
|
- spec/units/method_factory_spec.rb
|
|
@@ -101,6 +110,7 @@ files:
|
|
|
101
110
|
- README.textile
|
|
102
111
|
has_rdoc: false
|
|
103
112
|
homepage: http://github.com/davidlee/state-fu
|
|
113
|
+
licenses:
|
|
104
114
|
post_install_message:
|
|
105
115
|
rdoc_options:
|
|
106
116
|
- --charset=UTF-8
|
|
@@ -121,23 +131,25 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
121
131
|
requirements: []
|
|
122
132
|
|
|
123
133
|
rubyforge_project: state-fu
|
|
124
|
-
rubygems_version: 1.
|
|
134
|
+
rubygems_version: 1.3.5
|
|
125
135
|
signing_key:
|
|
126
136
|
specification_version: 3
|
|
127
137
|
summary: A rich library for state-oriented programming with state machines / workflows
|
|
128
138
|
test_files:
|
|
129
|
-
- spec/
|
|
139
|
+
- spec/custom_formatter.rb
|
|
130
140
|
- spec/features/binding_and_transition_helper_mixin_spec.rb
|
|
141
|
+
- spec/features/method_missing_only_once_spec.rb
|
|
131
142
|
- spec/features/not_requirements_spec.rb
|
|
143
|
+
- spec/features/plotter_spec.rb
|
|
144
|
+
- spec/features/shared_log_spec.rb
|
|
145
|
+
- spec/features/singleton_machine_spec.rb
|
|
132
146
|
- spec/features/state_and_array_options_accessor_spec.rb
|
|
133
|
-
- spec/features/
|
|
147
|
+
- spec/features/transition_boolean_comparison_spec.rb
|
|
134
148
|
- spec/helper.rb
|
|
135
149
|
- spec/integration/active_record_persistence_spec.rb
|
|
136
150
|
- spec/integration/binding_extension_spec.rb
|
|
137
151
|
- spec/integration/class_accessor_spec.rb
|
|
138
|
-
- spec/integration/dynamic_requirement_spec.rb
|
|
139
152
|
- spec/integration/event_definition_spec.rb
|
|
140
|
-
- spec/integration/ex_machine_for_accounts_spec.rb
|
|
141
153
|
- spec/integration/example_01_document_spec.rb
|
|
142
154
|
- spec/integration/example_02_string_spec.rb
|
|
143
155
|
- spec/integration/instance_accessor_spec.rb
|
|
@@ -145,13 +157,13 @@ test_files:
|
|
|
145
157
|
- spec/integration/machine_duplication_spec.rb
|
|
146
158
|
- spec/integration/relaxdb_persistence_spec.rb
|
|
147
159
|
- spec/integration/requirement_reflection_spec.rb
|
|
148
|
-
- spec/integration/sanity_spec.rb
|
|
149
160
|
- spec/integration/state_definition_spec.rb
|
|
150
161
|
- spec/integration/transition_spec.rb
|
|
162
|
+
- spec/spec_helper.rb
|
|
163
|
+
- spec/state_fu_spec.rb
|
|
151
164
|
- spec/units/binding_spec.rb
|
|
152
165
|
- spec/units/event_spec.rb
|
|
153
166
|
- spec/units/exceptions_spec.rb
|
|
154
|
-
- spec/units/fu_space_spec.rb
|
|
155
167
|
- spec/units/lathe_spec.rb
|
|
156
168
|
- spec/units/machine_spec.rb
|
|
157
169
|
- spec/units/method_factory_spec.rb
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
data/lib/state_fu/fu_space.rb
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
module StateFu
|
|
2
|
-
# Provides a place to stash references.
|
|
3
|
-
# In most cases you won't need to access it directly, though
|
|
4
|
-
# calling reset! before each of your tests/specs can be helpful.
|
|
5
|
-
class FuSpace
|
|
6
|
-
cattr_reader :named_machines, :class_machines, :field_names
|
|
7
|
-
|
|
8
|
-
# return the default machine, or an empty hash, given a missing index.
|
|
9
|
-
#
|
|
10
|
-
# * class_machines[ Class ][ method_name ] # => a StateFu::Machine
|
|
11
|
-
# * class_machines[ Klass ][ nil ] # => the Klass's default Machine
|
|
12
|
-
# * field_names[ Class ][ method_name ] # => name of attribute / db field
|
|
13
|
-
#
|
|
14
|
-
LAZY_HASH = lambda do |h, k|
|
|
15
|
-
if k.nil?
|
|
16
|
-
self[ StateFu::DEFAULT_MACHINE ]
|
|
17
|
-
else
|
|
18
|
-
h[k]= Hash.new()
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
# Add a machine to StateFu::FuSpace and register it with a given class, by a given name.
|
|
23
|
-
def self.insert!( klass, machine, name, field_name )
|
|
24
|
-
name = name.to_sym
|
|
25
|
-
field_name = field_name.to_sym
|
|
26
|
-
existing_machine = @@class_machines[klass][name]
|
|
27
|
-
if existing_machine && !existing_machine.empty?
|
|
28
|
-
raise("#{klass} already knows a non-empty Machine #{machine} by the name #{name}.")
|
|
29
|
-
else
|
|
30
|
-
@@class_machines[klass][name] = machine
|
|
31
|
-
@@field_names[klass][name] = field_name
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
class << self
|
|
35
|
-
alias_method :insert, :insert!
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
# Clears all machines and their bindings to classes.
|
|
39
|
-
# Also initializes the hashes we use to store our references.
|
|
40
|
-
def self.beginners_mind!
|
|
41
|
-
@@named_machines = Hash.new
|
|
42
|
-
@@class_machines = Hash.new( &LAZY_HASH )
|
|
43
|
-
@@field_names = Hash.new( &LAZY_HASH )
|
|
44
|
-
end
|
|
45
|
-
class << self
|
|
46
|
-
alias_method :reset!, :beginners_mind!
|
|
47
|
-
alias_method :forget!, :beginners_mind!
|
|
48
|
-
end
|
|
49
|
-
beginners_mind!
|
|
50
|
-
end
|
|
51
|
-
end
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
module StateFu
|
|
2
|
-
class MockTransition
|
|
3
|
-
include StateFu::Helper
|
|
4
|
-
include ContextualEval
|
|
5
|
-
|
|
6
|
-
attr_reader( :binding,
|
|
7
|
-
:machine,
|
|
8
|
-
:origin,
|
|
9
|
-
:target,
|
|
10
|
-
:event,
|
|
11
|
-
:args,
|
|
12
|
-
:errors,
|
|
13
|
-
:object,
|
|
14
|
-
:options,
|
|
15
|
-
:current_hook_slot,
|
|
16
|
-
:current_hook )
|
|
17
|
-
|
|
18
|
-
attr_accessor :test_only, :args, :options
|
|
19
|
-
|
|
20
|
-
def initialize( binding, event, target=nil, *args, &block )
|
|
21
|
-
@options = args.extract_options!.symbolize_keys!
|
|
22
|
-
if @binding = binding
|
|
23
|
-
@machine = binding.machine rescue nil
|
|
24
|
-
@object = binding.object rescue nil
|
|
25
|
-
@origin = binding.current_state rescue nil
|
|
26
|
-
end
|
|
27
|
-
@event = event
|
|
28
|
-
@target = find_event_target( event, target )
|
|
29
|
-
@args = args
|
|
30
|
-
@errors = []
|
|
31
|
-
@testing = true
|
|
32
|
-
|
|
33
|
-
machine.respond_to?(:inject_helpers_into) && machine.inject_helpers_into( self )
|
|
34
|
-
apply!( &block ) if block_given?
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
end
|
|
38
|
-
end
|