MINT-statemachine 1.2.3 → 1.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.
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe "State Machine Entry and Exit Actions" do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe "State Machine Odds And Ends" do
4
4
  include SwitchStatemachine
@@ -1,7 +1,7 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
1
+ require 'spec_helper'
2
2
  require "noodle"
3
3
 
4
- describe "Nested parallel" do
4
+ describe "Parallel states" do
5
5
  before(:each) do
6
6
  @out_out_order = false
7
7
  @locked = true
@@ -10,7 +10,9 @@ describe "Nested parallel" do
10
10
  @sm = Statemachine.build do
11
11
  trans :start,:go,:p
12
12
  state :maintenance
13
+
13
14
  parallel :p do
15
+ event :activate_exit, :maintain
14
16
  statemachine :s1 do
15
17
  superstate :operative do
16
18
  trans :locked, :coin, :unlocked, Proc.new { @cooked = true }
@@ -25,10 +27,28 @@ describe "Nested parallel" do
25
27
  end
26
28
  end
27
29
  end
30
+
28
31
  end
29
32
 
30
33
  @sm.context = @noodle
31
34
  end
35
+
36
+ it "should call exit only once if exiting parallel state" do
37
+ counter = 0
38
+ @sm.get_state(:p).exit_action = Proc.new { counter += 1 }
39
+ @sm.go
40
+ @sm.activate_exit
41
+ counter.should == 1
42
+ end
43
+
44
+ it "should call enter only once if entering parallel state" do
45
+ counter = 0
46
+ @sm.get_state(:p).entry_action = Proc.new { counter += 1 }
47
+ @sm.go
48
+ counter.should == 1
49
+ end
50
+
51
+
32
52
  # @TODO add tests that set a certain state that is part of a parallel state machine
33
53
  # to check if
34
54
  # the other sub statemachine is set to the initial state
@@ -36,14 +56,18 @@ describe "Nested parallel" do
36
56
  it "supports entering a parallel state" do
37
57
  @sm.state.should eql :start
38
58
  @sm.go
59
+ @sm.abstract_states.should ==[:root,:p, :operative, :onoff ]
39
60
  @sm.state.should eql :p
40
61
  @sm.states_id.should == [:locked,:on]
41
62
  @sm.coin
42
63
  @sm.state.should eql :p
43
64
  @sm.states_id.should == [:unlocked,:on]
65
+ @sm.abstract_states.should ==[:root,:p, :operative, :onoff ]
44
66
  @sm.toggle
45
67
  @sm.state.should eql :p
46
68
  @sm.states_id.should == [:unlocked,:off]
69
+ @sm.abstract_states.should ==[:root,:p, :operative, :onoff ]
70
+
47
71
  end
48
72
 
49
73
  it "supports leaving a parallel state" do
@@ -52,6 +76,7 @@ describe "Nested parallel" do
52
76
  @sm.states_id.should == [:locked,:on]
53
77
  @sm.maintain
54
78
  @sm.state.should == :maintenance
79
+ @sm.abstract_states.should ==[:root ]
55
80
 
56
81
  end
57
82
 
@@ -160,9 +185,12 @@ describe "Nested parallel" do
160
185
  @sm.go
161
186
  @sm.state.should == :p
162
187
  @sm.states_id.should == [:unlocked,:on]
188
+ @sm.abstract_states.should ==[:s,:root,:p, :operative, :onoff ]
163
189
  @sm.maintain
164
190
  @sm.state.should == :maintenance
165
191
  @sm.states_id.should == [:maintenance]
192
+ @sm.abstract_states.should ==[:root]
193
+
166
194
  end
167
195
 
168
196
  it "should support leaving a parallel state by an event from a super state of the parallel state" do
@@ -174,8 +202,10 @@ describe "Nested parallel" do
174
202
  event :m, :maintenance
175
203
  parallel :p do
176
204
  statemachine :s1 do
205
+ superstate :s11 do
177
206
  trans :locked, :coin, :unlocked, Proc.new { @cooked = true }
178
207
  trans :unlocked, :coin, :locked
208
+ end
179
209
  end
180
210
  statemachine :s2 do
181
211
  superstate :onoff do
@@ -202,10 +232,11 @@ describe "Nested parallel" do
202
232
  @sm.go
203
233
  lambda {@sm.unknown}.should raise_error
204
234
  end
235
+ end
205
236
 
206
-
207
- it "should support entering a nested parallel states" do
208
- @sm = Statemachine.build do
237
+ describe "Nested parallel states" do
238
+ before (:each) do
239
+ @sm = Statemachine.build do
209
240
  trans :start,:go, :unlocked
210
241
  state :maintenance
211
242
  superstate :test do
@@ -213,11 +244,13 @@ it "should support entering a nested parallel states" do
213
244
  event :m, :maintenance
214
245
  parallel :p do
215
246
  statemachine :s1 do
247
+ superstate :s11 do
216
248
  trans :locked, :coin, :unlocked, Proc.new { @cooked = true }
217
249
  trans :unlocked, :coin, :locked
250
+ end
218
251
  end
219
252
  statemachine :s2 do
220
- #superstate :r2 do
253
+ superstate :r2 do
221
254
  parallel :p2 do
222
255
  statemachine :s21 do
223
256
  superstate :onoff do
@@ -232,14 +265,22 @@ it "should support entering a nested parallel states" do
232
265
  end
233
266
  end
234
267
  end
235
- #end
268
+ end
236
269
  end
237
270
  end
238
271
  end
239
272
  event :repair, :maintenance
240
273
  end
241
274
  end
275
+ end
242
276
 
277
+ it "should point to their own state machine" do
278
+ @sm.go
279
+ @sm.state.should eql :p
280
+
281
+ end
282
+
283
+ it "should support entering a nested parallel states" do
243
284
  @sm.go
244
285
  @sm.state.should eql :p
245
286
  @sm.states_id.should == [:unlocked,:on,:on2]
@@ -250,5 +291,4 @@ it "should support entering a nested parallel states" do
250
291
  @sm.states_id.should == [:maintenance]
251
292
  end
252
293
 
253
-
254
294
  end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe "simple cases:" do
4
4
  before(:each) do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe "Turn Stile" do
4
4
  include TurnstileStatemachine
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe "Turn Stile" do
4
4
  include TurnstileStatemachine
@@ -14,10 +14,10 @@ describe "Turn Stile" do
14
14
  locked_state.transitions.length.should equal(2)
15
15
  unlocked_state.transitions.length.should equal(2)
16
16
 
17
- check_transition(locked_state.transitions[:coin], :locked, :unlocked, :coin, @unlock)
18
- check_transition(locked_state.transitions[:pass], :locked, :locked, :pass, @alarm)
19
- check_transition(unlocked_state.transitions[:pass], :unlocked, :locked, :pass, @lock)
20
- check_transition(unlocked_state.transitions[:coin], :unlocked, :locked, :coin, @thankyou)
17
+ check_transition(locked_state.get_transitions(:coin), :locked, :unlocked, :coin, @unlock)
18
+ check_transition(locked_state.get_transitions(:pass), :locked, :locked, :pass, @alarm)
19
+ check_transition(unlocked_state.get_transitions(:pass), :unlocked, :locked, :pass, @lock)
20
+ check_transition(unlocked_state.get_transitions(:coin), :unlocked, :locked, :coin, @thankyou)
21
21
  end
22
22
 
23
23
  it "start state" do
data/spec/spec_helper.rb CHANGED
@@ -7,11 +7,13 @@ require 'statemachine'
7
7
  $IS_TEST = true
8
8
 
9
9
  def check_transition(transition, origin_id, destination_id, event, action)
10
- transition.should_not equal(nil)
11
- transition.event.should equal(event)
12
- transition.origin_id.should equal(origin_id)
13
- transition.destination_id.should equal(destination_id)
14
- transition.action.should eql(action)
10
+ transition.each do |t|
11
+ t.should_not equal(nil)
12
+ t.event.should equal(event)
13
+ t.origin_id.should equal(origin_id)
14
+ t.destination_id.should equal(destination_id)
15
+ t.action.should eql(action)
16
+ end
15
17
  end
16
18
 
17
19
  module SwitchStatemachine
@@ -1,11 +1,11 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe "Transition Calculating Exits and Entries" do
4
4
 
5
5
  before(:each) do
6
6
  @transition = Statemachine::Transition.new(nil, nil, nil, nil, true)
7
7
  end
8
-
8
+
9
9
  it "to nil" do
10
10
  @a = Statemachine::State.new("a", nil, nil)
11
11
  exits, entries = @transition.exits_and_entries(@a, nil)
@@ -13,7 +13,7 @@ describe "Transition Calculating Exits and Entries" do
13
13
  entries.to_s.should eql([].to_s)
14
14
  entries.length.should equal(0)
15
15
  end
16
-
16
+
17
17
  it "to itself" do
18
18
  @a = Statemachine::State.new("a", nil, nil)
19
19
  exits, entries = @transition.exits_and_entries(@a, @a)
@@ -55,7 +55,7 @@ describe "Transition Calculating Exits and Entries" do
55
55
  exits.to_s.should eql([@a, @b].to_s)
56
56
  entries.to_s.should eql([@d, @c].to_s)
57
57
  end
58
-
58
+
59
59
  it "to nephew" do
60
60
  @b = Statemachine::State.new("b", nil, nil)
61
61
  @c = Statemachine::State.new("c", nil, nil)
@@ -73,7 +73,7 @@ describe "Transition Calculating Exits and Entries" do
73
73
  exits.to_s.should eql([@a].to_s)
74
74
  entries.to_s.should eql([@b].to_s)
75
75
  end
76
-
76
+
77
77
  it "to second cousin" do
78
78
  @c = Statemachine::State.new("c", nil, nil)
79
79
  @b = Statemachine::State.new("b", @c, nil)
@@ -97,11 +97,107 @@ describe "Transition Calculating Exits and Entries" do
97
97
  it "to parent's grandchild" do
98
98
  @c = Statemachine::State.new("c", nil, nil)
99
99
  @b = Statemachine::State.new("b", @c, nil)
100
- @a = Statemachine::State.new("a", @b, nil)
100
+ @a = Statemachine::State.new("a", @b, nil)
101
101
  @d = Statemachine::State.new("d", @c, nil)
102
102
  exits, entries = @transition.exits_and_entries(@d, @a)
103
103
  exits.to_s.should eql([@d].to_s)
104
104
  entries.to_s.should eql([@b, @a].to_s)
105
105
  end
106
-
106
+
107
107
  end
108
+
109
+ describe "Transitions without events" do
110
+ it "should be done" do
111
+ @log = ""
112
+ @sm = Statemachine.build do
113
+ state :off do
114
+ on_entry Proc.new {puts "entering off"}
115
+ on_exit Proc.new {puts "exiting off"}
116
+ event :toggle, :on, Proc.new { @log += "on" }
117
+ event nil, :done, nil, Proc.new {@log == "onoff"}
118
+ end
119
+ trans :on, :toggle, :off, Proc.new { @log += "off" }
120
+ end
121
+ @sm.context = self
122
+
123
+ @sm.toggle
124
+ @sm.state.should == :on
125
+ @sm.toggle
126
+ @sm.state.should == :done
127
+ end
128
+
129
+ it "should be done" do
130
+ @sm = Statemachine.build do
131
+ trans :on, :toggle, :off, ["@data = 0"]
132
+ state :off do
133
+ on_entry Proc.new {@data = @data + 1}
134
+ event :toggle, :off
135
+ event nil, :done, nil, "@data == 10"
136
+ end
137
+ end
138
+ @sm.context = self
139
+
140
+ for i in 1..9
141
+ @sm.toggle
142
+ @sm.state.should == :off
143
+ @data == i
144
+ end
145
+ @sm.toggle
146
+ @sm.state.should == :done
147
+ end
148
+
149
+ it "after entering a parallel statemachine shoud be done" do
150
+ def activate(new_states,abstract_states, atomic_states)
151
+
152
+ puts "activate #{new_states} #{abstract_states} #{atomic_states}"
153
+ end
154
+
155
+ @sm = Statemachine.build do
156
+ trans :start,:go,:p
157
+ parallel :p do
158
+ statemachine :s1 do
159
+ superstate :operative do
160
+ state :unlocked do
161
+ event nil, :locked
162
+ end
163
+ trans :locked, :coin, :unlocked
164
+ end
165
+ end
166
+ statemachine :s2 do
167
+ superstate :onoff do
168
+ trans :on, :toggle, :off
169
+ trans :off, :toggle, :on
170
+ end
171
+ end
172
+ end
173
+ end
174
+ @sm.activation=self.method(:activate)
175
+ @sm.go
176
+ @sm.states_id.should == [:locked,:on]
177
+ end
178
+
179
+ end
180
+
181
+ describe "Transitions with same events but different conditions" do
182
+ before(:each) do
183
+ @power = true
184
+ @sm = Statemachine.build do
185
+ trans :off, :toggle, :on, nil, "@power"
186
+ trans :off, :toggle, :no_power, nil, "not @power"
187
+ trans :on, :toggle, :off
188
+ end
189
+ @sm.context = self
190
+ end
191
+
192
+ it "should be on then no_power" do
193
+ @sm.state.should == :off
194
+ @sm.toggle
195
+ @sm.state.should == :on
196
+ @sm.toggle
197
+ @power = false
198
+ @sm.state.should == :off
199
+ @sm.toggle
200
+ @sm.state.should == :no_power
201
+ end
202
+ end
203
+
metadata CHANGED
@@ -1,117 +1,100 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: MINT-statemachine
3
- version: !ruby/object:Gem::Version
4
- hash: 25
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.3.0
5
5
  prerelease:
6
- segments:
7
- - 1
8
- - 2
9
- - 3
10
- version: 1.2.3
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Sebastian Feuerstack
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-11-01 00:00:00 Z
12
+ date: 2012-11-20 00:00:00.000000000Z
19
13
  dependencies: []
20
-
21
- description: The MINT Statemachine is a ruby library for building Finite State Machines, based on the Statemachine gem by Micah Martin.
14
+ description: The MINT Statemachine is a ruby library for building Finite State Machines,
15
+ based on the Statemachine gem by Micah Martin.
22
16
  email: Sebastian@Feuerstack.org
23
17
  executables: []
24
-
25
18
  extensions: []
26
-
27
19
  extra_rdoc_files: []
28
-
29
- files:
30
- - Gemfile
20
+ files:
21
+ - TODO
22
+ - Gemfile.lock
23
+ - LICENSE
24
+ - CHANGES
31
25
  - Rakefile
26
+ - Gemfile
32
27
  - README.rdoc
33
28
  - MINT-statemachine.gemspec
34
- - Gemfile.lock
35
- - CHANGES
36
- - TODO
37
- - LICENSE
29
+ - lib/statemachine.rb
30
+ - lib/statemachine/builder.rb
31
+ - lib/statemachine/statemachine.rb
32
+ - lib/statemachine/generate/util.rb
33
+ - lib/statemachine/generate/dot_graph/dot_graph_statemachine.rb
38
34
  - lib/statemachine/generate/java/java_statemachine.rb
35
+ - lib/statemachine/generate/dot_graph.rb
39
36
  - lib/statemachine/generate/src_builder.rb
40
37
  - lib/statemachine/generate/java.rb
41
- - lib/statemachine/generate/dot_graph.rb
42
- - lib/statemachine/generate/util.rb
43
- - lib/statemachine/generate/dot_graph/dot_graph_statemachine.rb
44
38
  - lib/statemachine/transition.rb
45
- - lib/statemachine/superstate.rb
46
39
  - lib/statemachine/version.rb
47
- - lib/statemachine/statemachine.rb
48
- - lib/statemachine/stub_context.rb
49
- - lib/statemachine/state.rb
50
40
  - lib/statemachine/parallelstate.rb
51
41
  - lib/statemachine/action_invokation.rb
52
- - lib/statemachine/builder.rb
53
- - lib/statemachine.rb
54
- - spec/sm_turnstile_spec.rb
55
- - spec/generate/java/java_statemachine_spec.rb
42
+ - lib/statemachine/superstate.rb
43
+ - lib/statemachine/state.rb
44
+ - lib/statemachine/stub_context.rb
45
+ - spec/default_transition_spec.rb
46
+ - spec/spec_helper.rb
47
+ - spec/sm_super_state_spec.rb
48
+ - spec/sm_action_parameterization_spec.rb
56
49
  - spec/generate/dot_graph/dot_graph_stagemachine_spec.rb
57
- - spec/sm_odds_n_ends_spec.rb
58
- - spec/noodle.rb
50
+ - spec/generate/java/java_statemachine_spec.rb
59
51
  - spec/sm_entry_exit_actions_spec.rb
60
- - spec/default_transition_spec.rb
61
- - spec/action_invokation_spec.rb
52
+ - spec/sm_simple_spec.rb
62
53
  - spec/sm_parallel_state_spec.rb
63
- - spec/builder_spec.rb
64
- - spec/sm_activation_spec.rb
65
- - spec/sm_super_state_spec.rb
66
54
  - spec/transition_spec.rb
67
- - spec/spec_helper.rb
68
- - spec/sm_simple_spec.rb
69
- - spec/sm_action_parameterization_spec.rb
55
+ - spec/noodle.rb
56
+ - spec/sm_activation_spec.rb
57
+ - spec/builder_spec.rb
58
+ - spec/action_invokation_spec.rb
59
+ - spec/sm_turnstile_spec.rb
70
60
  - spec/history_spec.rb
61
+ - spec/sm_odds_n_ends_spec.rb
71
62
  homepage: http://www.multi-access.de
72
63
  licenses: []
73
-
74
64
  post_install_message:
75
65
  rdoc_options: []
76
-
77
- require_paths:
66
+ require_paths:
78
67
  - lib
79
- required_ruby_version: !ruby/object:Gem::Requirement
68
+ required_ruby_version: !ruby/object:Gem::Requirement
80
69
  none: false
81
- requirements:
82
- - - ">="
83
- - !ruby/object:Gem::Version
84
- hash: 3
85
- segments:
86
- - 0
87
- version: "0"
88
- required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
75
  none: false
90
- requirements:
91
- - - ">="
92
- - !ruby/object:Gem::Version
93
- hash: 3
94
- segments:
95
- - 0
96
- version: "0"
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
97
80
  requirements: []
98
-
99
81
  rubyforge_project:
100
- rubygems_version: 1.8.5
82
+ rubygems_version: 1.8.15
101
83
  signing_key:
102
84
  specification_version: 3
103
- summary: MINT-Statemachine-1.2.3 - Statemachine Library for Ruby based on statemachine from http://slagyr.github.com/statemachine http://www.multi-access.de/open-source-software/third-party-software-extensions/
104
- test_files:
105
- - spec/sm_turnstile_spec.rb
106
- - spec/sm_odds_n_ends_spec.rb
107
- - spec/sm_entry_exit_actions_spec.rb
85
+ summary: MINT-Statemachine-1.3.0 - Statemachine Library for Ruby based on statemachine
86
+ from http://slagyr.github.com/statemachine http://www.multi-access.de/open-source-software/third-party-software-extensions/
87
+ test_files:
108
88
  - spec/default_transition_spec.rb
109
- - spec/action_invokation_spec.rb
110
- - spec/sm_parallel_state_spec.rb
111
- - spec/builder_spec.rb
112
- - spec/sm_activation_spec.rb
113
89
  - spec/sm_super_state_spec.rb
114
- - spec/transition_spec.rb
115
- - spec/sm_simple_spec.rb
116
90
  - spec/sm_action_parameterization_spec.rb
91
+ - spec/sm_entry_exit_actions_spec.rb
92
+ - spec/sm_simple_spec.rb
93
+ - spec/sm_parallel_state_spec.rb
94
+ - spec/transition_spec.rb
95
+ - spec/sm_activation_spec.rb
96
+ - spec/builder_spec.rb
97
+ - spec/action_invokation_spec.rb
98
+ - spec/sm_turnstile_spec.rb
117
99
  - spec/history_spec.rb
100
+ - spec/sm_odds_n_ends_spec.rb