stateful.rb 2.1.0 → 2.3.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 (58) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +161 -0
  3. data/Gemfile +3 -0
  4. data/README.md +309 -0
  5. data/lib/Stateful/ActiveRecord/ClassMethods.rb +7 -65
  6. data/lib/Stateful/ClassMethods.rb +60 -0
  7. data/lib/Stateful/Poro/ClassMethods.rb +12 -70
  8. data/lib/Stateful/Sequel/ClassMethods.rb +59 -0
  9. data/lib/Stateful/Sequel.rb +30 -0
  10. data/lib/Stateful/VERSION.rb +1 -1
  11. data/lib/Stateful.rb +3 -0
  12. data/stateful.rb.gemspec +42 -0
  13. data/test/ActiveRecord/WithColumnName.rb +159 -0
  14. data/test/ActiveRecord/WithExplicitDeterministicEventOrdering.rb +159 -0
  15. data/test/ActiveRecord/WithExplicitGlobalNonDeterministicEventOrdering.rb +165 -0
  16. data/test/ActiveRecord/WithExplicitGlobalNonDeterministicEventOrderingAndInitialStateBlock.rb +163 -0
  17. data/test/ActiveRecord/WithExplicitNonDeterministicEventOrdering.rb +161 -0
  18. data/test/ActiveRecord/WithInitialStateBlock.rb +157 -0
  19. data/test/ActiveRecord/WithMultipleFinalStates.rb +188 -0
  20. data/test/ActiveRecord/WithMultipleStateMachines.rb +221 -0
  21. data/test/ActiveRecord/WithMultipleStateMachinesAndStatefulBlock.rb +223 -0
  22. data/test/ActiveRecord/WithPersistenceNonSpecificExtend.rb +159 -0
  23. data/test/ActiveRecord/WithPersistenceNonSpecificExtendAndStatefulBlock.rb +161 -0
  24. data/test/ActiveRecord/WithPersistenceSpecificExtend.rb +159 -0
  25. data/test/ActiveRecord/WithPersistenceSpecificExtendAndStatefulBlock.rb +161 -0
  26. data/test/ActiveRecord/test_helper.rb +9 -0
  27. data/test/ActiveRecord.rb +5 -0
  28. data/test/Poro/WithExplicitDeterministicEventOrdering.rb +147 -0
  29. data/test/Poro/WithExplicitGlobalNonDeterministicEventOrdering.rb +153 -0
  30. data/test/Poro/WithExplicitGlobalNonDeterministicEventOrderingAndInitialStateBlock.rb +151 -0
  31. data/test/Poro/WithExplicitNonDeterministicEventOrdering.rb +149 -0
  32. data/test/Poro/WithInitialStateBlock.rb +145 -0
  33. data/test/Poro/WithMultipleFinalStates.rb +176 -0
  34. data/test/Poro/WithMultipleStateMachines.rb +192 -0
  35. data/test/Poro/WithMultipleStateMachinesAndStatefulBlock.rb +194 -0
  36. data/test/Poro/WithPersistenceNonSpecificExtend.rb +147 -0
  37. data/test/Poro/WithPersistenceNonSpecificExtendAndStatefulBlock.rb +149 -0
  38. data/test/Poro/WithPersistenceSpecificExtend.rb +147 -0
  39. data/test/Poro/WithPersistenceSpecificExtendAndStatefulBlock.rb +149 -0
  40. data/test/Poro/WithVariableName.rb +147 -0
  41. data/test/Poro.rb +5 -0
  42. data/test/Sequel/WithColumnName.rb +154 -0
  43. data/test/Sequel/WithExplicitDeterministicEventOrdering.rb +154 -0
  44. data/test/Sequel/WithExplicitGlobalNonDeterministicEventOrdering.rb +160 -0
  45. data/test/Sequel/WithExplicitGlobalNonDeterministicEventOrderingAndInitialStateBlock.rb +158 -0
  46. data/test/Sequel/WithExplicitNonDeterministicEventOrdering.rb +156 -0
  47. data/test/Sequel/WithInitialStateBlock.rb +152 -0
  48. data/test/Sequel/WithMultipleFinalStates.rb +183 -0
  49. data/test/Sequel/WithMultipleStateMachines.rb +216 -0
  50. data/test/Sequel/WithMultipleStateMachinesAndStatefulBlock.rb +218 -0
  51. data/test/Sequel/WithPersistenceNonSpecificExtend.rb +154 -0
  52. data/test/Sequel/WithPersistenceNonSpecificExtendAndStatefulBlock.rb +156 -0
  53. data/test/Sequel/WithPersistenceSpecificExtend.rb +154 -0
  54. data/test/Sequel/WithPersistenceSpecificExtendAndStatefulBlock.rb +156 -0
  55. data/test/Sequel/test_helper.rb +5 -0
  56. data/test/Sequel.rb +5 -0
  57. data/test/Stateful.rb +15 -0
  58. metadata +69 -4
@@ -0,0 +1,158 @@
1
+ # test/Sequel/WithExplicitGlobalNonDeterministicEventOrderingAndInitialStateBlock.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_machine10s do
17
+ primary_key :id
18
+ String :current_state
19
+ end
20
+
21
+ class SequelMachine10 < Sequel::Model
22
+ extend Stateful
23
+
24
+ stateful global_non_deterministic_event_ordering: true do
25
+ initial_state :initial_state do
26
+ on :an_event => :next_state
27
+ on :another_event => :final_state
28
+ end
29
+
30
+ state :next_state do
31
+ on :yet_another_event => :final_state
32
+ end
33
+
34
+ final_state :final_state
35
+ end
36
+ end
37
+
38
+ describe Stateful::Sequel do
39
+ let(:machine){SequelMachine10.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 SequelMachine10.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 SequelMachine10.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 SequelMachine10.stateful_state_machine.find(:next_state)
70
+ _(machine.next_state(:another_event)).must_equal SequelMachine10.stateful_state_machine.find(:final_state)
71
+ end
72
+
73
+ it "must have an intial state which has a collection of transitions to other states" do
74
+ _(machine.transitions.class).must_equal Array
75
+ _(machine.transitions.all?{|transition| transition.is_a?(Stateful::Transition)}).must_equal true
76
+ end
77
+
78
+ it "must have two transitions to other states" do
79
+ _(machine.transitions.size).must_equal 2
80
+ end
81
+
82
+ it "must know what transitions are available" do
83
+ transition_pairs = machine.transitions.collect{|t| [t.event_name, t.next_state_name]}
84
+ _(transition_pairs).must_include [:an_event, :next_state]
85
+ _(transition_pairs).must_include [:another_event, :final_state]
86
+ end
87
+
88
+ it "must be active" do
89
+ _(machine.active?).must_equal true
90
+ end
91
+ end
92
+
93
+ context "next_state" do
94
+ before do
95
+ machine.an_event
96
+ end
97
+
98
+ it "must not be in the initial state" do
99
+ _(machine.initial_state?).must_equal false
100
+ end
101
+
102
+ it "must not be in the final state" do
103
+ _(machine.final_state?).must_equal false
104
+ end
105
+
106
+ it "must be in the next_state state" do
107
+ _(machine.current_state.name).must_equal :next_state
108
+ _(machine.next_state?).must_equal true
109
+ end
110
+
111
+ it "must have a collection of transitions to other states" do
112
+ _(machine.transitions.class).must_equal Array
113
+ _(machine.transitions.all?{|transition| transition.is_a?(Stateful::Transition)}).must_equal true
114
+ end
115
+
116
+ it "must have one transition to other states" do
117
+ _(machine.transitions.size).must_equal 1
118
+ end
119
+
120
+ it "must know what transitions are available" do
121
+ _(machine.transitions.collect{|t| [t.event_name, t.next_state_name]}).must_equal [[:yet_another_event, :final_state]]
122
+ end
123
+
124
+ it "must be active" do
125
+ _(machine.active?).must_equal true
126
+ end
127
+ end
128
+
129
+ context "final_state" do
130
+ before do
131
+ machine.another_event
132
+ end
133
+
134
+ it "must have a final state" do
135
+ _(machine.final_state?).must_equal true
136
+ end
137
+
138
+ it "must have a final state consistent with what is given" do
139
+ _(machine.final_state).must_equal SequelMachine10.stateful_state_machine.final_state
140
+ end
141
+
142
+ it "must have a state with name as per the name given" do
143
+ _(machine.current_state.name).must_equal :final_state
144
+ end
145
+
146
+ it "must not be in the initial state (assuming that initial and final are different states)" do
147
+ _(machine.initial_state?).must_equal false
148
+ end
149
+
150
+ it "must have no transitions" do
151
+ _(machine.transitions.empty?).must_equal true
152
+ end
153
+
154
+ it "must not be active" do
155
+ _(machine.active?).must_equal false
156
+ end
157
+ end
158
+ end
@@ -0,0 +1,156 @@
1
+ # test/Sequel/WithExplicitNonDeterministicEventOrdering.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_machine6s do
17
+ primary_key :id
18
+ String :current_state
19
+ end
20
+
21
+ class SequelMachine6 < Sequel::Model
22
+ extend Stateful
23
+
24
+ initial_state :initial_state, non_deterministic: true do
25
+ on :an_event => :next_state
26
+ on :another_event => :final_state
27
+ end
28
+
29
+ state :next_state do
30
+ on :yet_another_event => :final_state
31
+ end
32
+
33
+ final_state :final_state
34
+ end
35
+
36
+ describe Stateful::Sequel do
37
+ let(:machine){SequelMachine6.create}
38
+
39
+ it "must have an initial state" do
40
+ _(machine.initial_state).wont_be_nil
41
+ end
42
+
43
+ it "must have a final state (if one has been specified)" do
44
+ if SequelMachine6.final_state?
45
+ _(machine.final_state).wont_be_nil
46
+ end
47
+ end
48
+
49
+ context "initial_state" do
50
+ it "must have an initial state before any events occur" do
51
+ _(machine.initial_state?).must_equal true
52
+ end
53
+
54
+ it "must have an initial state consistent with what is given" do
55
+ _(machine.initial_state).must_equal SequelMachine6.stateful_state_machine.initial_state
56
+ end
57
+
58
+ it "must have an initial state with name as per the name given" do
59
+ _(machine.initial_state.name).must_equal :initial_state
60
+ end
61
+
62
+ it "must not be in the final state (assuming that initial and final are different states)" do
63
+ _(machine.final_state?).must_equal false
64
+ end
65
+
66
+ it "must know what it's next state is given an event name" do
67
+ _(machine.next_state(:an_event)).must_equal SequelMachine6.stateful_state_machine.find(:next_state)
68
+ _(machine.next_state(:another_event)).must_equal SequelMachine6.stateful_state_machine.find(:final_state)
69
+ end
70
+
71
+ it "must have an intial state which has a collection of transitions to other states" do
72
+ _(machine.transitions.class).must_equal Array
73
+ _(machine.transitions.all?{|transition| transition.is_a?(Stateful::Transition)}).must_equal true
74
+ end
75
+
76
+ it "must have two transitions to other states" do
77
+ _(machine.transitions.size).must_equal 2
78
+ end
79
+
80
+ it "must know what transitions are available" do
81
+ transition_pairs = machine.transitions.collect{|t| [t.event_name, t.next_state_name]}
82
+ _(transition_pairs).must_include [:an_event, :next_state]
83
+ _(transition_pairs).must_include [:another_event, :final_state]
84
+ end
85
+
86
+ it "must be active" do
87
+ _(machine.active?).must_equal true
88
+ end
89
+ end
90
+
91
+ context "next_state" do
92
+ before do
93
+ machine.an_event
94
+ end
95
+
96
+ it "must not be in the initial state" do
97
+ _(machine.initial_state?).must_equal false
98
+ end
99
+
100
+ it "must not be in the final state" do
101
+ _(machine.final_state?).must_equal false
102
+ end
103
+
104
+ it "must be in the next_state state" do
105
+ _(machine.current_state.name).must_equal :next_state
106
+ _(machine.next_state?).must_equal true
107
+ end
108
+
109
+ it "must have a collection of transitions to other states" do
110
+ _(machine.transitions.class).must_equal Array
111
+ _(machine.transitions.all?{|transition| transition.is_a?(Stateful::Transition)}).must_equal true
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 SequelMachine6.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,152 @@
1
+ # test/Sequel/WithInitialStateBlock.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_machine4s do
17
+ primary_key :id
18
+ String :current_state
19
+ end
20
+
21
+ class SequelMachine4 < Sequel::Model
22
+ extend Stateful
23
+
24
+ initial_state :initial_state do
25
+ on :an_event => :next_state
26
+ on :another_event => :final_state
27
+ end
28
+
29
+ state :next_state do
30
+ on :yet_another_event => :final_state
31
+ end
32
+
33
+ final_state :final_state
34
+ end
35
+
36
+ describe Stateful::Sequel do
37
+ let(:machine){SequelMachine4.create}
38
+
39
+ it "must have an initial state" do
40
+ _(machine.initial_state).wont_be_nil
41
+ end
42
+
43
+ it "must have a final state (if one has been specified)" do
44
+ if SequelMachine4.final_state?
45
+ _(machine.final_state).wont_be_nil
46
+ end
47
+ end
48
+
49
+ context "initial_state" do
50
+ it "must have an initial state before any events occur" do
51
+ _(machine.initial_state?).must_equal true
52
+ end
53
+
54
+ it "must have an initial state consistent with what is given" do
55
+ _(machine.initial_state).must_equal SequelMachine4.stateful_state_machine.initial_state
56
+ end
57
+
58
+ it "must have an initial state with name as per the name given" do
59
+ _(machine.initial_state.name).must_equal :initial_state
60
+ end
61
+
62
+ it "must not be in the final state (assuming that initial and final are different states)" do
63
+ _(machine.final_state?).must_equal false
64
+ end
65
+
66
+ it "must know what it's next state is given an event name" do
67
+ _(machine.next_state(:an_event)).must_equal SequelMachine4.stateful_state_machine.find(:next_state)
68
+ _(machine.next_state(:another_event)).must_equal SequelMachine4.stateful_state_machine.find(:final_state)
69
+ end
70
+
71
+ it "must have an intial state which has as set of transitions to other states" do
72
+ _(machine.transitions.class).must_equal Array
73
+ end
74
+
75
+ it "must have two transitions to other states" do
76
+ _(machine.transitions.size).must_equal 2
77
+ end
78
+
79
+ it "must know what transitions are available" do
80
+ _(machine.transitions.collect{|t| [t.event_name, t.next_state_name]}).must_equal [[:an_event, :next_state], [:another_event, :final_state]]
81
+ end
82
+
83
+ it "must be active" do
84
+ _(machine.active?).must_equal true
85
+ end
86
+ end
87
+
88
+ context "next_state" do
89
+ before do
90
+ machine.an_event
91
+ end
92
+
93
+ it "must not be in the initial state" do
94
+ _(machine.initial_state?).must_equal false
95
+ end
96
+
97
+ it "must not be in the final state" do
98
+ _(machine.final_state?).must_equal false
99
+ end
100
+
101
+ it "must be in the next_state state" do
102
+ _(machine.current_state.name).must_equal :next_state
103
+ _(machine.next_state?).must_equal true
104
+ end
105
+
106
+ it "must have a set of transitions to other states" do
107
+ _(machine.transitions.class).must_equal Array
108
+ end
109
+
110
+ it "must have one transition to other states" do
111
+ _(machine.transitions.size).must_equal 1
112
+ end
113
+
114
+ it "must know what transitions are available" do
115
+ _(machine.transitions.collect{|t| [t.event_name, t.next_state_name]}).must_equal [[:yet_another_event, :final_state]]
116
+ end
117
+
118
+ it "must be active" do
119
+ _(machine.active?).must_equal true
120
+ end
121
+ end
122
+
123
+ context "final_state" do
124
+ before do
125
+ machine.another_event
126
+ end
127
+
128
+ it "must have a final state" do
129
+ _(machine.final_state?).must_equal true
130
+ end
131
+
132
+ it "must have a final state consistent with what is given" do
133
+ _(machine.final_state).must_equal SequelMachine4.stateful_state_machine.final_state
134
+ end
135
+
136
+ it "must have a state with name as per the name given" do
137
+ _(machine.current_state.name).must_equal :final_state
138
+ end
139
+
140
+ it "must not be in the initial state (assuming that initial and final are different states)" do
141
+ _(machine.initial_state?).must_equal false
142
+ end
143
+
144
+ it "must have no transitions" do
145
+ _(machine.transitions.empty?).must_equal true
146
+ end
147
+
148
+ it "must not be active" do
149
+ _(machine.active?).must_equal false
150
+ end
151
+ end
152
+ end
@@ -0,0 +1,183 @@
1
+ # test/Sequel/WithMultipleFinalStates.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_machine7s do
17
+ primary_key :id
18
+ String :current_state
19
+ end
20
+
21
+ class SequelMachine7 < Sequel::Model
22
+ extend Stateful
23
+
24
+ initial_state :initial_state do
25
+ on :an_event => :next_state
26
+ on :another_event => :final_state0
27
+ end
28
+
29
+ state :next_state do
30
+ on :yet_another_event => :final_state1
31
+ end
32
+
33
+ final_state :final_state0, :final_state1
34
+ end
35
+
36
+ describe Stateful::Sequel do
37
+ let(:machine){SequelMachine7.new}
38
+
39
+ it "must have an initial state" do
40
+ _(machine.initial_state).wont_be_nil
41
+ end
42
+
43
+ it "must have a final state (if one has been specified)" do
44
+ if SequelMachine7.final_state?
45
+ _(machine.final_state).wont_be_nil
46
+ end
47
+ end
48
+
49
+ context "initial_state" do
50
+ it "must have an initial state before any events occur" do
51
+ _(machine.initial_state?).must_equal true
52
+ end
53
+
54
+ it "must have an initial state consistent with what is given" do
55
+ _(machine.initial_state).must_equal SequelMachine7.stateful_state_machine.initial_state
56
+ end
57
+
58
+ it "must have an initial state with name as per the name given" do
59
+ _(machine.initial_state.name).must_equal :initial_state
60
+ end
61
+
62
+ it "must not be in the final state (assuming that initial and final are different states)" do
63
+ _(machine.final_state?).must_equal false
64
+ end
65
+
66
+ it "must know what it's next state is given an event name" do
67
+ _(machine.next_state(:an_event)).must_equal SequelMachine7.stateful_state_machine.find(:next_state)
68
+ _(machine.next_state(:another_event)).must_equal SequelMachine7.stateful_state_machine.find(:final_state0)
69
+ end
70
+
71
+ it "must have an intial state which has as set of transitions to other states" do
72
+ _(machine.transitions.class).must_equal Array
73
+ end
74
+
75
+ it "must have two transitions to other states" do
76
+ _(machine.transitions.size).must_equal 2
77
+ end
78
+
79
+ it "must know what transitions are available and in what order they are presented" do
80
+ _(machine.transitions.collect{|t| [t.event_name, t.next_state_name]}).must_equal [[:an_event, :next_state], [:another_event, :final_state0]]
81
+ end
82
+
83
+ it "must be active" do
84
+ _(machine.active?).must_equal true
85
+ end
86
+ end
87
+
88
+ context "next_state" do
89
+ before do
90
+ machine.an_event
91
+ end
92
+
93
+ it "must not be in the initial state" do
94
+ _(machine.initial_state?).must_equal false
95
+ end
96
+
97
+ it "must not be in a final state" do
98
+ _(machine.final_state?).must_equal false
99
+ end
100
+
101
+ it "must be in the next_state state" do
102
+ _(machine.current_state.name).must_equal :next_state
103
+ _(machine.next_state?).must_equal true
104
+ end
105
+
106
+ it "must have a set of transitions to other states" do
107
+ _(machine.transitions.class).must_equal Array
108
+ end
109
+
110
+ it "must have one transition to other states" do
111
+ _(machine.transitions.size).must_equal 1
112
+ end
113
+
114
+ it "must know what transitions are available" do
115
+ _(machine.transitions.collect{|t| [t.event_name, t.next_state_name]}).must_equal [[:yet_another_event, :final_state1]]
116
+ end
117
+
118
+ it "must be active" do
119
+ _(machine.active?).must_equal true
120
+ end
121
+ end
122
+
123
+ context "final_state0" do
124
+ before do
125
+ machine.another_event
126
+ end
127
+
128
+ it "must have a final state" do
129
+ _(machine.final_state?).must_equal true
130
+ end
131
+
132
+ it "must have a final state consistent with what is given" do
133
+ _(SequelMachine7.stateful_state_machine.final_states).must_include machine.final_state
134
+ end
135
+
136
+ it "must have a state with name as per the name given" do
137
+ _(machine.current_state.name).must_equal :final_state0
138
+ end
139
+
140
+ it "must not be in the initial state (assuming that initial and final are different states)" do
141
+ _(machine.initial_state?).must_equal false
142
+ end
143
+
144
+ it "must have no transitions" do
145
+ _(machine.transitions.empty?).must_equal true
146
+ end
147
+
148
+ it "must not be active" do
149
+ _(machine.active?).must_equal false
150
+ end
151
+ end
152
+
153
+ context "final_state1" do
154
+ before do
155
+ machine.an_event
156
+ machine.yet_another_event
157
+ end
158
+
159
+ it "must have a final state" do
160
+ _(machine.final_state?).must_equal true
161
+ end
162
+
163
+ it "must have a final state consistent with what is given" do
164
+ _(SequelMachine7.stateful_state_machine.final_states).must_include machine.final_state
165
+ end
166
+
167
+ it "must have a state with name as per the name given" do
168
+ _(machine.current_state.name).must_equal :final_state1
169
+ end
170
+
171
+ it "must not be in the initial state (assuming that initial and final are different states)" do
172
+ _(machine.initial_state?).must_equal false
173
+ end
174
+
175
+ it "must have no transitions" do
176
+ _(machine.transitions.empty?).must_equal true
177
+ end
178
+
179
+ it "must not be active" do
180
+ _(machine.active?).must_equal false
181
+ end
182
+ end
183
+ end