stateful.rb 2.0.0 → 2.2.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 (55) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +137 -0
  3. data/Gemfile +2 -0
  4. data/README.md +309 -0
  5. data/lib/Stateful/Sequel/ClassMethods.rb +117 -0
  6. data/lib/Stateful/Sequel.rb +30 -0
  7. data/lib/Stateful/VERSION.rb +1 -1
  8. data/lib/Stateful.rb +4 -1
  9. data/stateful.rb.gemspec +42 -0
  10. data/test/ActiveRecord/WithColumnName.rb +159 -0
  11. data/test/ActiveRecord/WithExplicitDeterministicEventOrdering.rb +159 -0
  12. data/test/ActiveRecord/WithExplicitGlobalNonDeterministicEventOrdering.rb +165 -0
  13. data/test/ActiveRecord/WithExplicitGlobalNonDeterministicEventOrderingAndInitialStateBlock.rb +163 -0
  14. data/test/ActiveRecord/WithExplicitNonDeterministicEventOrdering.rb +161 -0
  15. data/test/ActiveRecord/WithInitialStateBlock.rb +157 -0
  16. data/test/ActiveRecord/WithMultipleFinalStates.rb +188 -0
  17. data/test/ActiveRecord/WithMultipleStateMachines.rb +221 -0
  18. data/test/ActiveRecord/WithMultipleStateMachinesAndStatefulBlock.rb +223 -0
  19. data/test/ActiveRecord/WithPersistenceNonSpecificExtend.rb +159 -0
  20. data/test/ActiveRecord/WithPersistenceNonSpecificExtendAndStatefulBlock.rb +161 -0
  21. data/test/ActiveRecord/WithPersistenceSpecificExtend.rb +159 -0
  22. data/test/ActiveRecord/WithPersistenceSpecificExtendAndStatefulBlock.rb +161 -0
  23. data/test/ActiveRecord/test_helper.rb +9 -0
  24. data/test/ActiveRecord.rb +5 -0
  25. data/test/Poro/WithExplicitDeterministicEventOrdering.rb +147 -0
  26. data/test/Poro/WithExplicitGlobalNonDeterministicEventOrdering.rb +153 -0
  27. data/test/Poro/WithExplicitGlobalNonDeterministicEventOrderingAndInitialStateBlock.rb +151 -0
  28. data/test/Poro/WithExplicitNonDeterministicEventOrdering.rb +149 -0
  29. data/test/Poro/WithInitialStateBlock.rb +145 -0
  30. data/test/Poro/WithMultipleFinalStates.rb +176 -0
  31. data/test/Poro/WithMultipleStateMachines.rb +192 -0
  32. data/test/Poro/WithMultipleStateMachinesAndStatefulBlock.rb +194 -0
  33. data/test/Poro/WithPersistenceNonSpecificExtend.rb +147 -0
  34. data/test/Poro/WithPersistenceNonSpecificExtendAndStatefulBlock.rb +149 -0
  35. data/test/Poro/WithPersistenceSpecificExtend.rb +147 -0
  36. data/test/Poro/WithPersistenceSpecificExtendAndStatefulBlock.rb +149 -0
  37. data/test/Poro/WithVariableName.rb +147 -0
  38. data/test/Poro.rb +5 -0
  39. data/test/Sequel/WithColumnName.rb +154 -0
  40. data/test/Sequel/WithExplicitDeterministicEventOrdering.rb +154 -0
  41. data/test/Sequel/WithExplicitGlobalNonDeterministicEventOrdering.rb +160 -0
  42. data/test/Sequel/WithExplicitGlobalNonDeterministicEventOrderingAndInitialStateBlock.rb +158 -0
  43. data/test/Sequel/WithExplicitNonDeterministicEventOrdering.rb +156 -0
  44. data/test/Sequel/WithInitialStateBlock.rb +152 -0
  45. data/test/Sequel/WithMultipleFinalStates.rb +183 -0
  46. data/test/Sequel/WithMultipleStateMachines.rb +216 -0
  47. data/test/Sequel/WithMultipleStateMachinesAndStatefulBlock.rb +218 -0
  48. data/test/Sequel/WithPersistenceNonSpecificExtend.rb +154 -0
  49. data/test/Sequel/WithPersistenceNonSpecificExtendAndStatefulBlock.rb +156 -0
  50. data/test/Sequel/WithPersistenceSpecificExtend.rb +154 -0
  51. data/test/Sequel/WithPersistenceSpecificExtendAndStatefulBlock.rb +156 -0
  52. data/test/Sequel/test_helper.rb +5 -0
  53. data/test/Sequel.rb +5 -0
  54. data/test/Stateful.rb +15 -0
  55. metadata +69 -4
@@ -0,0 +1,218 @@
1
+ # test/Sequel/WithMultipleStateMachinesAndStatefulBlock.rb
2
+
3
+ gem 'minitest'
4
+ gem 'minitest-spec-context'
5
+
6
+ require 'minitest/autorun'
7
+ require 'minitest-spec-context'
8
+
9
+ require_relative './test_helper'
10
+
11
+ lib_dir = File.expand_path(File.join(__FILE__, '..', '..', '..', 'lib'))
12
+ $LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)
13
+
14
+ require 'Stateful'
15
+
16
+ DB.create_table :sequel_machine12s do
17
+ primary_key :id
18
+ String :fulfilment_state
19
+ String :payment_state
20
+ end
21
+
22
+ class SequelMachine12 < Sequel::Model
23
+ extend Stateful
24
+
25
+ stateful do
26
+ state_machine :fulfilment do
27
+ initial_state :pending do
28
+ on :items_collected => :ready
29
+ end
30
+
31
+ state :ready do
32
+ on :dispatch => :dispatched
33
+ end
34
+
35
+ final_state :dispatched
36
+ end
37
+
38
+ state_machine :payment do
39
+ initial_state :unpaid do
40
+ on :pay => :paid
41
+ end
42
+
43
+ state :paid do
44
+ on :refund => :refunded
45
+ end
46
+
47
+ final_state :refunded
48
+ end
49
+ end
50
+ end
51
+
52
+ describe Stateful::Sequel do
53
+ let(:machine){SequelMachine12.create}
54
+
55
+ context "initial states" do
56
+ it "must be in the fulfilment initial state" do
57
+ _(machine.fulfilment_initial_state?).must_equal true
58
+ end
59
+
60
+ it "must be in the payment initial state" do
61
+ _(machine.payment_initial_state?).must_equal true
62
+ end
63
+
64
+ it "must have the correct fulfilment state name" do
65
+ _(machine.fulfilment_state.name).must_equal :pending
66
+ end
67
+
68
+ it "must have the correct payment state name" do
69
+ _(machine.payment_state.name).must_equal :unpaid
70
+ end
71
+
72
+ it "must have fulfilment transitions" do
73
+ _(machine.fulfilment_transitions.size).must_equal 1
74
+ _(machine.fulfilment_transitions.first.event_name).must_equal :items_collected
75
+ end
76
+
77
+ it "must have payment transitions" do
78
+ _(machine.payment_transitions.size).must_equal 1
79
+ _(machine.payment_transitions.first.event_name).must_equal :pay
80
+ end
81
+
82
+ it "must not be in a fulfilment final state" do
83
+ _(machine.fulfilment_final_state?).must_equal false
84
+ end
85
+
86
+ it "must not be in a payment final state" do
87
+ _(machine.payment_final_state?).must_equal false
88
+ end
89
+
90
+ it "must have domain predicates" do
91
+ _(machine.pending?).must_equal true
92
+ _(machine.unpaid?).must_equal true
93
+ end
94
+ end
95
+
96
+ context "independent state transitions" do
97
+ before do
98
+ machine.pay
99
+ end
100
+
101
+ it "must still be in the fulfilment initial state" do
102
+ _(machine.fulfilment_initial_state?).must_equal true
103
+ _(machine.pending?).must_equal true
104
+ end
105
+
106
+ it "must have advanced the payment state" do
107
+ _(machine.payment_state.name).must_equal :paid
108
+ _(machine.paid?).must_equal true
109
+ end
110
+
111
+ it "must not be in the payment initial state" do
112
+ _(machine.payment_initial_state?).must_equal false
113
+ end
114
+
115
+ it "must have persisted the payment state" do
116
+ machine.refresh
117
+ _(machine.payment_state.name).must_equal :paid
118
+ end
119
+
120
+ it "must have persisted the fulfilment state as initial" do
121
+ machine.refresh
122
+ _(machine.fulfilment_state.name).must_equal :pending
123
+ end
124
+ end
125
+
126
+ context "both machines advanced" do
127
+ before do
128
+ machine.items_collected
129
+ machine.pay
130
+ end
131
+
132
+ it "must be in the ready fulfilment state" do
133
+ _(machine.fulfilment_state.name).must_equal :ready
134
+ _(machine.ready?).must_equal true
135
+ end
136
+
137
+ it "must be in the paid payment state" do
138
+ _(machine.payment_state.name).must_equal :paid
139
+ _(machine.paid?).must_equal true
140
+ end
141
+
142
+ it "must have correct fulfilment transitions" do
143
+ _(machine.fulfilment_transitions.size).must_equal 1
144
+ _(machine.fulfilment_transitions.first.event_name).must_equal :dispatch
145
+ end
146
+
147
+ it "must have correct payment transitions" do
148
+ _(machine.payment_transitions.size).must_equal 1
149
+ _(machine.payment_transitions.first.event_name).must_equal :refund
150
+ end
151
+
152
+ it "must have persisted both states" do
153
+ machine.refresh
154
+ _(machine.fulfilment_state.name).must_equal :ready
155
+ _(machine.payment_state.name).must_equal :paid
156
+ end
157
+ end
158
+
159
+ context "fulfilment final state" do
160
+ before do
161
+ machine.items_collected
162
+ machine.dispatch
163
+ end
164
+
165
+ it "must be in the fulfilment final state" do
166
+ _(machine.fulfilment_final_state?).must_equal true
167
+ _(machine.dispatched?).must_equal true
168
+ end
169
+
170
+ it "must have no fulfilment transitions" do
171
+ _(machine.fulfilment_transitions.empty?).must_equal true
172
+ end
173
+ end
174
+
175
+ context "payment final state" do
176
+ before do
177
+ machine.pay
178
+ machine.refund
179
+ end
180
+
181
+ it "must be in the payment final state" do
182
+ _(machine.payment_final_state?).must_equal true
183
+ _(machine.refunded?).must_equal true
184
+ end
185
+
186
+ it "must have no payment transitions" do
187
+ _(machine.payment_transitions.empty?).must_equal true
188
+ end
189
+ end
190
+
191
+ context "active?" do
192
+ it "must be active when all machines are in initial states" do
193
+ _(machine.active?).must_equal true
194
+ end
195
+
196
+ it "must be active when one machine has reached final state" do
197
+ machine.items_collected
198
+ machine.dispatch
199
+ _(machine.fulfilment_final_state?).must_equal true
200
+ _(machine.active?).must_equal true
201
+ end
202
+
203
+ it "must not be active when all machines have reached final states" do
204
+ machine.items_collected
205
+ machine.dispatch
206
+ machine.pay
207
+ machine.refund
208
+ _(machine.active?).must_equal false
209
+ end
210
+
211
+ it "must be able to check a specific machine" do
212
+ machine.items_collected
213
+ machine.dispatch
214
+ _(machine.active?(:fulfilment)).must_equal false
215
+ _(machine.active?(:payment)).must_equal true
216
+ end
217
+ end
218
+ end
@@ -0,0 +1,154 @@
1
+ # test/Sequel/WithPersistenceNonSpecificExtend.rb
2
+
3
+ gem 'minitest'
4
+ gem 'minitest-spec-context'
5
+
6
+ require 'minitest/autorun'
7
+ require 'minitest-spec-context'
8
+
9
+ require_relative './test_helper'
10
+
11
+ lib_dir = File.expand_path(File.join(__FILE__, '..', '..', '..', 'lib'))
12
+ $LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)
13
+
14
+ require 'Stateful'
15
+
16
+ DB.create_table :sequel_machine0s do
17
+ primary_key :id
18
+ String :current_state
19
+ end
20
+
21
+ class SequelMachine0 < Sequel::Model
22
+ extend Stateful
23
+
24
+ initial_state :initial_state
25
+
26
+ state :initial_state do
27
+ on :an_event => :next_state
28
+ on :another_event => :final_state
29
+ end
30
+
31
+ state :next_state do
32
+ on :yet_another_event => :final_state
33
+ end
34
+
35
+ final_state :final_state
36
+ end
37
+
38
+ describe Stateful::Sequel do
39
+ let(:machine){SequelMachine0.create}
40
+
41
+ it "must have an initial state" do
42
+ _(machine.initial_state).wont_be_nil
43
+ end
44
+
45
+ it "must have a final state (if one has been specified)" do
46
+ if SequelMachine0.final_state?
47
+ _(machine.final_state).wont_be_nil
48
+ end
49
+ end
50
+
51
+ context "initial_state" do
52
+ it "must have an initial state before any events occur" do
53
+ _(machine.initial_state?).must_equal true
54
+ end
55
+
56
+ it "must have an initial state consistent with what is given" do
57
+ _(machine.initial_state).must_equal SequelMachine0.stateful_state_machine.initial_state
58
+ end
59
+
60
+ it "must have an initial state with name as per the name given" do
61
+ _(machine.initial_state.name).must_equal :initial_state
62
+ end
63
+
64
+ it "must not be in the final state (assuming that initial and final are different states)" do
65
+ _(machine.final_state?).must_equal false
66
+ end
67
+
68
+ it "must know what it's next state is given an event name" do
69
+ _(machine.next_state(:an_event)).must_equal SequelMachine0.stateful_state_machine.find(:next_state)
70
+ _(machine.next_state(:another_event)).must_equal SequelMachine0.stateful_state_machine.find(:final_state)
71
+ end
72
+
73
+ it "must have an intial state which has as set of transitions to other states" do
74
+ _(machine.transitions.class).must_equal Array
75
+ end
76
+
77
+ it "must have two transitions to other states" do
78
+ _(machine.transitions.size).must_equal 2
79
+ end
80
+
81
+ it "must know what transitions are available" do
82
+ _(machine.transitions.collect{|t| [t.event_name, t.next_state_name]}).must_equal [[:an_event, :next_state], [:another_event, :final_state]]
83
+ end
84
+
85
+ it "must be active" do
86
+ _(machine.active?).must_equal true
87
+ end
88
+ end
89
+
90
+ context "next_state" do
91
+ before do
92
+ machine.an_event
93
+ end
94
+
95
+ it "must not be in the initial state" do
96
+ _(machine.initial_state?).must_equal false
97
+ end
98
+
99
+ it "must not be in the final state" do
100
+ _(machine.final_state?).must_equal false
101
+ end
102
+
103
+ it "must be in the next_state state" do
104
+ _(machine.current_state.name).must_equal :next_state
105
+ _(machine.next_state?).must_equal true
106
+ end
107
+
108
+ it "must have a set of transitions to other states" do
109
+ _(machine.transitions.class).must_equal Array
110
+ end
111
+
112
+ it "must have one transition to other states" do
113
+ _(machine.transitions.size).must_equal 1
114
+ end
115
+
116
+ it "must know what transitions are available" do
117
+ _(machine.transitions.collect{|t| [t.event_name, t.next_state_name]}).must_equal [[:yet_another_event, :final_state]]
118
+ end
119
+
120
+ it "must be active" do
121
+ _(machine.active?).must_equal true
122
+ end
123
+ end
124
+
125
+ context "final_state" do
126
+ before do
127
+ machine.another_event
128
+ end
129
+
130
+ it "must have a final state" do
131
+ _(machine.final_state?).must_equal true
132
+ end
133
+
134
+ it "must have a final state consistent with what is given" do
135
+ _(machine.final_state).must_equal SequelMachine0.stateful_state_machine.final_state
136
+ end
137
+
138
+ it "must have a state with name as per the name given" do
139
+ _(machine.current_state.name).must_equal :final_state
140
+ end
141
+
142
+ it "must not be in the initial state (assuming that initial and final are different states)" do
143
+ _(machine.initial_state?).must_equal false
144
+ end
145
+
146
+ it "must have no transitions" do
147
+ _(machine.transitions.empty?).must_equal true
148
+ end
149
+
150
+ it "must not be active" do
151
+ _(machine.active?).must_equal false
152
+ end
153
+ end
154
+ end
@@ -0,0 +1,156 @@
1
+ # test/Sequel/WithPersistenceNonSpecificExtendAndStatefulBlock.rb
2
+
3
+ gem 'minitest'
4
+ gem 'minitest-spec-context'
5
+
6
+ require 'minitest/autorun'
7
+ require 'minitest-spec-context'
8
+
9
+ require_relative './test_helper'
10
+
11
+ lib_dir = File.expand_path(File.join(__FILE__, '..', '..', '..', 'lib'))
12
+ $LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)
13
+
14
+ require 'Stateful'
15
+
16
+ DB.create_table :sequel_machine1s do
17
+ primary_key :id
18
+ String :current_state
19
+ end
20
+
21
+ class SequelMachine1 < Sequel::Model
22
+ extend Stateful
23
+
24
+ stateful do
25
+ initial_state :initial_state
26
+
27
+ state :initial_state do
28
+ on :an_event => :next_state
29
+ on :another_event => :final_state
30
+ end
31
+
32
+ state :next_state do
33
+ on :yet_another_event => :final_state
34
+ end
35
+
36
+ final_state :final_state
37
+ end
38
+ end
39
+
40
+ describe Stateful::Sequel do
41
+ let(:machine){SequelMachine1.create}
42
+
43
+ it "must have an initial state" do
44
+ _(machine.initial_state).wont_be_nil
45
+ end
46
+
47
+ it "must have a final state (if one has been specified)" do
48
+ if SequelMachine1.final_state?
49
+ _(machine.final_state).wont_be_nil
50
+ end
51
+ end
52
+
53
+ context "initial_state" do
54
+ it "must have an initial state before any events occur" do
55
+ _(machine.initial_state?).must_equal true
56
+ end
57
+
58
+ it "must have an initial state consistent with what is given" do
59
+ _(machine.initial_state).must_equal SequelMachine1.stateful_state_machine.initial_state
60
+ end
61
+
62
+ it "must have an initial state with name as per the name given" do
63
+ _(machine.initial_state.name).must_equal :initial_state
64
+ end
65
+
66
+ it "must not be in the final state (assuming that initial and final are different states)" do
67
+ _(machine.final_state?).must_equal false
68
+ end
69
+
70
+ it "must know what it's next state is given an event name" do
71
+ _(machine.next_state(:an_event)).must_equal SequelMachine1.stateful_state_machine.find(:next_state)
72
+ _(machine.next_state(:another_event)).must_equal SequelMachine1.stateful_state_machine.find(:final_state)
73
+ end
74
+
75
+ it "must have an intial state which has as set of transitions to other states" do
76
+ _(machine.transitions.class).must_equal Array
77
+ end
78
+
79
+ it "must have two transitions to other states" do
80
+ _(machine.transitions.size).must_equal 2
81
+ end
82
+
83
+ it "must know what transitions are available" do
84
+ _(machine.transitions.collect{|t| [t.event_name, t.next_state_name]}).must_equal [[:an_event, :next_state], [:another_event, :final_state]]
85
+ end
86
+
87
+ it "must be active" do
88
+ _(machine.active?).must_equal true
89
+ end
90
+ end
91
+
92
+ context "next_state" do
93
+ before do
94
+ machine.an_event
95
+ end
96
+
97
+ it "must not be in the initial state" do
98
+ _(machine.initial_state?).must_equal false
99
+ end
100
+
101
+ it "must not be in the final state" do
102
+ _(machine.final_state?).must_equal false
103
+ end
104
+
105
+ it "must be in the next_state state" do
106
+ _(machine.current_state.name).must_equal :next_state
107
+ _(machine.next_state?).must_equal true
108
+ end
109
+
110
+ it "must have a set of transitions to other states" do
111
+ _(machine.transitions.class).must_equal Array
112
+ end
113
+
114
+ it "must have one transition to other states" do
115
+ _(machine.transitions.size).must_equal 1
116
+ end
117
+
118
+ it "must know what transitions are available" do
119
+ _(machine.transitions.collect{|t| [t.event_name, t.next_state_name]}).must_equal [[:yet_another_event, :final_state]]
120
+ end
121
+
122
+ it "must be active" do
123
+ _(machine.active?).must_equal true
124
+ end
125
+ end
126
+
127
+ context "final_state" do
128
+ before do
129
+ machine.another_event
130
+ end
131
+
132
+ it "must have a final state" do
133
+ _(machine.final_state?).must_equal true
134
+ end
135
+
136
+ it "must have a final state consistent with what is given" do
137
+ _(machine.final_state).must_equal SequelMachine1.stateful_state_machine.final_state
138
+ end
139
+
140
+ it "must have a state with name as per the name given" do
141
+ _(machine.current_state.name).must_equal :final_state
142
+ end
143
+
144
+ it "must not be in the initial state (assuming that initial and final are different states)" do
145
+ _(machine.initial_state?).must_equal false
146
+ end
147
+
148
+ it "must have no transitions" do
149
+ _(machine.transitions.empty?).must_equal true
150
+ end
151
+
152
+ it "must not be active" do
153
+ _(machine.active?).must_equal false
154
+ end
155
+ end
156
+ end
@@ -0,0 +1,154 @@
1
+ # test/Sequel/WithPersistenceSpecificExtend.rb
2
+
3
+ gem 'minitest'
4
+ gem 'minitest-spec-context'
5
+
6
+ require 'minitest/autorun'
7
+ require 'minitest-spec-context'
8
+
9
+ require_relative './test_helper'
10
+
11
+ lib_dir = File.expand_path(File.join(__FILE__, '..', '..', '..', 'lib'))
12
+ $LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)
13
+
14
+ require 'Stateful/Sequel'
15
+
16
+ DB.create_table :sequel_machine2s do
17
+ primary_key :id
18
+ String :current_state
19
+ end
20
+
21
+ class SequelMachine2 < Sequel::Model
22
+ extend Stateful::Sequel
23
+
24
+ initial_state :initial_state
25
+
26
+ state :initial_state do
27
+ on :an_event => :next_state
28
+ on :another_event => :final_state
29
+ end
30
+
31
+ state :next_state do
32
+ on :yet_another_event => :final_state
33
+ end
34
+
35
+ final_state :final_state
36
+ end
37
+
38
+ describe Stateful::Sequel do
39
+ let(:machine){SequelMachine2.create}
40
+
41
+ it "must have an initial state" do
42
+ _(machine.initial_state).wont_be_nil
43
+ end
44
+
45
+ it "must have a final state (if one has been specified)" do
46
+ if SequelMachine2.final_state?
47
+ _(machine.final_state).wont_be_nil
48
+ end
49
+ end
50
+
51
+ context "initial_state" do
52
+ it "must have an initial state before any events occur" do
53
+ _(machine.initial_state?).must_equal true
54
+ end
55
+
56
+ it "must have an initial state consistent with what is given" do
57
+ _(machine.initial_state).must_equal SequelMachine2.stateful_state_machine.initial_state
58
+ end
59
+
60
+ it "must have an initial state with name as per the name given" do
61
+ _(machine.initial_state.name).must_equal :initial_state
62
+ end
63
+
64
+ it "must not be in the final state (assuming that initial and final are different states)" do
65
+ _(machine.final_state?).must_equal false
66
+ end
67
+
68
+ it "must know what it's next state is given an event name" do
69
+ _(machine.next_state(:an_event)).must_equal SequelMachine2.stateful_state_machine.find(:next_state)
70
+ _(machine.next_state(:another_event)).must_equal SequelMachine2.stateful_state_machine.find(:final_state)
71
+ end
72
+
73
+ it "must have an intial state which has as set of transitions to other states" do
74
+ _(machine.transitions.class).must_equal Array
75
+ end
76
+
77
+ it "must have two transitions to other states" do
78
+ _(machine.transitions.size).must_equal 2
79
+ end
80
+
81
+ it "must know what transitions are available" do
82
+ _(machine.transitions.collect{|t| [t.event_name, t.next_state_name]}).must_equal [[:an_event, :next_state], [:another_event, :final_state]]
83
+ end
84
+
85
+ it "must be active" do
86
+ _(machine.active?).must_equal true
87
+ end
88
+ end
89
+
90
+ context "next_state" do
91
+ before do
92
+ machine.an_event
93
+ end
94
+
95
+ it "must not be in the initial state" do
96
+ _(machine.initial_state?).must_equal false
97
+ end
98
+
99
+ it "must not be in the final state" do
100
+ _(machine.final_state?).must_equal false
101
+ end
102
+
103
+ it "must be in the next_state state" do
104
+ _(machine.current_state.name).must_equal :next_state
105
+ _(machine.next_state?).must_equal true
106
+ end
107
+
108
+ it "must have a set of transitions to other states" do
109
+ _(machine.transitions.class).must_equal Array
110
+ end
111
+
112
+ it "must have one transition to other states" do
113
+ _(machine.transitions.size).must_equal 1
114
+ end
115
+
116
+ it "must know what transitions are available" do
117
+ _(machine.transitions.collect{|t| [t.event_name, t.next_state_name]}).must_equal [[:yet_another_event, :final_state]]
118
+ end
119
+
120
+ it "must be active" do
121
+ _(machine.active?).must_equal true
122
+ end
123
+ end
124
+
125
+ context "final_state" do
126
+ before do
127
+ machine.another_event
128
+ end
129
+
130
+ it "must have a final state" do
131
+ _(machine.final_state?).must_equal true
132
+ end
133
+
134
+ it "must have a final state consistent with what is given" do
135
+ _(machine.final_state).must_equal SequelMachine2.stateful_state_machine.final_state
136
+ end
137
+
138
+ it "must have a state with name as per the name given" do
139
+ _(machine.current_state.name).must_equal :final_state
140
+ end
141
+
142
+ it "must not be in the initial state (assuming that initial and final are different states)" do
143
+ _(machine.initial_state?).must_equal false
144
+ end
145
+
146
+ it "must have no transitions" do
147
+ _(machine.transitions.empty?).must_equal true
148
+ end
149
+
150
+ it "must not be active" do
151
+ _(machine.active?).must_equal false
152
+ end
153
+ end
154
+ end