davidlee-state-fu 0.2.0 → 0.3.1
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 +6 -2
- data/Rakefile +24 -3
- data/lib/no_stdout.rb +28 -5
- data/lib/state-fu.rb +25 -21
- data/lib/state_fu/active_support_lite/misc.rb +57 -0
- data/lib/state_fu/binding.rb +51 -41
- data/lib/state_fu/core_ext.rb +5 -4
- data/lib/state_fu/event.rb +51 -16
- data/lib/state_fu/exceptions.rb +5 -0
- data/lib/state_fu/fu_space.rb +5 -4
- data/lib/state_fu/helper.rb +25 -3
- data/lib/state_fu/hooks.rb +4 -1
- data/lib/state_fu/interface.rb +20 -24
- data/lib/state_fu/lathe.rb +38 -2
- data/lib/state_fu/logger.rb +84 -6
- data/lib/state_fu/machine.rb +3 -0
- data/lib/state_fu/method_factory.rb +3 -3
- data/lib/state_fu/persistence/active_record.rb +3 -1
- data/lib/state_fu/persistence/attribute.rb +4 -4
- data/lib/state_fu/persistence/base.rb +3 -3
- data/lib/state_fu/persistence/relaxdb.rb +23 -0
- data/lib/state_fu/persistence.rb +24 -29
- data/lib/state_fu/plotter.rb +63 -0
- data/lib/state_fu/sprocket.rb +12 -0
- data/lib/state_fu/state.rb +22 -0
- data/lib/state_fu/transition.rb +13 -0
- data/lib/vizier.rb +300 -0
- data/spec/BDD/plotter_spec.rb +115 -0
- data/spec/features/binding_and_transition_helper_mixin_spec.rb +111 -0
- data/spec/features/not_requirements_spec.rb +81 -0
- data/spec/features/state_and_array_options_accessor_spec.rb +47 -0
- data/spec/features/transition_boolean_comparison.rb +90 -0
- data/spec/helper.rb +33 -0
- data/spec/integration/active_record_persistence_spec.rb +0 -1
- data/spec/integration/example_01_document_spec.rb +1 -1
- data/spec/integration/relaxdb_persistence_spec.rb +94 -0
- data/spec/integration/requirement_reflection_spec.rb +2 -2
- data/spec/integration/transition_spec.rb +9 -1
- data/spec/units/binding_spec.rb +46 -17
- data/spec/units/lathe_spec.rb +11 -10
- data/spec/units/method_factory_spec.rb +6 -1
- metadata +37 -23
- data/spec/integration/temp_spec.rb +0 -17
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../helper")
|
|
2
|
+
|
|
3
|
+
describe "extending bindings and transitions with Lathe#helper" do
|
|
4
|
+
|
|
5
|
+
include MySpecHelper
|
|
6
|
+
|
|
7
|
+
before(:each) do
|
|
8
|
+
reset!
|
|
9
|
+
make_pristine_class('Klass')
|
|
10
|
+
Klass.class_eval do
|
|
11
|
+
attr_accessor :ok
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
@machine = Klass.machine do
|
|
15
|
+
chain "a -a2b-> b -b2c-> c"
|
|
16
|
+
events.each do |e|
|
|
17
|
+
e.requires :ok
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
@obj = Klass.new
|
|
22
|
+
@binding = @obj.state_fu
|
|
23
|
+
@transition = @obj.state_fu.transition(:a2b)
|
|
24
|
+
end # before
|
|
25
|
+
|
|
26
|
+
#
|
|
27
|
+
#
|
|
28
|
+
|
|
29
|
+
describe StateFu::Transition do
|
|
30
|
+
describe "#==" do
|
|
31
|
+
|
|
32
|
+
describe "with an unaccepted transition" do
|
|
33
|
+
before do
|
|
34
|
+
stub(@transition).accepted? { false }
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "should == true" do
|
|
38
|
+
@transition.should_not == true
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "should not == false" do
|
|
42
|
+
@transition.should == false
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "should === true" do
|
|
46
|
+
@transition.should_not === true
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it "should not === false" do
|
|
50
|
+
@transition.should === false
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it "should not evaluate as truthy" do
|
|
54
|
+
pending
|
|
55
|
+
x = @transition || 1
|
|
56
|
+
x.should == 1
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
describe "with an accepted transition" do
|
|
62
|
+
before do
|
|
63
|
+
stub(@transition).accepted? { true }
|
|
64
|
+
end
|
|
65
|
+
it "should == true" do
|
|
66
|
+
@transition.should == true
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it "should not == false" do
|
|
70
|
+
@transition.should_not == false
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it "should === true" do
|
|
74
|
+
@transition.should === true
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it "should not === false" do
|
|
78
|
+
@transition.should_not === false
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it "should evaluate as truthy" do
|
|
82
|
+
x = @transition || 1
|
|
83
|
+
x.should == @transition
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
end
|
|
90
|
+
end
|
data/spec/helper.rb
CHANGED
|
@@ -6,6 +6,8 @@ $LOAD_PATH.unshift( "#{thisdir}/../lib" )
|
|
|
6
6
|
require 'state-fu'
|
|
7
7
|
require 'no_stdout'
|
|
8
8
|
|
|
9
|
+
StateFu::Logger.suppress!
|
|
10
|
+
|
|
9
11
|
require 'rubygems'
|
|
10
12
|
|
|
11
13
|
{"rr" => "rr", "spec" => "rspec" }.each do |lib, gem_name|
|
|
@@ -30,6 +32,7 @@ module MySpecHelper
|
|
|
30
32
|
begin
|
|
31
33
|
require 'activesupport'
|
|
32
34
|
require 'active_record'
|
|
35
|
+
require 'sqlite3'
|
|
33
36
|
rescue LoadError => e
|
|
34
37
|
pending "skipping specifications due to load error: #{e}"
|
|
35
38
|
return false
|
|
@@ -62,6 +65,36 @@ module MySpecHelper
|
|
|
62
65
|
end
|
|
63
66
|
end
|
|
64
67
|
|
|
68
|
+
def skip_unless_relaxdb
|
|
69
|
+
unless Object.const_defined?( 'RelaxDB' )
|
|
70
|
+
pending('Skipping specs because you do not have the relaxdb gem (paulcarey-relaxdb) installed ...')
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def prepare_relaxdb( options={} )
|
|
75
|
+
begin
|
|
76
|
+
require 'relaxdb'
|
|
77
|
+
if Object.const_defined?( "RelaxDB" )
|
|
78
|
+
RelaxDB.configure :host => "localhost", :port => 5984, :design_doc => "spec_doc"
|
|
79
|
+
RelaxDB.delete_db "relaxdb_spec" rescue "ok"
|
|
80
|
+
RelaxDB.use_db "relaxdb_spec"
|
|
81
|
+
RelaxDB.enable_view_creation
|
|
82
|
+
end
|
|
83
|
+
rescue LoadError => e
|
|
84
|
+
# pending "skipping specifications due to load error: #{e}"
|
|
85
|
+
return false
|
|
86
|
+
end
|
|
87
|
+
begin
|
|
88
|
+
RelaxDB.replicate_db "relaxdb_spec_base", "relaxdb_spec"
|
|
89
|
+
RelaxDB.enable_view_creation
|
|
90
|
+
rescue => e
|
|
91
|
+
puts "\n===== Run rake create_base_db before the first spec run ====="
|
|
92
|
+
puts
|
|
93
|
+
exit!
|
|
94
|
+
end
|
|
95
|
+
#
|
|
96
|
+
end
|
|
97
|
+
|
|
65
98
|
def make_pristine_class(class_name, superklass=Object, reset_first = false)
|
|
66
99
|
reset! if reset_first
|
|
67
100
|
@class_names ||= []
|
|
@@ -109,7 +109,6 @@ describe "an ActiveRecord model with StateFu included:" do
|
|
|
109
109
|
end
|
|
110
110
|
|
|
111
111
|
it "should fail to save if state_fu! does not instantiate the binding before create" do
|
|
112
|
-
pending "is this still relevant?"
|
|
113
112
|
mock( @ex ).state_fu!.at_least( 1 ) { }
|
|
114
113
|
lambda { @ex.save! }.should raise_error( ActiveRecord::StatementInvalid )
|
|
115
114
|
@ex.state_fu_field.should == nil
|
|
@@ -84,7 +84,7 @@ describe "Document" do
|
|
|
84
84
|
end
|
|
85
85
|
|
|
86
86
|
it "should not raise an error when publish! is called" do
|
|
87
|
-
@doc.status.
|
|
87
|
+
@doc.status.evaluate_requirement_with_args(:author).should == "Susan"
|
|
88
88
|
lambda { @doc.status.publish! }.should_not raise_error( )
|
|
89
89
|
end
|
|
90
90
|
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../helper")
|
|
2
|
+
|
|
3
|
+
describe "a RelaxDB::Document's persister" do
|
|
4
|
+
|
|
5
|
+
include MySpecHelper
|
|
6
|
+
before(:all) do
|
|
7
|
+
prepare_relaxdb()
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
before(:each) do
|
|
11
|
+
skip_unless_relaxdb()
|
|
12
|
+
reset!
|
|
13
|
+
make_pristine_class( 'ExampleDoc', RelaxDB::Document )
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "should be a subclass of RelaxDB::Document" do
|
|
17
|
+
ExampleDoc.superclass.should == RelaxDB::Document
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
describe "when no machine is defined" do
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
describe "when the :field_name is a RelaxDB property" do
|
|
24
|
+
before do
|
|
25
|
+
ExampleDoc.class_eval do
|
|
26
|
+
property :property_field
|
|
27
|
+
machine :field_name => "property_field" do
|
|
28
|
+
# ...
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
@obj = ExampleDoc.new
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "should add a relaxdb persister" do
|
|
35
|
+
@obj.state_fu.persister.class.should == StateFu::Persistence::RelaxDB
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
describe "when the :field_name is not a RelaxDB property" do
|
|
40
|
+
before do
|
|
41
|
+
ExampleDoc.class_eval do
|
|
42
|
+
machine :field_name => "not_a_property" do
|
|
43
|
+
# ...
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
@obj = ExampleDoc.new
|
|
47
|
+
end
|
|
48
|
+
it "should add an attribute-based persister" do
|
|
49
|
+
@obj.state_fu.persister.class.should == StateFu::Persistence::Attribute
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
describe StateFu::Persistence::RelaxDB do
|
|
55
|
+
before(:all) do
|
|
56
|
+
prepare_relaxdb()
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
include MySpecHelper
|
|
60
|
+
describe "a RelaxDB::Document with a simple machine" do
|
|
61
|
+
before do
|
|
62
|
+
skip_unless_relaxdb()
|
|
63
|
+
reset!
|
|
64
|
+
make_pristine_class( 'ExampleDoc', RelaxDB::Document )
|
|
65
|
+
ExampleDoc.class_eval do
|
|
66
|
+
property :state_fu_field
|
|
67
|
+
machine do
|
|
68
|
+
state :hungry do
|
|
69
|
+
event :eat, :to => :satiated
|
|
70
|
+
end
|
|
71
|
+
end # machine
|
|
72
|
+
end # class_eval
|
|
73
|
+
@obj = ExampleDoc.new
|
|
74
|
+
end # before
|
|
75
|
+
|
|
76
|
+
it "should update the property on transition acceptance" do
|
|
77
|
+
@obj.state_fu.should == :hungry
|
|
78
|
+
t = @obj.eat!
|
|
79
|
+
t.should be_accepted
|
|
80
|
+
@obj.state_fu.should == :satiated
|
|
81
|
+
@obj.send(:state_fu_field).should == 'satiated'
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it "should persist the current state of the machine to the database" do
|
|
85
|
+
@obj.state_fu.should == :hungry
|
|
86
|
+
@obj.eat!
|
|
87
|
+
@obj.state_fu.should == :satiated
|
|
88
|
+
@obj.save!
|
|
89
|
+
@obj2 = RelaxDB.load( @obj._id )
|
|
90
|
+
@obj2.state_fu.should == :satiated
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
end
|
|
94
|
+
end
|
|
@@ -50,7 +50,7 @@ describe "Transition requirement reflection" do
|
|
|
50
50
|
describe "transition.valid? / transition.requirements_met?" do
|
|
51
51
|
it "should be true if all requirements are met (return truth)" do
|
|
52
52
|
@obj.state_fu.next_states[:moon].entry_requirements.should == [:spacesuit?]
|
|
53
|
-
@obj.state_fu.
|
|
53
|
+
@obj.state_fu.evaluate_requirement_with_args(:spacesuit?).should == true
|
|
54
54
|
@obj.fly_spaceship?(:moon).should == true
|
|
55
55
|
@obj.fly_spaceship(:moon).requirements_met?.should == true
|
|
56
56
|
@obj.fly_spaceship(:moon).should be_valid
|
|
@@ -59,7 +59,7 @@ describe "Transition requirement reflection" do
|
|
|
59
59
|
it "should be false if not all requirements are met" do
|
|
60
60
|
stub( @obj ).spacesuit?() { false }
|
|
61
61
|
@obj.state_fu.next_states[:moon].entry_requirements.should == [:spacesuit?]
|
|
62
|
-
@obj.state_fu.
|
|
62
|
+
@obj.state_fu.evaluate_requirement_with_args(:spacesuit?).should == false
|
|
63
63
|
@obj.fly_spaceship?(:moon).should == false
|
|
64
64
|
@obj.fly_spaceship(:moon).requirements_met?.should == false
|
|
65
65
|
@obj.fly_spaceship(:moon).should_not be_valid
|
|
@@ -1004,7 +1004,11 @@ describe StateFu::Transition do
|
|
|
1004
1004
|
|
|
1005
1005
|
describe "when the fireable? event has multiple targets but only one can be entered" do
|
|
1006
1006
|
before do
|
|
1007
|
-
|
|
1007
|
+
reset!
|
|
1008
|
+
make_pristine_class("Klass")
|
|
1009
|
+
@machine = Klass.machine do
|
|
1010
|
+
initial_state :alive
|
|
1011
|
+
|
|
1008
1012
|
state :cremated
|
|
1009
1013
|
|
|
1010
1014
|
state :buried do
|
|
@@ -1014,15 +1018,19 @@ describe StateFu::Transition do
|
|
|
1014
1018
|
end
|
|
1015
1019
|
|
|
1016
1020
|
event :inevitability do
|
|
1021
|
+
from :alive
|
|
1017
1022
|
to :cremated, :buried
|
|
1018
1023
|
end
|
|
1019
1024
|
end
|
|
1020
1025
|
@obj = Klass.new()
|
|
1021
1026
|
@binding = @obj.state_fu
|
|
1027
|
+
@machine.events[:inevitability].should be_kind_of(StateFu::Event)
|
|
1022
1028
|
@machine.events[:inevitability].fireable_by?( @binding ).should == true
|
|
1023
1029
|
@machine.states[:cremated].enterable_by?( @binding ).should == true
|
|
1024
1030
|
@machine.states[:buried].enterable_by?( @binding ).should == false
|
|
1031
|
+
@binding.valid_events.map(&:name).should == [@machine.events[:inevitability]].map(&:name)
|
|
1025
1032
|
@binding.valid_events.should == [@machine.events[:inevitability]]
|
|
1033
|
+
@binding.valid_transitions.values.flatten.map(&:name).should == [:cremated]
|
|
1026
1034
|
@binding.valid_transitions.values.flatten.should == [@machine.states[:cremated]]
|
|
1027
1035
|
end # before
|
|
1028
1036
|
|
data/spec/units/binding_spec.rb
CHANGED
|
@@ -3,6 +3,27 @@ require File.expand_path("#{File.dirname(__FILE__)}/../helper")
|
|
|
3
3
|
describe StateFu::Binding do
|
|
4
4
|
include MySpecHelper
|
|
5
5
|
|
|
6
|
+
describe "instance methods" do
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
#
|
|
10
|
+
# class methods
|
|
11
|
+
#
|
|
12
|
+
|
|
13
|
+
describe "class methods" do
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
#
|
|
18
|
+
#
|
|
19
|
+
#
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
#
|
|
24
|
+
#
|
|
25
|
+
#
|
|
26
|
+
|
|
6
27
|
before do
|
|
7
28
|
reset!
|
|
8
29
|
make_pristine_class('Klass')
|
|
@@ -100,7 +121,7 @@ describe StateFu::Binding do
|
|
|
100
121
|
end
|
|
101
122
|
end
|
|
102
123
|
|
|
103
|
-
describe ".state
|
|
124
|
+
describe ".state and .initial_state" do
|
|
104
125
|
it "should default to machine.initial_state when no initial_state is explicitly defined" do
|
|
105
126
|
@machine.initial_state.name.should == :new
|
|
106
127
|
@binding.current_state.should == @machine.initial_state
|
|
@@ -120,31 +141,39 @@ describe StateFu::Binding do
|
|
|
120
141
|
before do
|
|
121
142
|
end
|
|
122
143
|
describe "fireable?" do
|
|
123
|
-
|
|
124
|
-
|
|
144
|
+
before do
|
|
145
|
+
reset!
|
|
146
|
+
make_pristine_class("Klass")
|
|
147
|
+
@machine = Klass.machine do
|
|
148
|
+
state :snoo do
|
|
149
|
+
event :am_fireable, :to => :wizz
|
|
150
|
+
end
|
|
151
|
+
state :wizz do
|
|
152
|
+
event :not_fireable, :to => :pong
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
@obj = Klass.new
|
|
125
156
|
end
|
|
126
157
|
|
|
127
|
-
describe "when called with arguments which would
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
make_pristine_class("Klass")
|
|
131
|
-
@machine = Klass.machine do
|
|
132
|
-
state :snoo
|
|
133
|
-
state :wizz do
|
|
134
|
-
event :ping, :to => :pong
|
|
135
|
-
end
|
|
136
|
-
end
|
|
137
|
-
@obj = Klass.new
|
|
158
|
+
describe "when called with arguments which would return a valid transition from .transition()" do
|
|
159
|
+
it "should return true" do
|
|
160
|
+
@obj.state_fu.fireable?(:am_fireable).should == true
|
|
138
161
|
end
|
|
162
|
+
end
|
|
139
163
|
|
|
164
|
+
describe "when called with arguments which would raise an InvalidTransition from .transition()" do
|
|
140
165
|
it "should return nil" do
|
|
141
166
|
@obj.state_fu.name.should == :snoo
|
|
142
|
-
lambda { @obj.state_fu.transition(:
|
|
143
|
-
lambda { @obj.state_fu.fireable?(:
|
|
144
|
-
@obj.state_fu.fireable?(:
|
|
167
|
+
lambda { @obj.state_fu.transition(:not_fireable) }.should raise_error( StateFu::InvalidTransition )
|
|
168
|
+
lambda { @obj.state_fu.fireable?(:not_fireable) }.should_not raise_error( StateFu::InvalidTransition )
|
|
169
|
+
@obj.state_fu.fireable?(:not_fireable).should == nil
|
|
145
170
|
end
|
|
146
171
|
end
|
|
147
172
|
|
|
173
|
+
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"
|
|
175
|
+
end
|
|
176
|
+
|
|
148
177
|
end
|
|
149
178
|
|
|
150
179
|
end
|
data/spec/units/lathe_spec.rb
CHANGED
|
@@ -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 ) { @lathe.sprocket }
|
|
383
|
+
mock( @machine ).find_or_create_states_by_name( @lathe.sprocket ).at_least(1) { @lathe.sprocket }
|
|
384
384
|
end
|
|
385
385
|
|
|
386
386
|
it "should create the named event if it does not exist" do
|
|
@@ -474,12 +474,11 @@ describe StateFu::Lathe do
|
|
|
474
474
|
|
|
475
475
|
describe "a child lathe for an event" do
|
|
476
476
|
before do
|
|
477
|
-
stub( @machine ).find_or_create_states_by_name(:a) { [:a] }
|
|
478
|
-
stub( @machine ).find_or_create_states_by_name(:b) { [:b] }
|
|
479
|
-
|
|
480
477
|
@master = @lathe
|
|
481
478
|
@event = @lathe.event( :go )
|
|
482
479
|
@lathe = StateFu::Lathe.new( @machine, @event )
|
|
480
|
+
stub( @machine ).find_or_create_states_by_name(:a) { [:a] }
|
|
481
|
+
stub( @machine ).find_or_create_states_by_name(:b) { [:b] }
|
|
483
482
|
end
|
|
484
483
|
|
|
485
484
|
describe ".from" do
|
|
@@ -494,16 +493,16 @@ describe StateFu::Lathe do
|
|
|
494
493
|
@event.origins.should == [:a, :b]
|
|
495
494
|
end
|
|
496
495
|
|
|
497
|
-
it "should
|
|
496
|
+
it "should accumulate @origins on successive invocations" do
|
|
498
497
|
mock( @machine ).find_or_create_states_by_name(:a, :b) { [:a, :b] }
|
|
499
498
|
mock( @machine ).find_or_create_states_by_name(:x, :y) { [:x, :y] }
|
|
500
499
|
@lathe.from( :a, :b )
|
|
501
500
|
@event.origins.should == [:a, :b]
|
|
502
501
|
@lathe.from( :x, :y )
|
|
503
|
-
@event.origins.should == [:x, :y]
|
|
502
|
+
@event.origins.should == [:a, :b, :x, :y]
|
|
504
503
|
end
|
|
505
504
|
|
|
506
|
-
it "should set both origin and target if a hash is given" do
|
|
505
|
+
it "should set / update both origin and target if a hash is given" do
|
|
507
506
|
mock( @machine ).find_or_create_states_by_name(:a) { [:a] }
|
|
508
507
|
mock( @machine ).find_or_create_states_by_name(:b) { [:b] }
|
|
509
508
|
mock( @machine ).find_or_create_states_by_name(:a, :b) { [:a, :b] }
|
|
@@ -511,9 +510,11 @@ describe StateFu::Lathe do
|
|
|
511
510
|
@lathe.from( :a => :b )
|
|
512
511
|
@event.origin.should == :a
|
|
513
512
|
@event.target.should == :b
|
|
514
|
-
@lathe.from([:a, :b] => [:x, :y] )
|
|
513
|
+
@lathe.from( { [:a, :b] => [:x, :y] })
|
|
514
|
+
@event.origin.should == nil
|
|
515
|
+
@event.target.should == nil
|
|
515
516
|
@event.origins.should == [:a, :b]
|
|
516
|
-
@event.targets.should == [:x, :y]
|
|
517
|
+
@event.targets.should == [:b, :x, :y] # accumulated total
|
|
517
518
|
end
|
|
518
519
|
end
|
|
519
520
|
|
|
@@ -535,7 +536,7 @@ describe StateFu::Lathe do
|
|
|
535
536
|
@lathe.to( :a, :b )
|
|
536
537
|
@event.targets.should == [:a, :b]
|
|
537
538
|
@lathe.to( :x, :y )
|
|
538
|
-
@event.targets.should == [:x, :y]
|
|
539
|
+
@event.targets.should == [:a, :b, :x, :y] # accumulated targets
|
|
539
540
|
end
|
|
540
541
|
end
|
|
541
542
|
|
|
@@ -59,7 +59,12 @@ describe StateFu::MethodFactory do
|
|
|
59
59
|
@obj.send(:state_fu_field).should == 'targ'
|
|
60
60
|
end
|
|
61
61
|
|
|
62
|
-
it "should
|
|
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
|
|
63
68
|
end
|
|
64
69
|
end
|
|
65
70
|
|
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.3.1
|
|
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-06-
|
|
12
|
+
date: 2009-06-26 00:00:00 -07:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies: []
|
|
15
15
|
|
|
@@ -37,6 +37,7 @@ files:
|
|
|
37
37
|
- lib/state_fu/active_support_lite/cattr_reader.rb
|
|
38
38
|
- lib/state_fu/active_support_lite/inheritable_attributes.rb
|
|
39
39
|
- lib/state_fu/active_support_lite/keys.rb
|
|
40
|
+
- lib/state_fu/active_support_lite/misc.rb
|
|
40
41
|
- lib/state_fu/active_support_lite/object.rb
|
|
41
42
|
- lib/state_fu/active_support_lite/string.rb
|
|
42
43
|
- lib/state_fu/active_support_lite/symbol.rb
|
|
@@ -57,10 +58,18 @@ files:
|
|
|
57
58
|
- lib/state_fu/persistence/active_record.rb
|
|
58
59
|
- lib/state_fu/persistence/attribute.rb
|
|
59
60
|
- lib/state_fu/persistence/base.rb
|
|
61
|
+
- lib/state_fu/persistence/relaxdb.rb
|
|
60
62
|
- lib/state_fu/persistence/session.rb
|
|
63
|
+
- lib/state_fu/plotter.rb
|
|
61
64
|
- lib/state_fu/sprocket.rb
|
|
62
65
|
- lib/state_fu/state.rb
|
|
63
66
|
- lib/state_fu/transition.rb
|
|
67
|
+
- lib/vizier.rb
|
|
68
|
+
- spec/BDD/plotter_spec.rb
|
|
69
|
+
- spec/features/binding_and_transition_helper_mixin_spec.rb
|
|
70
|
+
- spec/features/not_requirements_spec.rb
|
|
71
|
+
- spec/features/state_and_array_options_accessor_spec.rb
|
|
72
|
+
- spec/features/transition_boolean_comparison.rb
|
|
64
73
|
- spec/helper.rb
|
|
65
74
|
- spec/integration/active_record_persistence_spec.rb
|
|
66
75
|
- spec/integration/binding_extension_spec.rb
|
|
@@ -73,10 +82,10 @@ files:
|
|
|
73
82
|
- spec/integration/instance_accessor_spec.rb
|
|
74
83
|
- spec/integration/lathe_extension_spec.rb
|
|
75
84
|
- spec/integration/machine_duplication_spec.rb
|
|
85
|
+
- spec/integration/relaxdb_persistence_spec.rb
|
|
76
86
|
- spec/integration/requirement_reflection_spec.rb
|
|
77
87
|
- spec/integration/sanity_spec.rb
|
|
78
88
|
- spec/integration/state_definition_spec.rb
|
|
79
|
-
- spec/integration/temp_spec.rb
|
|
80
89
|
- spec/integration/transition_spec.rb
|
|
81
90
|
- spec/spec.opts
|
|
82
91
|
- spec/units/binding_spec.rb
|
|
@@ -117,29 +126,34 @@ signing_key:
|
|
|
117
126
|
specification_version: 3
|
|
118
127
|
summary: A rich library for state-oriented programming with state machines / workflows
|
|
119
128
|
test_files:
|
|
120
|
-
- spec/
|
|
121
|
-
- spec/
|
|
122
|
-
- spec/
|
|
123
|
-
- spec/
|
|
124
|
-
- spec/
|
|
125
|
-
- spec/units/state_spec.rb
|
|
126
|
-
- spec/units/method_factory_spec.rb
|
|
127
|
-
- spec/units/exceptions_spec.rb
|
|
128
|
-
- spec/units/fu_space_spec.rb
|
|
129
|
+
- spec/BDD/plotter_spec.rb
|
|
130
|
+
- spec/features/binding_and_transition_helper_mixin_spec.rb
|
|
131
|
+
- spec/features/not_requirements_spec.rb
|
|
132
|
+
- spec/features/state_and_array_options_accessor_spec.rb
|
|
133
|
+
- spec/features/transition_boolean_comparison.rb
|
|
129
134
|
- spec/helper.rb
|
|
130
|
-
- spec/integration/
|
|
131
|
-
- spec/integration/
|
|
135
|
+
- spec/integration/active_record_persistence_spec.rb
|
|
136
|
+
- spec/integration/binding_extension_spec.rb
|
|
132
137
|
- spec/integration/class_accessor_spec.rb
|
|
138
|
+
- spec/integration/dynamic_requirement_spec.rb
|
|
139
|
+
- spec/integration/event_definition_spec.rb
|
|
140
|
+
- spec/integration/ex_machine_for_accounts_spec.rb
|
|
141
|
+
- spec/integration/example_01_document_spec.rb
|
|
142
|
+
- spec/integration/example_02_string_spec.rb
|
|
133
143
|
- spec/integration/instance_accessor_spec.rb
|
|
134
|
-
- spec/integration/requirement_reflection_spec.rb
|
|
135
|
-
- spec/integration/binding_extension_spec.rb
|
|
136
144
|
- spec/integration/lathe_extension_spec.rb
|
|
137
145
|
- spec/integration/machine_duplication_spec.rb
|
|
138
|
-
- spec/integration/
|
|
139
|
-
- spec/integration/
|
|
146
|
+
- spec/integration/relaxdb_persistence_spec.rb
|
|
147
|
+
- spec/integration/requirement_reflection_spec.rb
|
|
140
148
|
- spec/integration/sanity_spec.rb
|
|
141
|
-
- spec/integration/
|
|
142
|
-
- spec/integration/
|
|
143
|
-
- spec/
|
|
144
|
-
- spec/
|
|
145
|
-
- spec/
|
|
149
|
+
- spec/integration/state_definition_spec.rb
|
|
150
|
+
- spec/integration/transition_spec.rb
|
|
151
|
+
- spec/units/binding_spec.rb
|
|
152
|
+
- spec/units/event_spec.rb
|
|
153
|
+
- spec/units/exceptions_spec.rb
|
|
154
|
+
- spec/units/fu_space_spec.rb
|
|
155
|
+
- spec/units/lathe_spec.rb
|
|
156
|
+
- spec/units/machine_spec.rb
|
|
157
|
+
- spec/units/method_factory_spec.rb
|
|
158
|
+
- spec/units/sprocket_spec.rb
|
|
159
|
+
- spec/units/state_spec.rb
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
require File.expand_path("#{File.dirname(__FILE__)}/../helper")
|
|
2
|
-
|
|
3
|
-
describe StateFu::State do
|
|
4
|
-
include MySpecHelper
|
|
5
|
-
|
|
6
|
-
it "should respond to deep_copy" do
|
|
7
|
-
reset!
|
|
8
|
-
make_pristine_class "Klass"
|
|
9
|
-
@machine = Klass.machine do
|
|
10
|
-
state :initial
|
|
11
|
-
end
|
|
12
|
-
@state = @machine.states.first
|
|
13
|
-
@state.should respond_to(:deep_copy)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
end
|
|
17
|
-
|