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
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
require File.expand_path("#{File.dirname(__FILE__)}/../helper")
|
|
2
2
|
|
|
3
|
-
StateFu::FuSpace.reset!
|
|
4
3
|
|
|
5
4
|
##
|
|
6
5
|
##
|
|
@@ -12,92 +11,79 @@ describe "A pristine class Klass with StateFu included:" do
|
|
|
12
11
|
make_pristine_class 'Klass'
|
|
13
12
|
end
|
|
14
13
|
|
|
15
|
-
it "should return a new Machine bound to the class given Klass.
|
|
16
|
-
Klass.should respond_to(:
|
|
17
|
-
Klass.
|
|
18
|
-
machine = Klass.
|
|
19
|
-
Klass.
|
|
14
|
+
it "should return a new Machine bound to the class given Klass.state_fu_machine()" do
|
|
15
|
+
Klass.should respond_to(:state_fu_machine)
|
|
16
|
+
Klass.state_fu_machine.should be_kind_of(StateFu::Machine)
|
|
17
|
+
machine = Klass.state_fu_machine
|
|
18
|
+
Klass.state_fu_machine.should == machine
|
|
20
19
|
end
|
|
21
20
|
|
|
22
|
-
it "should return {} given Klass.
|
|
23
|
-
Klass.should respond_to(:
|
|
24
|
-
Klass.
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
it "should return [] given Klass.machine_names()" do
|
|
28
|
-
Klass.should respond_to(:machine_names)
|
|
29
|
-
Klass.machine_names.should == []
|
|
21
|
+
it "should return {} given Klass.state_fu_machines" do
|
|
22
|
+
Klass.should respond_to(:state_fu_machines)
|
|
23
|
+
Klass.state_fu_machines.should == {}
|
|
30
24
|
end
|
|
31
25
|
|
|
32
26
|
##
|
|
33
27
|
##
|
|
34
28
|
##
|
|
35
29
|
|
|
36
|
-
describe "Having called Klass.
|
|
30
|
+
describe "Having called Klass.state_fu_machine() with an empty block:" do
|
|
37
31
|
before(:each) do
|
|
38
|
-
Klass.
|
|
32
|
+
Klass.state_fu_machine do
|
|
39
33
|
end
|
|
40
|
-
StateFu::DEFAULT_MACHINE.should == :state_fu
|
|
41
34
|
end
|
|
42
35
|
|
|
43
|
-
it "should return a StateFu::Machine given Klass.
|
|
44
|
-
Klass.should respond_to(:
|
|
45
|
-
Klass.
|
|
46
|
-
Klass.
|
|
36
|
+
it "should return a StateFu::Machine given Klass.state_fu_machine()" do
|
|
37
|
+
Klass.should respond_to(:state_fu_machine)
|
|
38
|
+
Klass.state_fu_machine.should_not be_nil
|
|
39
|
+
Klass.state_fu_machine.should be_kind_of( StateFu::Machine )
|
|
47
40
|
end
|
|
48
41
|
|
|
49
|
-
it "should return { :
|
|
50
|
-
Klass.should respond_to(:
|
|
51
|
-
machines = Klass.
|
|
42
|
+
it "should return { :default => <StateFu::Machine> } given Klass.state_fu_machines()" do
|
|
43
|
+
Klass.should respond_to(:state_fu_machines)
|
|
44
|
+
machines = Klass.state_fu_machines()
|
|
52
45
|
machines.should be_kind_of(Hash)
|
|
53
46
|
machines.should_not be_empty
|
|
54
47
|
machines.length.should == 1
|
|
55
|
-
machines.keys.should == [
|
|
48
|
+
machines.keys.should == [StateFu::DEFAULT]
|
|
56
49
|
machines.values.first.should be_kind_of( StateFu::Machine )
|
|
57
50
|
end
|
|
58
51
|
|
|
59
|
-
|
|
60
|
-
Klass.should respond_to(:machine_names)
|
|
61
|
-
Klass.machine_names.should == [:state_fu]
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
describe "Having called Klass.machine(:two) with an empty block:" do
|
|
52
|
+
describe "Having called Klass.state_fu_machine(:two) with an empty block:" do
|
|
65
53
|
before(:each) do
|
|
66
|
-
Klass.
|
|
54
|
+
Klass.state_fu_machine(:two) do
|
|
67
55
|
end
|
|
68
56
|
end
|
|
69
57
|
|
|
70
|
-
it "should return a StateFu::Machine given Klass.
|
|
71
|
-
Klass.should respond_to(:
|
|
72
|
-
Klass.
|
|
73
|
-
Klass.
|
|
58
|
+
it "should return a StateFu::Machine given Klass.state_fu_machine(:two)" do
|
|
59
|
+
Klass.should respond_to(:state_fu_machine)
|
|
60
|
+
Klass.state_fu_machine(:two).should_not be_nil
|
|
61
|
+
Klass.state_fu_machine(:two).should be_kind_of( StateFu::Machine )
|
|
74
62
|
end
|
|
75
63
|
|
|
76
|
-
it "should return a new Machine given Klass.
|
|
77
|
-
Klass.should respond_to(:
|
|
78
|
-
Klass.
|
|
79
|
-
three = Klass.
|
|
80
|
-
Klass.
|
|
81
|
-
|
|
64
|
+
it "should return a new Machine given Klass.state_fu_machine(:three)" do
|
|
65
|
+
Klass.should respond_to(:state_fu_machine)
|
|
66
|
+
Klass.state_fu_machine(:three).should be_kind_of( StateFu::Machine )
|
|
67
|
+
three = Klass.state_fu_machine(:three)
|
|
68
|
+
Klass.state_fu_machines[:three].should == three
|
|
69
|
+
Klass.state_fu_machine(:three).should == three
|
|
82
70
|
end
|
|
83
71
|
|
|
84
|
-
it "should return { :
|
|
85
|
-
Klass.should respond_to(:
|
|
86
|
-
machines = Klass.
|
|
72
|
+
it "should return { :default => <StateFu::Machine>, :two => <StateFu::Machine> } given Klass.state_fu_machines()" do
|
|
73
|
+
Klass.should respond_to(:state_fu_machines)
|
|
74
|
+
machines = Klass.state_fu_machines()
|
|
87
75
|
machines.should be_kind_of(Hash)
|
|
88
76
|
machines.should_not be_empty
|
|
89
77
|
machines.length.should == 2
|
|
90
|
-
machines.keys.should include
|
|
78
|
+
machines.keys.should include StateFu::DEFAULT
|
|
91
79
|
machines.keys.should include :two
|
|
92
80
|
machines.values.length.should == 2
|
|
93
81
|
machines.values.each { |v| v.should be_kind_of( StateFu::Machine ) }
|
|
94
82
|
end
|
|
95
83
|
|
|
96
|
-
it "should return [
|
|
97
|
-
Klass.should respond_to(:
|
|
98
|
-
Klass.
|
|
99
|
-
Klass.machine_names.should include :state_fu
|
|
100
|
-
Klass.machine_names.should include :two
|
|
84
|
+
it "should return [DEFAULT, :two] give Klass.state_fu_machines.keys" do
|
|
85
|
+
Klass.should respond_to(:state_fu_machines)
|
|
86
|
+
Klass.state_fu_machines.keys.should =~ [StateFu::DEFAULT, :two]
|
|
101
87
|
end
|
|
102
88
|
end
|
|
103
89
|
|
|
@@ -110,16 +96,20 @@ describe "A pristine class Klass with StateFu included:" do
|
|
|
110
96
|
|
|
111
97
|
# sorry, Lamarckism not supported
|
|
112
98
|
it "does NOT inherit it's parent class' Machines !!" do
|
|
113
|
-
Child.
|
|
99
|
+
Child.state_fu_machine.should_not == Klass.state_fu_machine
|
|
114
100
|
end
|
|
115
101
|
|
|
116
|
-
it "should know the Machine after calling Klass.
|
|
117
|
-
Child.
|
|
118
|
-
Klass.
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
102
|
+
it "should know the Machine after calling Klass.state_fu_machine.bind!( Child )" do
|
|
103
|
+
Child.state_fu_machine.should_not == Klass.state_fu_machine
|
|
104
|
+
Klass.state_fu_machine.bind!( Child )
|
|
105
|
+
Klass.state_fu_machines.should == { StateFu::DEFAULT => Klass.state_fu_machine }
|
|
106
|
+
Child.state_fu_machine.should == Klass.state_fu_machine
|
|
107
|
+
Klass.state_fu_machine.bind!( Child, :snoo )
|
|
108
|
+
Child.state_fu_machines.should == {
|
|
109
|
+
StateFu::DEFAULT => Klass.state_fu_machine,
|
|
110
|
+
:snoo => Klass.state_fu_machine
|
|
111
|
+
}
|
|
112
|
+
Child.state_fu_machine(:snoo).should == Klass.state_fu_machine
|
|
123
113
|
end
|
|
124
114
|
|
|
125
115
|
end
|
|
@@ -12,18 +12,18 @@ describe "Adding events to a Machine outside a state block" do
|
|
|
12
12
|
before do
|
|
13
13
|
reset!
|
|
14
14
|
make_pristine_class 'Klass'
|
|
15
|
-
Klass.
|
|
15
|
+
Klass.state_fu_machine() { }
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
describe "calling Klass.
|
|
18
|
+
describe "calling Klass.state_fu_machine().events" do
|
|
19
19
|
it "should return []" do
|
|
20
|
-
Klass.
|
|
20
|
+
Klass.state_fu_machine().events.should == []
|
|
21
21
|
end
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
-
describe "calling event(:die){ from :dead, :to => :alive } in a Klass.
|
|
24
|
+
describe "calling event(:die){ from :dead, :to => :alive } in a Klass.state_fu_machine()" do
|
|
25
25
|
before do
|
|
26
|
-
Klass.
|
|
26
|
+
Klass.state_fu_machine do
|
|
27
27
|
event :die do # arity == 0
|
|
28
28
|
from :dead, :to => :alive
|
|
29
29
|
end
|
|
@@ -31,31 +31,31 @@ describe "Adding events to a Machine outside a state block" do
|
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
it "should require a name when calling machine.event()" do
|
|
34
|
-
lambda { Klass.
|
|
34
|
+
lambda { Klass.state_fu_machine(){ event {} } }.should raise_error(ArgumentError)
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
it "should add 2 states to the machine called: [:dead, :alive] " do
|
|
38
|
-
Klass.
|
|
39
|
-
Klass.
|
|
40
|
-
Klass.
|
|
41
|
-
Klass.
|
|
38
|
+
Klass.state_fu_machine.state_names.should == [:dead, :alive]
|
|
39
|
+
Klass.state_fu_machine.states.length.should == 2
|
|
40
|
+
Klass.state_fu_machine.states.each { |s| s.should be_kind_of(StateFu::State) }
|
|
41
|
+
Klass.state_fu_machine.states.map(&:name).sort.should == [:alive, :dead]
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
describe "the <StateFu::Event> created" do
|
|
45
|
-
it "should be accessible through Klass.
|
|
46
|
-
Klass.
|
|
47
|
-
Klass.
|
|
48
|
-
Klass.
|
|
49
|
-
Klass.
|
|
45
|
+
it "should be accessible through Klass.state_fu_machine.events" do
|
|
46
|
+
Klass.state_fu_machine.events.should be_kind_of(Array)
|
|
47
|
+
Klass.state_fu_machine.events.length.should == 1
|
|
48
|
+
Klass.state_fu_machine.events.first.should be_kind_of( StateFu::Event )
|
|
49
|
+
Klass.state_fu_machine.events.first.name.should == :die
|
|
50
50
|
end
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
end
|
|
54
54
|
|
|
55
55
|
# arity of blocks is optional, thanks to magic fairy dust ;)
|
|
56
|
-
describe "calling event(:die){ |s| s.from :dead, :to => :alive } in a Klass.
|
|
56
|
+
describe "calling event(:die){ |s| s.from :dead, :to => :alive } in a Klass.state_fu_machine()" do
|
|
57
57
|
before do
|
|
58
|
-
Klass.
|
|
58
|
+
Klass.state_fu_machine do
|
|
59
59
|
event :die do |s|
|
|
60
60
|
s.from :dead, :to => :alive
|
|
61
61
|
end
|
|
@@ -63,9 +63,9 @@ describe "Adding events to a Machine outside a state block" do
|
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
it "should add 2 states to the machine called [:dead, :alive] " do
|
|
66
|
-
Klass.
|
|
67
|
-
Klass.
|
|
68
|
-
Klass.
|
|
66
|
+
Klass.state_fu_machine.state_names.should == [:dead, :alive]
|
|
67
|
+
Klass.state_fu_machine.states.length.should == 2
|
|
68
|
+
Klass.state_fu_machine.states.each { |s| s.should be_kind_of( StateFu::State ) }
|
|
69
69
|
end
|
|
70
70
|
end
|
|
71
71
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
require File.expand_path("#{File.dirname(__FILE__)}/../helper")
|
|
2
2
|
|
|
3
|
-
# require 'activesupport'
|
|
3
|
+
# require 'activesupport'
|
|
4
4
|
# require 'activerecord'
|
|
5
5
|
|
|
6
6
|
describe "Document" do
|
|
@@ -26,7 +26,7 @@ describe "Document" do
|
|
|
26
26
|
# puts "new feed!"
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
state_fu_machine( :status ) do
|
|
30
30
|
state :draft do
|
|
31
31
|
event :publish, :to => :published
|
|
32
32
|
end
|
|
@@ -40,8 +40,8 @@ describe "Document" do
|
|
|
40
40
|
execute :destroy
|
|
41
41
|
end
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
states do
|
|
44
|
+
accepted :save!
|
|
45
45
|
end
|
|
46
46
|
end
|
|
47
47
|
end
|
|
@@ -61,6 +61,7 @@ describe "Document" do
|
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
it "should raise a RequirementError when publish! is called" do
|
|
64
|
+
@doc.status.name.should == :draft
|
|
64
65
|
lambda { @doc.status.publish! }.should raise_error( StateFu::RequirementError )
|
|
65
66
|
begin
|
|
66
67
|
@doc.status.publish!
|
|
@@ -84,12 +85,11 @@ describe "Document" do
|
|
|
84
85
|
end
|
|
85
86
|
|
|
86
87
|
it "should not raise an error when publish! is called" do
|
|
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
|
|
|
91
91
|
it "should call update_rss when publish! is called" do
|
|
92
|
-
mock( @doc ).update_rss() {}
|
|
92
|
+
mock( @doc ).update_rss(anything) {}
|
|
93
93
|
@doc.status.publish!
|
|
94
94
|
end
|
|
95
95
|
|
|
@@ -99,7 +99,12 @@ describe "Document" do
|
|
|
99
99
|
end
|
|
100
100
|
|
|
101
101
|
describe "status_field attribute" do
|
|
102
|
-
|
|
102
|
+
|
|
103
|
+
# need to think about this
|
|
104
|
+
#
|
|
105
|
+
# it "should be private in ruby 1.8 and 1.9" do
|
|
106
|
+
# lambda { @doc.status_field }.should raise_error()
|
|
107
|
+
# end
|
|
103
108
|
|
|
104
109
|
it "should be defined before state_fu is called" do
|
|
105
110
|
@doc.send( :status_field ).should == 'draft'
|
|
@@ -119,7 +124,7 @@ describe "Document" do
|
|
|
119
124
|
describe "delete!" do
|
|
120
125
|
|
|
121
126
|
it "should execute destroy()" do
|
|
122
|
-
mock( @doc ).destroy() {}
|
|
127
|
+
mock( @doc ).destroy(anything) {}
|
|
123
128
|
@doc.status.delete!
|
|
124
129
|
end
|
|
125
130
|
|
|
@@ -24,6 +24,7 @@ describe String do
|
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
def shell_escape
|
|
27
|
+
#
|
|
27
28
|
klone = clone
|
|
28
29
|
begin
|
|
29
30
|
klone.shell.escape!
|
|
@@ -32,7 +33,7 @@ describe String do
|
|
|
32
33
|
klone
|
|
33
34
|
end
|
|
34
35
|
|
|
35
|
-
|
|
36
|
+
state_fu_machine (:shell) do
|
|
36
37
|
event(:escape, :from => {:dirty => :clean}) do
|
|
37
38
|
execute :sanitize_for_shell!
|
|
38
39
|
end
|
|
@@ -48,7 +49,7 @@ describe String do
|
|
|
48
49
|
it "should call sanitize_for_shell! when shell.escape! is called, and be clean afterwards " do
|
|
49
50
|
@str.should be_dirty
|
|
50
51
|
@str.should_not be_clean
|
|
51
|
-
mock( @str ).sanitize_for_shell! {}
|
|
52
|
+
mock( @str ).sanitize_for_shell!(anything) {}
|
|
52
53
|
@str.shell.escape!
|
|
53
54
|
@str.should_not be_dirty
|
|
54
55
|
@str.should be_clean
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
require File.expand_path("#{File.dirname(__FILE__)}/../helper")
|
|
2
2
|
|
|
3
|
-
StateFu::FuSpace.reset!
|
|
4
|
-
|
|
5
3
|
##
|
|
6
4
|
##
|
|
7
5
|
##
|
|
@@ -14,32 +12,31 @@ describe "An instance of Klass with StateFu included:" do
|
|
|
14
12
|
end
|
|
15
13
|
|
|
16
14
|
describe "when no machine is defined" do
|
|
17
|
-
it "should
|
|
18
|
-
@k.state_fu().should
|
|
15
|
+
it "should raise an ArgumentError given .state_fu()" do
|
|
16
|
+
lambda { @k.state_fu() }.should raise_error(ArgumentError)
|
|
19
17
|
end
|
|
20
18
|
|
|
21
19
|
it "should return {} given .bindings()" do
|
|
22
|
-
@k.
|
|
20
|
+
@k.state_fu_bindings.should == {}
|
|
23
21
|
end
|
|
24
22
|
|
|
25
23
|
it "should return [] given .state_fu!()" do
|
|
26
24
|
@k.state_fu!.should == []
|
|
27
|
-
end
|
|
25
|
+
end
|
|
28
26
|
end # no machine
|
|
29
27
|
|
|
30
28
|
describe "when an empty machine is defined for the class with the default name:" do
|
|
31
29
|
before(:each) do
|
|
32
|
-
Klass.
|
|
33
|
-
StateFu::DEFAULT_MACHINE.should == :state_fu
|
|
30
|
+
Klass.state_fu_machine() {}
|
|
34
31
|
end
|
|
35
32
|
|
|
36
33
|
it "should return a StateFu::Binding given .state_fu()" do
|
|
37
|
-
@k.
|
|
34
|
+
@k.state_fu_binding.should be_kind_of( StateFu::Binding )
|
|
38
35
|
end
|
|
39
36
|
|
|
40
37
|
describe "before a binding is instantiated by calling .state_fu() or .state_fu!" do
|
|
41
38
|
it "should return {} given .bindings()" do
|
|
42
|
-
@k.bindings
|
|
39
|
+
@k.bindings.should == {}
|
|
43
40
|
end
|
|
44
41
|
end
|
|
45
42
|
|
|
@@ -50,7 +47,7 @@ describe "An instance of Klass with StateFu included:" do
|
|
|
50
47
|
|
|
51
48
|
it "should return { :state_fu => <StateFu::Binding>} given .bindings()" do
|
|
52
49
|
@k.bindings().length.should == 1
|
|
53
|
-
@k.bindings().keys.should == [
|
|
50
|
+
@k.bindings().keys.should == [StateFu::DEFAULT]
|
|
54
51
|
@k.bindings().values.first.should be_kind_of( StateFu::Binding )
|
|
55
52
|
end
|
|
56
53
|
end
|
|
@@ -59,7 +56,7 @@ describe "An instance of Klass with StateFu included:" do
|
|
|
59
56
|
it "should return { :state_fu => <StateFu::Binding>} given .bindings()" do
|
|
60
57
|
@k.state_fu!()
|
|
61
58
|
@k.bindings().length.should == 1
|
|
62
|
-
@k.bindings().keys.should == [
|
|
59
|
+
@k.bindings().keys.should == [StateFu::DEFAULT]
|
|
63
60
|
@k.bindings().values.first.should be_kind_of( StateFu::Binding )
|
|
64
61
|
end
|
|
65
62
|
end
|
|
@@ -71,29 +68,29 @@ describe "An instance of Klass with StateFu included:" do
|
|
|
71
68
|
|
|
72
69
|
describe "when there is an empty machine called :two for the class" do
|
|
73
70
|
before(:each) do
|
|
74
|
-
Klass.
|
|
71
|
+
Klass.state_fu_machine(:two) {}
|
|
75
72
|
end
|
|
76
73
|
|
|
77
74
|
it "should return the same Binding given .state_fu() and .state_fu(:state_fu)" do
|
|
78
75
|
@k.state_fu().should be_kind_of( StateFu::Binding )
|
|
79
|
-
@k.state_fu().should == @k.state_fu(
|
|
76
|
+
@k.state_fu().should == @k.state_fu(StateFu::DEFAULT)
|
|
80
77
|
end
|
|
81
78
|
|
|
82
79
|
it "should return a StateFu::Binding for the machine called :two given .state_fu(:two)" do
|
|
83
80
|
@k.state_fu(:two).should be_kind_of( StateFu::Binding )
|
|
84
|
-
@k.state_fu(:two).should_not == @k.state_fu(
|
|
85
|
-
@k.state_fu(:two).machine.should == Klass.
|
|
81
|
+
@k.state_fu(:two).should_not == @k.state_fu(StateFu::DEFAULT)
|
|
82
|
+
@k.state_fu(:two).machine.should == Klass.state_fu_machine(:two)
|
|
86
83
|
end
|
|
87
84
|
|
|
88
|
-
it "should
|
|
89
|
-
@k.state_fu(:hibiscus).should
|
|
85
|
+
it "should raise an ArgumentError when .state_fu() is called with the name of a machine which doesn't exist" do
|
|
86
|
+
lambda { @k.state_fu(:hibiscus) }.should raise_error(ArgumentError)
|
|
90
87
|
end
|
|
91
88
|
|
|
92
89
|
it "should return an array of the two StateFu::Bindings given .state_fu!" do
|
|
93
90
|
@k.state_fu!.should be_kind_of( Array )
|
|
94
91
|
@k.state_fu!.length.should == 2
|
|
95
92
|
@k.state_fu!.each { |m| m.should be_kind_of( StateFu::Binding ) }
|
|
96
|
-
@k.state_fu!.map(&:method_name).sort_by(&:to_s).should == [
|
|
93
|
+
@k.state_fu!.map(&:method_name).sort_by(&:to_s).should == [StateFu::DEFAULT, :two]
|
|
97
94
|
end
|
|
98
95
|
end
|
|
99
96
|
end
|
|
@@ -12,7 +12,7 @@ describe "extending StateFu::Lathe" do
|
|
|
12
12
|
before do
|
|
13
13
|
reset!
|
|
14
14
|
make_pristine_class('Klass')
|
|
15
|
-
@machine = Klass.
|
|
15
|
+
@machine = Klass.state_fu_machine() do
|
|
16
16
|
state :init
|
|
17
17
|
end
|
|
18
18
|
end # before
|
|
@@ -56,7 +56,7 @@ describe "extending StateFu::Lathe" do
|
|
|
56
56
|
tool :bench_grinder
|
|
57
57
|
snark()
|
|
58
58
|
end
|
|
59
|
-
m2 = Klass.
|
|
59
|
+
m2 = Klass.state_fu_machine(:two) do
|
|
60
60
|
end
|
|
61
61
|
lambda { m2.lathe.snark }.should raise_error( NoMethodError )
|
|
62
62
|
end
|
|
@@ -12,7 +12,7 @@ describe "Copying / cloning a Machine" do
|
|
|
12
12
|
before do
|
|
13
13
|
reset!
|
|
14
14
|
make_pristine_class("Klass")
|
|
15
|
-
@original = Klass.
|
|
15
|
+
@original = Klass.state_fu_machine do
|
|
16
16
|
state :a do
|
|
17
17
|
event :goto_b, :to => :b
|
|
18
18
|
end
|
|
@@ -20,24 +20,37 @@ describe "Copying / cloning a Machine" do
|
|
|
20
20
|
@copy = @original.clone
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
state( :b, :picture => "Bee" ) do
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
@copy. events[:goto_b].options[:wibble].should == :updated
|
|
33
|
-
@original.events[:goto_b].options[:wibble].should == :updated
|
|
34
|
-
@copy. states[:b].options[:picture].should == 'Bee'
|
|
35
|
-
@original.states[:b].options[:picture].should == 'Bee'
|
|
36
|
-
end
|
|
23
|
+
# let's just test for strict object equality w/ equal? and call it a day
|
|
24
|
+
|
|
25
|
+
it "should update an event's options in the original when it's changed in the copy" do
|
|
26
|
+
@original.events[:goto_b].should be_equal @copy.events[:goto_b]
|
|
27
|
+
@original.events[:goto_b].options.should be_equal @copy.events[:goto_b].options
|
|
28
|
+
end
|
|
37
29
|
|
|
38
|
-
it "should update the original
|
|
39
|
-
|
|
40
|
-
|
|
30
|
+
it "should update a state's options in the original when it's changed in the copy" do
|
|
31
|
+
@original.states[:a].should be_equal @copy.states[:a]
|
|
32
|
+
@original.states[:a].options.should be_equal @copy.states[:a].options
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "should update the original when an event is added to the clone" do
|
|
36
|
+
@original.events.should be_equal @copy.events
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "should update the original when a state is added to the clone" do
|
|
40
|
+
@original.states.should be_equal @copy.states
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "should update the original with any changes to helpers" do
|
|
44
|
+
@original.helpers.should be_equal @copy.helpers
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "should update the original with any changes to named_procs" do
|
|
48
|
+
@original.named_procs.should be_equal @copy.named_procs
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "should update the original with any changes to requirement_messages" do
|
|
52
|
+
@original.requirement_messages.should be_equal @copy.requirement_messages
|
|
53
|
+
end
|
|
41
54
|
|
|
42
55
|
end # shallow
|
|
43
56
|
|
|
@@ -45,7 +58,7 @@ describe "Copying / cloning a Machine" do
|
|
|
45
58
|
before do
|
|
46
59
|
reset!
|
|
47
60
|
make_pristine_class("Klass")
|
|
48
|
-
@original = Klass.
|
|
61
|
+
@original = Klass.state_fu_machine do
|
|
49
62
|
state :a do
|
|
50
63
|
event :goto_b, :to => :b
|
|
51
64
|
end
|
|
@@ -53,26 +66,35 @@ describe "Copying / cloning a Machine" do
|
|
|
53
66
|
@copy = @original.deep_copy()
|
|
54
67
|
end
|
|
55
68
|
|
|
56
|
-
it "should NOT update
|
|
57
|
-
@
|
|
58
|
-
@
|
|
69
|
+
it "should NOT update an event's options in the original when it's changed in the copy" do
|
|
70
|
+
@original.events[:goto_b].should_not be_equal @copy.events[:goto_b]
|
|
71
|
+
@original.events[:goto_b].options.should_not be_equal @copy.events[:goto_b].options
|
|
72
|
+
end
|
|
59
73
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
state( :b, :picture => "Bee" ) do
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
@copy. events[:goto_b].options[:wibble].should == :updated
|
|
68
|
-
@original.events[:goto_b].options[:wibble].should == nil
|
|
69
|
-
@copy. states[:b].options[:picture].should == 'Bee'
|
|
70
|
-
@original.states[:b].options[:picture].should == nil
|
|
71
|
-
end
|
|
74
|
+
it "should NOT update a state's options in the original when it's changed in the copy" do
|
|
75
|
+
@original.states[:a].should_not be_equal @copy.states[:a]
|
|
76
|
+
@original.states[:a].options.should_not be_equal @copy.states[:a].options
|
|
77
|
+
end
|
|
72
78
|
|
|
73
|
-
it "should NOT update the original
|
|
74
|
-
|
|
75
|
-
|
|
79
|
+
it "should NOT update the original when an event is added to the clone" do
|
|
80
|
+
@original.events.should_not be_equal @copy.events
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it "should NOT update the original when a state is added to the clone" do
|
|
84
|
+
@original.states.should_not be_equal @copy.states
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it "should NOT update the original with any changes to helpers" do
|
|
88
|
+
@original.helpers.should_not be_equal @copy.helpers
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it "should NOT update the original with any changes to named_procs" do
|
|
92
|
+
@original.named_procs.should_not be_equal @copy.named_procs
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
it "should NOT update the original with any changes to requirement_messages" do
|
|
96
|
+
@original.requirement_messages.should_not be_equal @copy.requirement_messages
|
|
97
|
+
end
|
|
76
98
|
|
|
77
99
|
end # deep
|
|
78
100
|
|
|
@@ -8,6 +8,9 @@ describe "a RelaxDB::Document's persister" do
|
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
before(:each) do
|
|
11
|
+
if skip_slow_specs?
|
|
12
|
+
skip_slow_specs and return false
|
|
13
|
+
end
|
|
11
14
|
skip_unless_relaxdb()
|
|
12
15
|
reset!
|
|
13
16
|
make_pristine_class( 'ExampleDoc', RelaxDB::Document )
|
|
@@ -24,7 +27,7 @@ describe "a RelaxDB::Document's persister" do
|
|
|
24
27
|
before do
|
|
25
28
|
ExampleDoc.class_eval do
|
|
26
29
|
property :property_field
|
|
27
|
-
|
|
30
|
+
state_fu_machine :field_name => "property_field" do
|
|
28
31
|
# ...
|
|
29
32
|
end
|
|
30
33
|
end
|
|
@@ -39,7 +42,7 @@ describe "a RelaxDB::Document's persister" do
|
|
|
39
42
|
describe "when the :field_name is not a RelaxDB property" do
|
|
40
43
|
before do
|
|
41
44
|
ExampleDoc.class_eval do
|
|
42
|
-
|
|
45
|
+
state_fu_machine :field_name => "not_a_property" do
|
|
43
46
|
# ...
|
|
44
47
|
end
|
|
45
48
|
end
|
|
@@ -64,7 +67,7 @@ describe StateFu::Persistence::RelaxDB do
|
|
|
64
67
|
make_pristine_class( 'ExampleDoc', RelaxDB::Document )
|
|
65
68
|
ExampleDoc.class_eval do
|
|
66
69
|
property :state_fu_field
|
|
67
|
-
|
|
70
|
+
state_fu_machine do
|
|
68
71
|
state :hungry do
|
|
69
72
|
event :eat, :to => :satiated
|
|
70
73
|
end
|