stateful.rb 2.1.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 +3 -0
  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,154 @@
1
+ # test/Sequel/WithColumnName.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_machine8s do
17
+ primary_key :id
18
+ String :status
19
+ end
20
+
21
+ class SequelMachine8 < Sequel::Model
22
+ @stateful_column_name = 'status'
23
+
24
+ extend Stateful
25
+
26
+ initial_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){SequelMachine8.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 SequelMachine8.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 SequelMachine8.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 SequelMachine8.stateful_state_machine.find(:next_state)
70
+ _(machine.next_state(:another_event)).must_equal SequelMachine8.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.status.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 SequelMachine8.stateful_state_machine.final_state
136
+ end
137
+
138
+ it "must have a state with name as per the name given" do
139
+ _(machine.status.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,154 @@
1
+ # test/Sequel/WithExplicitDeterministicEventOrdering.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_machine5s do
17
+ primary_key :id
18
+ String :current_state
19
+ end
20
+
21
+ class SequelMachine5 < Sequel::Model
22
+ extend Stateful
23
+
24
+ initial_state :initial_state, 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){SequelMachine5.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 SequelMachine5.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 SequelMachine5.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 SequelMachine5.stateful_state_machine.find(:next_state)
68
+ _(machine.next_state(:another_event)).must_equal SequelMachine5.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 and in what order they are presented" do
81
+ _(machine.transitions.collect{|t| [t.event_name, t.next_state_name]}).must_equal [[:an_event, :next_state], [:another_event, :final_state]]
82
+ end
83
+
84
+ it "must be active" do
85
+ _(machine.active?).must_equal true
86
+ end
87
+ end
88
+
89
+ context "next_state" do
90
+ before do
91
+ machine.an_event
92
+ end
93
+
94
+ it "must not be in the initial state" do
95
+ _(machine.initial_state?).must_equal false
96
+ end
97
+
98
+ it "must not be in the final state" do
99
+ _(machine.final_state?).must_equal false
100
+ end
101
+
102
+ it "must be in the next_state state" do
103
+ _(machine.current_state.name).must_equal :next_state
104
+ _(machine.next_state?).must_equal true
105
+ end
106
+
107
+ it "must have a collection of transitions to other states" do
108
+ _(machine.transitions.class).must_equal Array
109
+ _(machine.transitions.all?{|transition| transition.is_a?(Stateful::Transition)}).must_equal true
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 SequelMachine5.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,160 @@
1
+ # test/Sequel/WithExplicitGlobalNonDeterministicEventOrdering.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_machine9s do
17
+ primary_key :id
18
+ String :current_state
19
+ end
20
+
21
+ class SequelMachine9 < Sequel::Model
22
+ extend Stateful
23
+
24
+ stateful global_non_deterministic_event_ordering: true 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){SequelMachine9.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 SequelMachine9.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 SequelMachine9.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 SequelMachine9.stateful_state_machine.find(:next_state)
72
+ _(machine.next_state(:another_event)).must_equal SequelMachine9.stateful_state_machine.find(:final_state)
73
+ end
74
+
75
+ it "must have an intial state which has a collection of transitions to other states" do
76
+ _(machine.transitions.class).must_equal Array
77
+ _(machine.transitions.all?{|transition| transition.is_a?(Stateful::Transition)}).must_equal true
78
+ end
79
+
80
+ it "must have two transitions to other states" do
81
+ _(machine.transitions.size).must_equal 2
82
+ end
83
+
84
+ it "must know what transitions are available" do
85
+ transition_pairs = machine.transitions.collect{|t| [t.event_name, t.next_state_name]}
86
+ _(transition_pairs).must_include [:an_event, :next_state]
87
+ _(transition_pairs).must_include [:another_event, :final_state]
88
+ end
89
+
90
+ it "must be active" do
91
+ _(machine.active?).must_equal true
92
+ end
93
+ end
94
+
95
+ context "next_state" do
96
+ before do
97
+ machine.an_event
98
+ end
99
+
100
+ it "must not be in the initial state" do
101
+ _(machine.initial_state?).must_equal false
102
+ end
103
+
104
+ it "must not be in the final state" do
105
+ _(machine.final_state?).must_equal false
106
+ end
107
+
108
+ it "must be in the next_state state" do
109
+ _(machine.current_state.name).must_equal :next_state
110
+ _(machine.next_state?).must_equal true
111
+ end
112
+
113
+ it "must have a collection of transitions to other states" do
114
+ _(machine.transitions.class).must_equal Array
115
+ _(machine.transitions.all?{|transition| transition.is_a?(Stateful::Transition)}).must_equal true
116
+ end
117
+
118
+ it "must have one transition to other states" do
119
+ _(machine.transitions.size).must_equal 1
120
+ end
121
+
122
+ it "must know what transitions are available" do
123
+ _(machine.transitions.collect{|t| [t.event_name, t.next_state_name]}).must_equal [[:yet_another_event, :final_state]]
124
+ end
125
+
126
+ it "must be active" do
127
+ _(machine.active?).must_equal true
128
+ end
129
+ end
130
+
131
+ context "final_state" do
132
+ before do
133
+ machine.another_event
134
+ end
135
+
136
+ it "must have a final state" do
137
+ _(machine.final_state?).must_equal true
138
+ end
139
+
140
+ it "must have a final state consistent with what is given" do
141
+ _(machine.final_state).must_equal SequelMachine9.stateful_state_machine.final_state
142
+ end
143
+
144
+ it "must have a state with name as per the name given" do
145
+ _(machine.current_state.name).must_equal :final_state
146
+ end
147
+
148
+ it "must not be in the initial state (assuming that initial and final are different states)" do
149
+ _(machine.initial_state?).must_equal false
150
+ end
151
+
152
+ it "must have no transitions" do
153
+ _(machine.transitions.empty?).must_equal true
154
+ end
155
+
156
+ it "must not be active" do
157
+ _(machine.active?).must_equal false
158
+ end
159
+ end
160
+ end
@@ -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