enum_state_machine 0.1.1 → 0.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.
- checksums.yaml +4 -4
- data/enum_state_machine.gemspec +4 -6
- data/lib/enum_state_machine/integrations/active_model.rb +23 -24
- data/lib/enum_state_machine/version.rb +1 -1
- data/test/functional/state_machine_test.rb +29 -27
- data/test/test_helper.rb +13 -1
- data/test/unit/assertions_test.rb +10 -4
- data/test/unit/branch_test.rb +65 -52
- data/test/unit/callback_test.rb +29 -29
- data/test/unit/error_test.rb +7 -5
- data/test/unit/eval_helpers_test.rb +2 -2
- data/test/unit/event_collection_test.rb +10 -10
- data/test/unit/event_test.rb +56 -55
- data/test/unit/graph_test.rb +6 -6
- data/test/unit/helper_module_test.rb +1 -1
- data/test/unit/integrations/active_model_test.rb +4 -4
- data/test/unit/integrations/active_record_test.rb +7 -7
- data/test/unit/integrations/base_test.rb +2 -2
- data/test/unit/integrations_test.rb +3 -3
- data/test/unit/invalid_event_test.rb +1 -1
- data/test/unit/invalid_parallel_transition_test.rb +1 -1
- data/test/unit/invalid_transition_test.rb +3 -3
- data/test/unit/machine_collection_test.rb +22 -18
- data/test/unit/machine_test.rb +123 -110
- data/test/unit/matcher_helpers_test.rb +3 -3
- data/test/unit/matcher_test.rb +7 -7
- data/test/unit/node_collection_test.rb +24 -22
- data/test/unit/path_collection_test.rb +17 -11
- data/test/unit/path_test.rb +16 -14
- data/test/unit/state_collection_test.rb +12 -12
- data/test/unit/state_context_test.rb +23 -21
- data/test/unit/state_enum_test.rb +1 -1
- data/test/unit/state_machine_test.rb +2 -2
- data/test/unit/state_test.rb +55 -53
- data/test/unit/transition_collection_test.rb +47 -45
- data/test/unit/transition_test.rb +53 -45
- metadata +14 -50
data/test/unit/graph_test.rb
CHANGED
@@ -8,7 +8,7 @@ begin
|
|
8
8
|
(RUBY_PLATFORM =~ /darwin/) ? 'ArialMT' : 'Arial'
|
9
9
|
end
|
10
10
|
|
11
|
-
class GraphDefaultTest < Test
|
11
|
+
class GraphDefaultTest < MiniTest::Test
|
12
12
|
def setup
|
13
13
|
@graph = EnumStateMachine::Graph.new('test')
|
14
14
|
end
|
@@ -30,14 +30,14 @@ begin
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
class GraphNodesTest < Test
|
33
|
+
class GraphNodesTest < MiniTest::Test
|
34
34
|
def setup
|
35
35
|
@graph = EnumStateMachine::Graph.new('test')
|
36
36
|
@node = @graph.add_nodes('parked', :shape => 'ellipse')
|
37
37
|
end
|
38
38
|
|
39
39
|
def test_should_return_generated_node
|
40
|
-
|
40
|
+
refute_nil @node
|
41
41
|
end
|
42
42
|
|
43
43
|
def test_should_use_specified_name
|
@@ -53,7 +53,7 @@ begin
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
-
class GraphEdgesTest < Test
|
56
|
+
class GraphEdgesTest < MiniTest::Test
|
57
57
|
def setup
|
58
58
|
@graph = EnumStateMachine::Graph.new('test')
|
59
59
|
@graph.add_nodes('parked', :shape => 'ellipse')
|
@@ -62,7 +62,7 @@ begin
|
|
62
62
|
end
|
63
63
|
|
64
64
|
def test_should_return_generated_edge
|
65
|
-
|
65
|
+
refute_nil @edge
|
66
66
|
end
|
67
67
|
|
68
68
|
def test_should_use_specified_nodes
|
@@ -79,7 +79,7 @@ begin
|
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
-
class GraphOutputTest < Test
|
82
|
+
class GraphOutputTest < MiniTest::Test
|
83
83
|
def setup
|
84
84
|
@graph_name = "test_#{rand(1000000)}"
|
85
85
|
@graph = EnumStateMachine::Graph.new(@graph_name)
|
@@ -10,7 +10,7 @@ end
|
|
10
10
|
require 'active_support/all'
|
11
11
|
|
12
12
|
module ActiveModelTest
|
13
|
-
class BaseTestCase < Test
|
13
|
+
class BaseTestCase < MiniTest::Test
|
14
14
|
def default_test
|
15
15
|
end
|
16
16
|
|
@@ -101,7 +101,7 @@ module ActiveModelTest
|
|
101
101
|
end
|
102
102
|
|
103
103
|
def test_should_have_a_locale_path
|
104
|
-
|
104
|
+
refute_nil EnumStateMachine::Integrations::ActiveModel.locale_path
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
@@ -191,7 +191,7 @@ module ActiveModelTest
|
|
191
191
|
end
|
192
192
|
|
193
193
|
def test_should_raise_exception_for_predicate_without_parameters
|
194
|
-
|
194
|
+
assert_raises(ArgumentError) { @record.state? }
|
195
195
|
end
|
196
196
|
|
197
197
|
def test_should_return_false_for_predicate_if_does_not_match_current_value
|
@@ -203,7 +203,7 @@ module ActiveModelTest
|
|
203
203
|
end
|
204
204
|
|
205
205
|
def test_should_raise_exception_for_predicate_if_invalid_state_specified
|
206
|
-
|
206
|
+
assert_raises(IndexError) { @record.state?(:invalid) }
|
207
207
|
end
|
208
208
|
end
|
209
209
|
|
@@ -97,7 +97,7 @@ module ActiveRecordTest
|
|
97
97
|
end
|
98
98
|
|
99
99
|
def test_should_have_a_locale_path
|
100
|
-
|
100
|
+
refute_nil EnumStateMachine::Integrations::ActiveRecord.locale_path
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
@@ -608,7 +608,7 @@ module ActiveRecordTest
|
|
608
608
|
end
|
609
609
|
|
610
610
|
def test_should_raise_exception_for_predicate_if_invalid_state_specified
|
611
|
-
|
611
|
+
assert_raises(IndexError) { @record.state?(:invalid) }
|
612
612
|
end
|
613
613
|
end
|
614
614
|
|
@@ -670,7 +670,7 @@ module ActiveRecordTest
|
|
670
670
|
end
|
671
671
|
|
672
672
|
def test_should_raise_exception_for_predicate_if_invalid_state_specified
|
673
|
-
|
673
|
+
assert_raises(IndexError) { @record.status?(:invalid) }
|
674
674
|
end
|
675
675
|
|
676
676
|
def test_should_set_initial_state_on_created_object
|
@@ -710,7 +710,7 @@ module ActiveRecordTest
|
|
710
710
|
end
|
711
711
|
|
712
712
|
def test_should_not_delegate_attribute_predicate_with_different_attribute
|
713
|
-
|
713
|
+
assert_raises(ArgumentError) { @record.public_state? }
|
714
714
|
end
|
715
715
|
|
716
716
|
def teardown
|
@@ -800,7 +800,7 @@ module ActiveRecordTest
|
|
800
800
|
end
|
801
801
|
else
|
802
802
|
def test_should_update_record
|
803
|
-
|
803
|
+
refute_equal @timestamp, @record.updated_at
|
804
804
|
end
|
805
805
|
end
|
806
806
|
end
|
@@ -1775,12 +1775,12 @@ module ActiveRecordTest
|
|
1775
1775
|
|
1776
1776
|
def test_should_fail_if_event_is_invalid
|
1777
1777
|
@record.state_event = 'invalid'
|
1778
|
-
|
1778
|
+
assert_raises(ActiveRecord::RecordInvalid) { @record.save! }
|
1779
1779
|
end
|
1780
1780
|
|
1781
1781
|
def test_should_fail_if_event_has_no_transition
|
1782
1782
|
@record.state = 'idling'
|
1783
|
-
|
1783
|
+
assert_raises(ActiveRecord::RecordInvalid) { @record.save! }
|
1784
1784
|
end
|
1785
1785
|
|
1786
1786
|
def test_should_be_successful_if_event_has_transition
|
@@ -4,7 +4,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
|
4
4
|
require 'rubygems'
|
5
5
|
|
6
6
|
module BaseTest
|
7
|
-
class IntegrationTest < Test
|
7
|
+
class IntegrationTest < MiniTest::Test
|
8
8
|
def test_should_have_an_integration_name
|
9
9
|
assert_equal :base, EnumStateMachine::Integrations::Base.integration_name
|
10
10
|
end
|
@@ -26,7 +26,7 @@ module BaseTest
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
class IncludedTest < Test
|
29
|
+
class IncludedTest < MiniTest::Test
|
30
30
|
def setup
|
31
31
|
@integration = Module.new
|
32
32
|
EnumStateMachine::Integrations.const_set('Custom', @integration)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
2
|
|
3
|
-
class IntegrationMatcherTest < Test
|
3
|
+
class IntegrationMatcherTest < MiniTest::Test
|
4
4
|
def setup
|
5
5
|
superclass = Class.new
|
6
6
|
self.class.const_set('Vehicle', superclass)
|
@@ -51,7 +51,7 @@ class IntegrationMatcherTest < Test::Unit::TestCase
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
class IntegrationFinderTest < Test
|
54
|
+
class IntegrationFinderTest < MiniTest::Test
|
55
55
|
def test_should_find_base
|
56
56
|
assert_equal EnumStateMachine::Integrations::Base, EnumStateMachine::Integrations.find_by_name(:base)
|
57
57
|
end
|
@@ -65,7 +65,7 @@ class IntegrationFinderTest < Test::Unit::TestCase
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def test_should_raise_an_exception_if_invalid
|
68
|
-
exception =
|
68
|
+
exception = assert_raises(EnumStateMachine::IntegrationNotFound) { EnumStateMachine::Integrations.find_by_name(:invalid) }
|
69
69
|
assert_equal ':invalid is an invalid integration', exception.message
|
70
70
|
end
|
71
71
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
2
|
|
3
|
-
class InvalidEventTest < Test
|
3
|
+
class InvalidEventTest < MiniTest::Test
|
4
4
|
def setup
|
5
5
|
@object = Object.new
|
6
6
|
@invalid_event = EnumStateMachine::InvalidEvent.new(@object, :invalid)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
2
|
|
3
|
-
class InvalidTransitionTest < Test
|
3
|
+
class InvalidTransitionTest < MiniTest::Test
|
4
4
|
def setup
|
5
5
|
@klass = Class.new
|
6
6
|
@machine = EnumStateMachine::Machine.new(@klass)
|
@@ -46,7 +46,7 @@ class InvalidTransitionTest < Test::Unit::TestCase
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
class InvalidTransitionWithNamespaceTest < Test
|
49
|
+
class InvalidTransitionWithNamespaceTest < MiniTest::Test
|
50
50
|
def setup
|
51
51
|
@klass = Class.new
|
52
52
|
@machine = EnumStateMachine::Machine.new(@klass, :namespace => 'alarm')
|
@@ -76,7 +76,7 @@ class InvalidTransitionWithNamespaceTest < Test::Unit::TestCase
|
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
|
-
class InvalidTransitionWithIntegrationTest < Test
|
79
|
+
class InvalidTransitionWithIntegrationTest < MiniTest::Test
|
80
80
|
def setup
|
81
81
|
EnumStateMachine::Integrations.const_set('Custom', Module.new do
|
82
82
|
include EnumStateMachine::Integrations::Base
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
2
|
|
3
|
-
class MachineCollectionByDefaultTest < Test
|
3
|
+
class MachineCollectionByDefaultTest < MiniTest::Test
|
4
4
|
def setup
|
5
5
|
@machines = EnumStateMachine::MachineCollection.new
|
6
6
|
end
|
@@ -10,7 +10,7 @@ class MachineCollectionByDefaultTest < Test::Unit::TestCase
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
class MachineCollectionStateInitializationTest < Test
|
13
|
+
class MachineCollectionStateInitializationTest < MiniTest::Test
|
14
14
|
def setup
|
15
15
|
@machines = EnumStateMachine::MachineCollection.new
|
16
16
|
|
@@ -32,7 +32,7 @@ class MachineCollectionStateInitializationTest < Test::Unit::TestCase
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def test_should_raise_exception_if_invalid_option_specified
|
35
|
-
|
35
|
+
assert_raises(ArgumentError) {@machines.initialize_states(@object, :invalid => true)}
|
36
36
|
end
|
37
37
|
|
38
38
|
def test_should_only_initialize_static_states_prior_to_block
|
@@ -110,7 +110,7 @@ class MachineCollectionStateInitializationTest < Test::Unit::TestCase
|
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
113
|
-
class MachineCollectionFireTest < Test
|
113
|
+
class MachineCollectionFireTest < MiniTest::Test
|
114
114
|
def setup
|
115
115
|
@machines = EnumStateMachine::MachineCollection.new
|
116
116
|
|
@@ -144,10 +144,14 @@ class MachineCollectionFireTest < Test::Unit::TestCase
|
|
144
144
|
end
|
145
145
|
|
146
146
|
def test_should_raise_exception_if_invalid_event_specified
|
147
|
-
exception =
|
147
|
+
exception = assert_raises(EnumStateMachine::InvalidEvent) {
|
148
|
+
@machines.fire_events(@object, :invalid)
|
149
|
+
}
|
148
150
|
assert_equal :invalid, exception.event
|
149
151
|
|
150
|
-
exception =
|
152
|
+
exception = assert_raises(EnumStateMachine::InvalidEvent) {
|
153
|
+
@machines.fire_events(@object, :ignite, :invalid)
|
154
|
+
}
|
151
155
|
assert_equal :invalid, exception.event
|
152
156
|
end
|
153
157
|
|
@@ -189,7 +193,7 @@ class MachineCollectionFireTest < Test::Unit::TestCase
|
|
189
193
|
end
|
190
194
|
end
|
191
195
|
|
192
|
-
class MachineCollectionFireWithTransactionsTest < Test
|
196
|
+
class MachineCollectionFireWithTransactionsTest < MiniTest::Test
|
193
197
|
def setup
|
194
198
|
@machines = EnumStateMachine::MachineCollection.new
|
195
199
|
|
@@ -263,7 +267,7 @@ class MachineCollectionFireWithTransactionsTest < Test::Unit::TestCase
|
|
263
267
|
end
|
264
268
|
end
|
265
269
|
|
266
|
-
class MachineCollectionFireWithValidationsTest < Test
|
270
|
+
class MachineCollectionFireWithValidationsTest < MiniTest::Test
|
267
271
|
def setup
|
268
272
|
EnumStateMachine::Integrations.const_set('Custom', Module.new do
|
269
273
|
include EnumStateMachine::Integrations::Base
|
@@ -331,7 +335,7 @@ class MachineCollectionFireWithValidationsTest < Test::Unit::TestCase
|
|
331
335
|
end
|
332
336
|
end
|
333
337
|
|
334
|
-
class MachineCollectionTransitionsWithoutEventsTest < Test
|
338
|
+
class MachineCollectionTransitionsWithoutEventsTest < MiniTest::Test
|
335
339
|
def setup
|
336
340
|
@klass = Class.new
|
337
341
|
|
@@ -355,7 +359,7 @@ class MachineCollectionTransitionsWithoutEventsTest < Test::Unit::TestCase
|
|
355
359
|
end
|
356
360
|
end
|
357
361
|
|
358
|
-
class MachineCollectionTransitionsWithBlankEventsTest < Test
|
362
|
+
class MachineCollectionTransitionsWithBlankEventsTest < MiniTest::Test
|
359
363
|
def setup
|
360
364
|
@klass = Class.new
|
361
365
|
|
@@ -379,7 +383,7 @@ class MachineCollectionTransitionsWithBlankEventsTest < Test::Unit::TestCase
|
|
379
383
|
end
|
380
384
|
end
|
381
385
|
|
382
|
-
class MachineCollectionTransitionsWithInvalidEventsTest < Test
|
386
|
+
class MachineCollectionTransitionsWithInvalidEventsTest < MiniTest::Test
|
383
387
|
def setup
|
384
388
|
@klass = Class.new
|
385
389
|
|
@@ -403,7 +407,7 @@ class MachineCollectionTransitionsWithInvalidEventsTest < Test::Unit::TestCase
|
|
403
407
|
end
|
404
408
|
end
|
405
409
|
|
406
|
-
class MachineCollectionTransitionsWithoutTransitionTest < Test
|
410
|
+
class MachineCollectionTransitionsWithoutTransitionTest < MiniTest::Test
|
407
411
|
def setup
|
408
412
|
@klass = Class.new
|
409
413
|
|
@@ -428,7 +432,7 @@ class MachineCollectionTransitionsWithoutTransitionTest < Test::Unit::TestCase
|
|
428
432
|
end
|
429
433
|
end
|
430
434
|
|
431
|
-
class MachineCollectionTransitionsWithTransitionTest < Test
|
435
|
+
class MachineCollectionTransitionsWithTransitionTest < MiniTest::Test
|
432
436
|
def setup
|
433
437
|
@klass = Class.new
|
434
438
|
|
@@ -452,7 +456,7 @@ class MachineCollectionTransitionsWithTransitionTest < Test::Unit::TestCase
|
|
452
456
|
end
|
453
457
|
end
|
454
458
|
|
455
|
-
class MachineCollectionTransitionsWithSameActionsTest < Test
|
459
|
+
class MachineCollectionTransitionsWithSameActionsTest < MiniTest::Test
|
456
460
|
def setup
|
457
461
|
@klass = Class.new
|
458
462
|
|
@@ -481,7 +485,7 @@ class MachineCollectionTransitionsWithSameActionsTest < Test::Unit::TestCase
|
|
481
485
|
end
|
482
486
|
end
|
483
487
|
|
484
|
-
class MachineCollectionTransitionsWithDifferentActionsTest < Test
|
488
|
+
class MachineCollectionTransitionsWithDifferentActionsTest < MiniTest::Test
|
485
489
|
def setup
|
486
490
|
@klass = Class.new
|
487
491
|
|
@@ -506,7 +510,7 @@ class MachineCollectionTransitionsWithDifferentActionsTest < Test::Unit::TestCas
|
|
506
510
|
end
|
507
511
|
end
|
508
512
|
|
509
|
-
class MachineCollectionTransitionsWithExisitingTransitionsTest < Test
|
513
|
+
class MachineCollectionTransitionsWithExisitingTransitionsTest < MiniTest::Test
|
510
514
|
def setup
|
511
515
|
@klass = Class.new
|
512
516
|
|
@@ -530,7 +534,7 @@ class MachineCollectionTransitionsWithExisitingTransitionsTest < Test::Unit::Tes
|
|
530
534
|
end
|
531
535
|
end
|
532
536
|
|
533
|
-
class MachineCollectionTransitionsWithCustomOptionsTest < Test
|
537
|
+
class MachineCollectionTransitionsWithCustomOptionsTest < MiniTest::Test
|
534
538
|
def setup
|
535
539
|
@klass = Class.new
|
536
540
|
|
@@ -549,7 +553,7 @@ class MachineCollectionTransitionsWithCustomOptionsTest < Test::Unit::TestCase
|
|
549
553
|
end
|
550
554
|
end
|
551
555
|
|
552
|
-
class MachineCollectionFireAttributesWithValidationsTest < Test
|
556
|
+
class MachineCollectionFireAttributesWithValidationsTest < MiniTest::Test
|
553
557
|
def setup
|
554
558
|
@klass = Class.new do
|
555
559
|
attr_accessor :errors
|
data/test/unit/machine_test.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
2
|
|
3
|
-
class MachineByDefaultTest < Test
|
3
|
+
class MachineByDefaultTest < MiniTest::Test
|
4
4
|
def setup
|
5
5
|
@klass = Class.new
|
6
6
|
@machine = EnumStateMachine::Machine.new(@klass)
|
@@ -24,7 +24,7 @@ class MachineByDefaultTest < Test::Unit::TestCase
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def test_should_have_an_initial_state
|
27
|
-
|
27
|
+
refute_nil @machine.initial_state(@object)
|
28
28
|
end
|
29
29
|
|
30
30
|
def test_should_have_a_nil_initial_state
|
@@ -171,7 +171,7 @@ class MachineByDefaultTest < Test::Unit::TestCase
|
|
171
171
|
end
|
172
172
|
end
|
173
173
|
|
174
|
-
class MachineWithCustomNameTest < Test
|
174
|
+
class MachineWithCustomNameTest < MiniTest::Test
|
175
175
|
def setup
|
176
176
|
@klass = Class.new
|
177
177
|
@machine = EnumStateMachine::Machine.new(@klass, :status)
|
@@ -227,7 +227,7 @@ class MachineWithCustomNameTest < Test::Unit::TestCase
|
|
227
227
|
end
|
228
228
|
end
|
229
229
|
|
230
|
-
class MachineWithoutInitializationTest < Test
|
230
|
+
class MachineWithoutInitializationTest < MiniTest::Test
|
231
231
|
def setup
|
232
232
|
@klass = Class.new do
|
233
233
|
def initialize(attributes = {})
|
@@ -257,7 +257,7 @@ class MachineWithoutInitializationTest < Test::Unit::TestCase
|
|
257
257
|
end
|
258
258
|
end
|
259
259
|
|
260
|
-
class MachineWithStaticInitialStateTest < Test
|
260
|
+
class MachineWithStaticInitialStateTest < MiniTest::Test
|
261
261
|
def setup
|
262
262
|
@klass = Class.new
|
263
263
|
@machine = EnumStateMachine::Machine.new(@klass, :initial => :parked)
|
@@ -316,7 +316,7 @@ class MachineWithStaticInitialStateTest < Test::Unit::TestCase
|
|
316
316
|
end
|
317
317
|
end
|
318
318
|
|
319
|
-
class MachineWithDynamicInitialStateTest < Test
|
319
|
+
class MachineWithDynamicInitialStateTest < MiniTest::Test
|
320
320
|
def setup
|
321
321
|
@klass = Class.new do
|
322
322
|
attr_accessor :initial_state
|
@@ -380,7 +380,7 @@ class MachineWithDynamicInitialStateTest < Test::Unit::TestCase
|
|
380
380
|
end
|
381
381
|
end
|
382
382
|
|
383
|
-
class MachineStateInitializationTest < Test
|
383
|
+
class MachineStateInitializationTest < MiniTest::Test
|
384
384
|
def setup
|
385
385
|
@klass = Class.new
|
386
386
|
@machine = EnumStateMachine::Machine.new(@klass, :state, :initial => :parked, :initialize => false)
|
@@ -434,7 +434,7 @@ class MachineStateInitializationTest < Test::Unit::TestCase
|
|
434
434
|
end
|
435
435
|
end
|
436
436
|
|
437
|
-
class MachineWithCustomActionTest < Test
|
437
|
+
class MachineWithCustomActionTest < MiniTest::Test
|
438
438
|
def setup
|
439
439
|
@machine = EnumStateMachine::Machine.new(Class.new, :action => :save)
|
440
440
|
end
|
@@ -444,7 +444,7 @@ class MachineWithCustomActionTest < Test::Unit::TestCase
|
|
444
444
|
end
|
445
445
|
end
|
446
446
|
|
447
|
-
class MachineWithNilActionTest < Test
|
447
|
+
class MachineWithNilActionTest < MiniTest::Test
|
448
448
|
def setup
|
449
449
|
integration = Module.new do
|
450
450
|
include EnumStateMachine::Integrations::Base
|
@@ -464,7 +464,7 @@ class MachineWithNilActionTest < Test::Unit::TestCase
|
|
464
464
|
end
|
465
465
|
end
|
466
466
|
|
467
|
-
class MachineWithoutIntegrationTest < Test
|
467
|
+
class MachineWithoutIntegrationTest < MiniTest::Test
|
468
468
|
def setup
|
469
469
|
@klass = Class.new
|
470
470
|
@machine = EnumStateMachine::Machine.new(@klass)
|
@@ -493,7 +493,7 @@ class MachineWithoutIntegrationTest < Test::Unit::TestCase
|
|
493
493
|
end
|
494
494
|
end
|
495
495
|
|
496
|
-
class MachineWithCustomIntegrationTest < Test
|
496
|
+
class MachineWithCustomIntegrationTest < MiniTest::Test
|
497
497
|
def setup
|
498
498
|
integration = Module.new do
|
499
499
|
include EnumStateMachine::Integrations::Base
|
@@ -561,7 +561,7 @@ class MachineWithCustomIntegrationTest < Test::Unit::TestCase
|
|
561
561
|
end
|
562
562
|
end
|
563
563
|
|
564
|
-
class MachineWithIntegrationTest < Test
|
564
|
+
class MachineWithIntegrationTest < MiniTest::Test
|
565
565
|
def setup
|
566
566
|
EnumStateMachine::Integrations.const_set('Custom', Module.new do
|
567
567
|
include EnumStateMachine::Integrations::Base
|
@@ -628,7 +628,7 @@ class MachineWithIntegrationTest < Test::Unit::TestCase
|
|
628
628
|
end
|
629
629
|
end
|
630
630
|
|
631
|
-
class MachineWithActionUndefinedTest < Test
|
631
|
+
class MachineWithActionUndefinedTest < MiniTest::Test
|
632
632
|
def setup
|
633
633
|
@klass = Class.new
|
634
634
|
@machine = EnumStateMachine::Machine.new(@klass, :action => :save)
|
@@ -660,7 +660,7 @@ class MachineWithActionUndefinedTest < Test::Unit::TestCase
|
|
660
660
|
end
|
661
661
|
end
|
662
662
|
|
663
|
-
class MachineWithActionDefinedInClassTest < Test
|
663
|
+
class MachineWithActionDefinedInClassTest < MiniTest::Test
|
664
664
|
def setup
|
665
665
|
@klass = Class.new do
|
666
666
|
def save
|
@@ -696,7 +696,7 @@ class MachineWithActionDefinedInClassTest < Test::Unit::TestCase
|
|
696
696
|
end
|
697
697
|
end
|
698
698
|
|
699
|
-
class MachineWithActionDefinedInIncludedModuleTest < Test
|
699
|
+
class MachineWithActionDefinedInIncludedModuleTest < MiniTest::Test
|
700
700
|
def setup
|
701
701
|
@mod = mod = Module.new do
|
702
702
|
def save
|
@@ -740,7 +740,7 @@ class MachineWithActionDefinedInIncludedModuleTest < Test::Unit::TestCase
|
|
740
740
|
end
|
741
741
|
end
|
742
742
|
|
743
|
-
class MachineWithActionDefinedInSuperclassTest < Test
|
743
|
+
class MachineWithActionDefinedInSuperclassTest < MiniTest::Test
|
744
744
|
def setup
|
745
745
|
@superclass = Class.new do
|
746
746
|
def save
|
@@ -781,7 +781,7 @@ class MachineWithActionDefinedInSuperclassTest < Test::Unit::TestCase
|
|
781
781
|
end
|
782
782
|
end
|
783
783
|
|
784
|
-
class MachineWithPrivateActionTest < Test
|
784
|
+
class MachineWithPrivateActionTest < MiniTest::Test
|
785
785
|
def setup
|
786
786
|
@superclass = Class.new do
|
787
787
|
private
|
@@ -823,7 +823,7 @@ class MachineWithPrivateActionTest < Test::Unit::TestCase
|
|
823
823
|
end
|
824
824
|
end
|
825
825
|
|
826
|
-
class MachineWithActionAlreadyOverriddenTest < Test
|
826
|
+
class MachineWithActionAlreadyOverriddenTest < MiniTest::Test
|
827
827
|
def setup
|
828
828
|
@superclass = Class.new do
|
829
829
|
def save
|
@@ -845,7 +845,7 @@ class MachineWithActionAlreadyOverriddenTest < Test::Unit::TestCase
|
|
845
845
|
end
|
846
846
|
end
|
847
847
|
|
848
|
-
class MachineWithCustomPluralTest < Test
|
848
|
+
class MachineWithCustomPluralTest < MiniTest::Test
|
849
849
|
def setup
|
850
850
|
@integration = Module.new do
|
851
851
|
include EnumStateMachine::Integrations::Base
|
@@ -893,7 +893,7 @@ class MachineWithCustomPluralTest < Test::Unit::TestCase
|
|
893
893
|
end
|
894
894
|
end
|
895
895
|
|
896
|
-
class MachineWithCustomInvalidationTest < Test
|
896
|
+
class MachineWithCustomInvalidationTest < MiniTest::Test
|
897
897
|
def setup
|
898
898
|
@integration = Module.new do
|
899
899
|
include EnumStateMachine::Integrations::Base
|
@@ -929,9 +929,9 @@ class MachineWithCustomInvalidationTest < Test::Unit::TestCase
|
|
929
929
|
end
|
930
930
|
end
|
931
931
|
|
932
|
-
class MachineTest < Test
|
932
|
+
class MachineTest < MiniTest::Test
|
933
933
|
def test_should_raise_exception_if_invalid_option_specified
|
934
|
-
|
934
|
+
assert_raises(ArgumentError) {EnumStateMachine::Machine.new(Class.new, :invalid => true)}
|
935
935
|
end
|
936
936
|
|
937
937
|
def test_should_not_raise_exception_if_custom_messages_specified
|
@@ -958,7 +958,7 @@ class MachineTest < Test::Unit::TestCase
|
|
958
958
|
end
|
959
959
|
end
|
960
960
|
|
961
|
-
class MachineAfterBeingCopiedTest < Test
|
961
|
+
class MachineAfterBeingCopiedTest < MiniTest::Test
|
962
962
|
def setup
|
963
963
|
@machine = EnumStateMachine::Machine.new(Class.new, :state, :initial => :parked)
|
964
964
|
@machine.event(:ignite) {}
|
@@ -971,11 +971,11 @@ class MachineAfterBeingCopiedTest < Test::Unit::TestCase
|
|
971
971
|
end
|
972
972
|
|
973
973
|
def test_should_not_have_the_same_collection_of_states
|
974
|
-
|
974
|
+
refute_same @copied_machine.states, @machine.states
|
975
975
|
end
|
976
976
|
|
977
977
|
def test_should_copy_each_state
|
978
|
-
|
978
|
+
refute_same @copied_machine.states[:parked], @machine.states[:parked]
|
979
979
|
end
|
980
980
|
|
981
981
|
def test_should_update_machine_for_each_state
|
@@ -987,11 +987,11 @@ class MachineAfterBeingCopiedTest < Test::Unit::TestCase
|
|
987
987
|
end
|
988
988
|
|
989
989
|
def test_should_not_have_the_same_collection_of_events
|
990
|
-
|
990
|
+
refute_same @copied_machine.events, @machine.events
|
991
991
|
end
|
992
992
|
|
993
993
|
def test_should_copy_each_event
|
994
|
-
|
994
|
+
refute_same @copied_machine.events[:ignite], @machine.events[:ignite]
|
995
995
|
end
|
996
996
|
|
997
997
|
def test_should_update_machine_for_each_event
|
@@ -1003,23 +1003,23 @@ class MachineAfterBeingCopiedTest < Test::Unit::TestCase
|
|
1003
1003
|
end
|
1004
1004
|
|
1005
1005
|
def test_should_not_have_the_same_callbacks
|
1006
|
-
|
1006
|
+
refute_same @copied_machine.callbacks, @machine.callbacks
|
1007
1007
|
end
|
1008
1008
|
|
1009
1009
|
def test_should_not_have_the_same_before_callbacks
|
1010
|
-
|
1010
|
+
refute_same @copied_machine.callbacks[:before], @machine.callbacks[:before]
|
1011
1011
|
end
|
1012
1012
|
|
1013
1013
|
def test_should_not_have_the_same_after_callbacks
|
1014
|
-
|
1014
|
+
refute_same @copied_machine.callbacks[:after], @machine.callbacks[:after]
|
1015
1015
|
end
|
1016
1016
|
|
1017
1017
|
def test_should_not_have_the_same_failure_callbacks
|
1018
|
-
|
1018
|
+
refute_same @copied_machine.callbacks[:failure], @machine.callbacks[:failure]
|
1019
1019
|
end
|
1020
1020
|
end
|
1021
1021
|
|
1022
|
-
class MachineAfterChangingOwnerClassTest < Test
|
1022
|
+
class MachineAfterChangingOwnerClassTest < MiniTest::Test
|
1023
1023
|
def setup
|
1024
1024
|
@original_class = Class.new
|
1025
1025
|
@machine = EnumStateMachine::Machine.new(@original_class)
|
@@ -1048,7 +1048,7 @@ class MachineAfterChangingOwnerClassTest < Test::Unit::TestCase
|
|
1048
1048
|
end
|
1049
1049
|
end
|
1050
1050
|
|
1051
|
-
class MachineAfterChangingInitialState < Test
|
1051
|
+
class MachineAfterChangingInitialState < MiniTest::Test
|
1052
1052
|
def setup
|
1053
1053
|
@klass = Class.new
|
1054
1054
|
@machine = EnumStateMachine::Machine.new(@klass, :initial => :parked)
|
@@ -1074,7 +1074,7 @@ class MachineAfterChangingInitialState < Test::Unit::TestCase
|
|
1074
1074
|
end
|
1075
1075
|
end
|
1076
1076
|
|
1077
|
-
class MachineWithHelpersTest < Test
|
1077
|
+
class MachineWithHelpersTest < MiniTest::Test
|
1078
1078
|
def setup
|
1079
1079
|
@klass = Class.new
|
1080
1080
|
@machine = EnumStateMachine::Machine.new(@klass)
|
@@ -1082,11 +1082,13 @@ class MachineWithHelpersTest < Test::Unit::TestCase
|
|
1082
1082
|
end
|
1083
1083
|
|
1084
1084
|
def test_should_throw_exception_with_invalid_scope
|
1085
|
-
|
1085
|
+
assert_raises(RUBY_VERSION < '1.9' ? IndexError : KeyError) {
|
1086
|
+
@machine.define_helper(:invalid, :park) {}
|
1087
|
+
}
|
1086
1088
|
end
|
1087
1089
|
end
|
1088
1090
|
|
1089
|
-
class MachineWithInstanceHelpersTest < Test
|
1091
|
+
class MachineWithInstanceHelpersTest < MiniTest::Test
|
1090
1092
|
def setup
|
1091
1093
|
@klass = Class.new
|
1092
1094
|
@machine = EnumStateMachine::Machine.new(@klass)
|
@@ -1269,7 +1271,7 @@ class MachineWithInstanceHelpersTest < Test::Unit::TestCase
|
|
1269
1271
|
end
|
1270
1272
|
end
|
1271
1273
|
|
1272
|
-
class MachineWithClassHelpersTest < Test
|
1274
|
+
class MachineWithClassHelpersTest < MiniTest::Test
|
1273
1275
|
def setup
|
1274
1276
|
@klass = Class.new
|
1275
1277
|
@machine = EnumStateMachine::Machine.new(@klass)
|
@@ -1451,7 +1453,7 @@ class MachineWithClassHelpersTest < Test::Unit::TestCase
|
|
1451
1453
|
end
|
1452
1454
|
end
|
1453
1455
|
|
1454
|
-
class MachineWithConflictingHelpersBeforeDefinitionTest < Test
|
1456
|
+
class MachineWithConflictingHelpersBeforeDefinitionTest < MiniTest::Test
|
1455
1457
|
def setup
|
1456
1458
|
require 'stringio'
|
1457
1459
|
@original_stderr, $stderr = $stderr, StringIO.new
|
@@ -1625,7 +1627,7 @@ class MachineWithConflictingHelpersBeforeDefinitionTest < Test::Unit::TestCase
|
|
1625
1627
|
end
|
1626
1628
|
end
|
1627
1629
|
|
1628
|
-
class MachineWithConflictingHelpersAfterDefinitionTest < Test
|
1630
|
+
class MachineWithConflictingHelpersAfterDefinitionTest < MiniTest::Test
|
1629
1631
|
def setup
|
1630
1632
|
require 'stringio'
|
1631
1633
|
@original_stderr, $stderr = $stderr, StringIO.new
|
@@ -1868,7 +1870,7 @@ class MachineWithConflictingHelpersAfterDefinitionTest < Test::Unit::TestCase
|
|
1868
1870
|
end
|
1869
1871
|
end
|
1870
1872
|
|
1871
|
-
class MachineWithSuperclassConflictingHelpersAfterDefinitionTest < Test
|
1873
|
+
class MachineWithSuperclassConflictingHelpersAfterDefinitionTest < MiniTest::Test
|
1872
1874
|
def setup
|
1873
1875
|
require 'stringio'
|
1874
1876
|
@original_stderr, $stderr = $stderr, StringIO.new
|
@@ -1902,7 +1904,7 @@ class MachineWithSuperclassConflictingHelpersAfterDefinitionTest < Test::Unit::T
|
|
1902
1904
|
end
|
1903
1905
|
end
|
1904
1906
|
|
1905
|
-
class MachineWithoutInitializeTest < Test
|
1907
|
+
class MachineWithoutInitializeTest < MiniTest::Test
|
1906
1908
|
def setup
|
1907
1909
|
@klass = Class.new
|
1908
1910
|
@machine = EnumStateMachine::Machine.new(@klass, :initial => :parked)
|
@@ -1914,7 +1916,7 @@ class MachineWithoutInitializeTest < Test::Unit::TestCase
|
|
1914
1916
|
end
|
1915
1917
|
end
|
1916
1918
|
|
1917
|
-
class MachineWithInitializeWithoutSuperTest < Test
|
1919
|
+
class MachineWithInitializeWithoutSuperTest < MiniTest::Test
|
1918
1920
|
def setup
|
1919
1921
|
@klass = Class.new do
|
1920
1922
|
def initialize
|
@@ -1929,7 +1931,7 @@ class MachineWithInitializeWithoutSuperTest < Test::Unit::TestCase
|
|
1929
1931
|
end
|
1930
1932
|
end
|
1931
1933
|
|
1932
|
-
class MachineWithInitializeAndSuperTest < Test
|
1934
|
+
class MachineWithInitializeAndSuperTest < MiniTest::Test
|
1933
1935
|
def setup
|
1934
1936
|
@klass = Class.new do
|
1935
1937
|
def initialize
|
@@ -1945,7 +1947,7 @@ class MachineWithInitializeAndSuperTest < Test::Unit::TestCase
|
|
1945
1947
|
end
|
1946
1948
|
end
|
1947
1949
|
|
1948
|
-
class MachineWithInitializeArgumentsAndBlockTest < Test
|
1950
|
+
class MachineWithInitializeArgumentsAndBlockTest < MiniTest::Test
|
1949
1951
|
def setup
|
1950
1952
|
@superclass = Class.new do
|
1951
1953
|
attr_reader :args
|
@@ -1974,7 +1976,7 @@ class MachineWithInitializeArgumentsAndBlockTest < Test::Unit::TestCase
|
|
1974
1976
|
end
|
1975
1977
|
end
|
1976
1978
|
|
1977
|
-
class MachineWithCustomInitializeTest < Test
|
1979
|
+
class MachineWithCustomInitializeTest < MiniTest::Test
|
1978
1980
|
def setup
|
1979
1981
|
@klass = Class.new do
|
1980
1982
|
def initialize(state = nil, options = {})
|
@@ -1997,7 +1999,7 @@ class MachineWithCustomInitializeTest < Test::Unit::TestCase
|
|
1997
1999
|
end
|
1998
2000
|
end
|
1999
2001
|
|
2000
|
-
class MachinePersistenceTest < Test
|
2002
|
+
class MachinePersistenceTest < MiniTest::Test
|
2001
2003
|
def setup
|
2002
2004
|
@klass = Class.new do
|
2003
2005
|
attr_accessor :state_event
|
@@ -2023,7 +2025,7 @@ class MachinePersistenceTest < Test::Unit::TestCase
|
|
2023
2025
|
end
|
2024
2026
|
|
2025
2027
|
@object.state_value = 1
|
2026
|
-
|
2028
|
+
assert_raises(NoMethodError) { @machine.read(@object, :value) }
|
2027
2029
|
assert_equal 1, @machine.read(@object, :value, true)
|
2028
2030
|
end
|
2029
2031
|
|
@@ -2042,14 +2044,14 @@ class MachinePersistenceTest < Test::Unit::TestCase
|
|
2042
2044
|
attr_reader :state_value
|
2043
2045
|
end
|
2044
2046
|
|
2045
|
-
|
2047
|
+
assert_raises(NoMethodError) { @machine.write(@object, :value, 1) }
|
2046
2048
|
assert_equal 1, @machine.write(@object, :value, 1, true)
|
2047
2049
|
assert_equal 1, @object.state_value
|
2048
2050
|
end
|
2049
2051
|
end
|
2050
2052
|
|
2051
2053
|
|
2052
|
-
class MachineWithStatesTest < Test
|
2054
|
+
class MachineWithStatesTest < MiniTest::Test
|
2053
2055
|
def setup
|
2054
2056
|
@klass = Class.new
|
2055
2057
|
@machine = EnumStateMachine::Machine.new(@klass)
|
@@ -2075,7 +2077,7 @@ class MachineWithStatesTest < Test::Unit::TestCase
|
|
2075
2077
|
end
|
2076
2078
|
|
2077
2079
|
def test_should_raise_exception_on_invalid_human_state_name_lookup
|
2078
|
-
exception =
|
2080
|
+
exception = assert_raises(IndexError) {@klass.human_state_name(:invalid)}
|
2079
2081
|
assert_equal ':invalid is an invalid name', exception.message
|
2080
2082
|
end
|
2081
2083
|
|
@@ -2088,12 +2090,12 @@ class MachineWithStatesTest < Test::Unit::TestCase
|
|
2088
2090
|
end
|
2089
2091
|
|
2090
2092
|
def test_should_raise_exception_if_invalid_option_specified
|
2091
|
-
exception =
|
2093
|
+
exception = assert_raises(ArgumentError) {@machine.state(:first_gear, :invalid => true)}
|
2092
2094
|
assert_equal 'Invalid key(s): invalid', exception.message
|
2093
2095
|
end
|
2094
2096
|
|
2095
2097
|
def test_should_raise_exception_if_conflicting_type_used_for_name
|
2096
|
-
exception =
|
2098
|
+
exception = assert_raises(ArgumentError) { @machine.state 'first_gear' }
|
2097
2099
|
assert_equal '"first_gear" state defined as String, :parked defined as Symbol; all states must be consistent', exception.message
|
2098
2100
|
end
|
2099
2101
|
|
@@ -2102,7 +2104,7 @@ class MachineWithStatesTest < Test::Unit::TestCase
|
|
2102
2104
|
end
|
2103
2105
|
end
|
2104
2106
|
|
2105
|
-
class MachineWithStatesWithCustomValuesTest < Test
|
2107
|
+
class MachineWithStatesWithCustomValuesTest < MiniTest::Test
|
2106
2108
|
def setup
|
2107
2109
|
@klass = Class.new
|
2108
2110
|
@machine = EnumStateMachine::Machine.new(@klass)
|
@@ -2121,7 +2123,7 @@ class MachineWithStatesWithCustomValuesTest < Test::Unit::TestCase
|
|
2121
2123
|
end
|
2122
2124
|
end
|
2123
2125
|
|
2124
|
-
class MachineWithStatesWithCustomHumanNamesTest < Test
|
2126
|
+
class MachineWithStatesWithCustomHumanNamesTest < MiniTest::Test
|
2125
2127
|
def setup
|
2126
2128
|
@klass = Class.new
|
2127
2129
|
@machine = EnumStateMachine::Machine.new(@klass)
|
@@ -2137,7 +2139,7 @@ class MachineWithStatesWithCustomHumanNamesTest < Test::Unit::TestCase
|
|
2137
2139
|
end
|
2138
2140
|
end
|
2139
2141
|
|
2140
|
-
class MachineWithStatesWithRuntimeDependenciesTest < Test
|
2142
|
+
class MachineWithStatesWithRuntimeDependenciesTest < MiniTest::Test
|
2141
2143
|
def setup
|
2142
2144
|
@klass = Class.new
|
2143
2145
|
@machine = EnumStateMachine::Machine.new(@klass)
|
@@ -2154,7 +2156,7 @@ class MachineWithStatesWithRuntimeDependenciesTest < Test::Unit::TestCase
|
|
2154
2156
|
end
|
2155
2157
|
end
|
2156
2158
|
|
2157
|
-
class MachineWithStateWithMatchersTest < Test
|
2159
|
+
class MachineWithStateWithMatchersTest < MiniTest::Test
|
2158
2160
|
def setup
|
2159
2161
|
@klass = Class.new
|
2160
2162
|
@machine = EnumStateMachine::Machine.new(@klass)
|
@@ -2165,13 +2167,13 @@ class MachineWithStateWithMatchersTest < Test::Unit::TestCase
|
|
2165
2167
|
end
|
2166
2168
|
|
2167
2169
|
def test_should_use_custom_matcher
|
2168
|
-
|
2170
|
+
refute_nil @state.matcher
|
2169
2171
|
assert @state.matches?(1)
|
2170
2172
|
assert !@state.matches?(nil)
|
2171
2173
|
end
|
2172
2174
|
end
|
2173
2175
|
|
2174
|
-
class MachineWithCachedStateTest < Test
|
2176
|
+
class MachineWithCachedStateTest < MiniTest::Test
|
2175
2177
|
def setup
|
2176
2178
|
@klass = Class.new
|
2177
2179
|
@machine = EnumStateMachine::Machine.new(@klass, :initial => :parked)
|
@@ -2189,7 +2191,7 @@ class MachineWithCachedStateTest < Test::Unit::TestCase
|
|
2189
2191
|
end
|
2190
2192
|
end
|
2191
2193
|
|
2192
|
-
class MachineWithStatesWithBehaviorsTest < Test
|
2194
|
+
class MachineWithStatesWithBehaviorsTest < MiniTest::Test
|
2193
2195
|
def setup
|
2194
2196
|
@klass = Class.new
|
2195
2197
|
@machine = EnumStateMachine::Machine.new(@klass)
|
@@ -2202,16 +2204,16 @@ class MachineWithStatesWithBehaviorsTest < Test::Unit::TestCase
|
|
2202
2204
|
end
|
2203
2205
|
|
2204
2206
|
def test_should_define_behaviors_for_each_state
|
2205
|
-
|
2206
|
-
|
2207
|
+
refute_nil @parked.context_methods[:speed]
|
2208
|
+
refute_nil @idling.context_methods[:speed]
|
2207
2209
|
end
|
2208
2210
|
|
2209
2211
|
def test_should_define_different_behaviors_for_each_state
|
2210
|
-
|
2212
|
+
refute_equal @parked.context_methods[:speed], @idling.context_methods[:speed]
|
2211
2213
|
end
|
2212
2214
|
end
|
2213
2215
|
|
2214
|
-
class MachineWithExistingStateTest < Test
|
2216
|
+
class MachineWithExistingStateTest < MiniTest::Test
|
2215
2217
|
def setup
|
2216
2218
|
@klass = Class.new
|
2217
2219
|
@machine = EnumStateMachine::Machine.new(@klass)
|
@@ -2236,7 +2238,7 @@ class MachineWithExistingStateTest < Test::Unit::TestCase
|
|
2236
2238
|
end
|
2237
2239
|
end
|
2238
2240
|
|
2239
|
-
class MachineWithStateMatchersTest < Test
|
2241
|
+
class MachineWithStateMatchersTest < MiniTest::Test
|
2240
2242
|
def setup
|
2241
2243
|
@klass = Class.new
|
2242
2244
|
@machine = EnumStateMachine::Machine.new(@klass)
|
@@ -2251,7 +2253,9 @@ class MachineWithStateMatchersTest < Test::Unit::TestCase
|
|
2251
2253
|
end
|
2252
2254
|
|
2253
2255
|
def test_should_not_allow_configurations
|
2254
|
-
exception =
|
2256
|
+
exception = assert_raises(ArgumentError) {
|
2257
|
+
@machine.state(EnumStateMachine::BlacklistMatcher.new([:parked]), :human_name => 'Parked')
|
2258
|
+
}
|
2255
2259
|
assert_equal 'Cannot configure states when using matchers (using {:human_name=>"Parked"})', exception.message
|
2256
2260
|
end
|
2257
2261
|
|
@@ -2275,7 +2279,7 @@ class MachineWithStateMatchersTest < Test::Unit::TestCase
|
|
2275
2279
|
end
|
2276
2280
|
end
|
2277
2281
|
|
2278
|
-
class MachineWithOtherStates < Test
|
2282
|
+
class MachineWithOtherStates < MiniTest::Test
|
2279
2283
|
def setup
|
2280
2284
|
@klass = Class.new
|
2281
2285
|
@machine = EnumStateMachine::Machine.new(@klass, :initial => :parked)
|
@@ -2295,7 +2299,7 @@ class MachineWithOtherStates < Test::Unit::TestCase
|
|
2295
2299
|
end
|
2296
2300
|
end
|
2297
2301
|
|
2298
|
-
class MachineWithEventsTest < Test
|
2302
|
+
class MachineWithEventsTest < MiniTest::Test
|
2299
2303
|
def setup
|
2300
2304
|
@klass = Class.new
|
2301
2305
|
@machine = EnumStateMachine::Machine.new(@klass)
|
@@ -2335,18 +2339,18 @@ class MachineWithEventsTest < Test::Unit::TestCase
|
|
2335
2339
|
end
|
2336
2340
|
|
2337
2341
|
def test_should_raise_exception_on_invalid_human_state_event_name_lookup
|
2338
|
-
exception =
|
2342
|
+
exception = assert_raises(IndexError) {@klass.human_state_event_name(:invalid)}
|
2339
2343
|
assert_equal ':invalid is an invalid name', exception.message
|
2340
2344
|
end
|
2341
2345
|
|
2342
2346
|
def test_should_raise_exception_if_conflicting_type_used_for_name
|
2343
2347
|
@machine.event :park
|
2344
|
-
exception =
|
2348
|
+
exception = assert_raises(ArgumentError) { @machine.event 'ignite' }
|
2345
2349
|
assert_equal '"ignite" event defined as String, :park defined as Symbol; all events must be consistent', exception.message
|
2346
2350
|
end
|
2347
2351
|
end
|
2348
2352
|
|
2349
|
-
class MachineWithExistingEventTest < Test
|
2353
|
+
class MachineWithExistingEventTest < MiniTest::Test
|
2350
2354
|
def setup
|
2351
2355
|
@machine = EnumStateMachine::Machine.new(Class.new)
|
2352
2356
|
@event = @machine.event(:ignite)
|
@@ -2362,7 +2366,7 @@ class MachineWithExistingEventTest < Test::Unit::TestCase
|
|
2362
2366
|
end
|
2363
2367
|
end
|
2364
2368
|
|
2365
|
-
class MachineWithEventsWithCustomHumanNamesTest < Test
|
2369
|
+
class MachineWithEventsWithCustomHumanNamesTest < MiniTest::Test
|
2366
2370
|
def setup
|
2367
2371
|
@klass = Class.new
|
2368
2372
|
@machine = EnumStateMachine::Machine.new(@klass)
|
@@ -2378,7 +2382,7 @@ class MachineWithEventsWithCustomHumanNamesTest < Test::Unit::TestCase
|
|
2378
2382
|
end
|
2379
2383
|
end
|
2380
2384
|
|
2381
|
-
class MachineWithEventMatchersTest < Test
|
2385
|
+
class MachineWithEventMatchersTest < MiniTest::Test
|
2382
2386
|
def setup
|
2383
2387
|
@klass = Class.new
|
2384
2388
|
@machine = EnumStateMachine::Machine.new(@klass)
|
@@ -2393,7 +2397,9 @@ class MachineWithEventMatchersTest < Test::Unit::TestCase
|
|
2393
2397
|
end
|
2394
2398
|
|
2395
2399
|
def test_should_not_allow_configurations
|
2396
|
-
exception =
|
2400
|
+
exception = assert_raises(ArgumentError) {
|
2401
|
+
@machine.event(EnumStateMachine::BlacklistMatcher.new([:park]), :human_name => 'Park')
|
2402
|
+
}
|
2397
2403
|
assert_equal 'Cannot configure events when using matchers (using {:human_name=>"Park"})', exception.message
|
2398
2404
|
end
|
2399
2405
|
|
@@ -2417,7 +2423,7 @@ class MachineWithEventMatchersTest < Test::Unit::TestCase
|
|
2417
2423
|
end
|
2418
2424
|
end
|
2419
2425
|
|
2420
|
-
class MachineWithEventsWithTransitionsTest < Test
|
2426
|
+
class MachineWithEventsWithTransitionsTest < MiniTest::Test
|
2421
2427
|
def setup
|
2422
2428
|
@klass = Class.new
|
2423
2429
|
@machine = EnumStateMachine::Machine.new(@klass, :initial => :parked)
|
@@ -2452,7 +2458,7 @@ class MachineWithEventsWithTransitionsTest < Test::Unit::TestCase
|
|
2452
2458
|
end
|
2453
2459
|
end
|
2454
2460
|
|
2455
|
-
class MachineWithMultipleEventsTest < Test
|
2461
|
+
class MachineWithMultipleEventsTest < MiniTest::Test
|
2456
2462
|
def setup
|
2457
2463
|
@klass = Class.new
|
2458
2464
|
@machine = EnumStateMachine::Machine.new(@klass, :initial => :parked)
|
@@ -2482,19 +2488,21 @@ class MachineWithMultipleEventsTest < Test::Unit::TestCase
|
|
2482
2488
|
end
|
2483
2489
|
end
|
2484
2490
|
|
2485
|
-
class MachineWithTransitionsTest < Test
|
2491
|
+
class MachineWithTransitionsTest < MiniTest::Test
|
2486
2492
|
def setup
|
2487
2493
|
@klass = Class.new
|
2488
2494
|
@machine = EnumStateMachine::Machine.new(@klass, :initial => :parked)
|
2489
2495
|
end
|
2490
2496
|
|
2491
2497
|
def test_should_require_on_event
|
2492
|
-
exception =
|
2498
|
+
exception = assert_raises(ArgumentError) { @machine.transition(:parked => :idling) }
|
2493
2499
|
assert_equal 'Must specify :on event', exception.message
|
2494
2500
|
end
|
2495
2501
|
|
2496
2502
|
def test_should_not_allow_except_on_option
|
2497
|
-
exception =
|
2503
|
+
exception = assert_raises(ArgumentError) {
|
2504
|
+
@machine.transition(:except_on => :ignite, :on => :ignite)
|
2505
|
+
}
|
2498
2506
|
assert_equal 'Invalid key(s): except_on', exception.message
|
2499
2507
|
end
|
2500
2508
|
|
@@ -2568,7 +2576,7 @@ class MachineWithTransitionsTest < Test::Unit::TestCase
|
|
2568
2576
|
end
|
2569
2577
|
end
|
2570
2578
|
|
2571
|
-
class MachineWithTransitionCallbacksTest < Test
|
2579
|
+
class MachineWithTransitionCallbacksTest < MiniTest::Test
|
2572
2580
|
def setup
|
2573
2581
|
@klass = Class.new do
|
2574
2582
|
attr_accessor :callbacks
|
@@ -2588,7 +2596,7 @@ class MachineWithTransitionCallbacksTest < Test::Unit::TestCase
|
|
2588
2596
|
end
|
2589
2597
|
|
2590
2598
|
def test_should_raise_exception_if_method_not_specified
|
2591
|
-
exception =
|
2599
|
+
exception = assert_raises(ArgumentError) {@machine.before_transition :to => :idling}
|
2592
2600
|
assert_equal 'Method(s) for callback must be specified', exception.message
|
2593
2601
|
end
|
2594
2602
|
|
@@ -2711,7 +2719,7 @@ class MachineWithTransitionCallbacksTest < Test::Unit::TestCase
|
|
2711
2719
|
end
|
2712
2720
|
end
|
2713
2721
|
|
2714
|
-
class MachineWithFailureCallbacksTest < Test
|
2722
|
+
class MachineWithFailureCallbacksTest < MiniTest::Test
|
2715
2723
|
def setup
|
2716
2724
|
@klass = Class.new do
|
2717
2725
|
attr_accessor :callbacks
|
@@ -2725,12 +2733,14 @@ class MachineWithFailureCallbacksTest < Test::Unit::TestCase
|
|
2725
2733
|
end
|
2726
2734
|
|
2727
2735
|
def test_should_raise_exception_if_implicit_option_specified
|
2728
|
-
exception =
|
2736
|
+
exception = assert_raises(ArgumentError) {
|
2737
|
+
@machine.after_failure :invalid => :valid, :do => lambda {}
|
2738
|
+
}
|
2729
2739
|
assert_equal 'Invalid key(s): invalid', exception.message
|
2730
2740
|
end
|
2731
2741
|
|
2732
2742
|
def test_should_raise_exception_if_method_not_specified
|
2733
|
-
exception =
|
2743
|
+
exception = assert_raises(ArgumentError) {@machine.after_failure :on => :ignite}
|
2734
2744
|
assert_equal 'Method(s) for callback must be specified', exception.message
|
2735
2745
|
end
|
2736
2746
|
|
@@ -2757,7 +2767,7 @@ class MachineWithFailureCallbacksTest < Test::Unit::TestCase
|
|
2757
2767
|
end
|
2758
2768
|
end
|
2759
2769
|
|
2760
|
-
class MachineWithPathsTest < Test
|
2770
|
+
class MachineWithPathsTest < MiniTest::Test
|
2761
2771
|
def setup
|
2762
2772
|
@klass = Class.new
|
2763
2773
|
@machine = EnumStateMachine::Machine.new(@klass)
|
@@ -2781,7 +2791,7 @@ class MachineWithPathsTest < Test::Unit::TestCase
|
|
2781
2791
|
end
|
2782
2792
|
end
|
2783
2793
|
|
2784
|
-
class MachineWithOwnerSubclassTest < Test
|
2794
|
+
class MachineWithOwnerSubclassTest < MiniTest::Test
|
2785
2795
|
def setup
|
2786
2796
|
@klass = Class.new
|
2787
2797
|
@machine = EnumStateMachine::Machine.new(@klass)
|
@@ -2789,7 +2799,7 @@ class MachineWithOwnerSubclassTest < Test::Unit::TestCase
|
|
2789
2799
|
end
|
2790
2800
|
|
2791
2801
|
def test_should_have_a_different_collection_of_state_machines
|
2792
|
-
|
2802
|
+
refute_same @klass.state_machines, @subclass.state_machines
|
2793
2803
|
end
|
2794
2804
|
|
2795
2805
|
def test_should_have_the_same_attribute_associated_state_machines
|
@@ -2797,7 +2807,7 @@ class MachineWithOwnerSubclassTest < Test::Unit::TestCase
|
|
2797
2807
|
end
|
2798
2808
|
end
|
2799
2809
|
|
2800
|
-
class MachineWithExistingMachinesOnOwnerClassTest < Test
|
2810
|
+
class MachineWithExistingMachinesOnOwnerClassTest < MiniTest::Test
|
2801
2811
|
def setup
|
2802
2812
|
@klass = Class.new
|
2803
2813
|
@machine = EnumStateMachine::Machine.new(@klass, :initial => :parked)
|
@@ -2816,7 +2826,7 @@ class MachineWithExistingMachinesOnOwnerClassTest < Test::Unit::TestCase
|
|
2816
2826
|
end
|
2817
2827
|
end
|
2818
2828
|
|
2819
|
-
class MachineWithExistingMachinesWithSameAttributesOnOwnerClassTest < Test
|
2829
|
+
class MachineWithExistingMachinesWithSameAttributesOnOwnerClassTest < MiniTest::Test
|
2820
2830
|
def setup
|
2821
2831
|
@klass = Class.new
|
2822
2832
|
@machine = EnumStateMachine::Machine.new(@klass, :initial => :parked)
|
@@ -2885,7 +2895,7 @@ class MachineWithExistingMachinesWithSameAttributesOnOwnerClassTest < Test::Unit
|
|
2885
2895
|
end
|
2886
2896
|
end
|
2887
2897
|
|
2888
|
-
class MachineWithExistingMachinesWithSameAttributesOnOwnerSubclassTest < Test
|
2898
|
+
class MachineWithExistingMachinesWithSameAttributesOnOwnerSubclassTest < MiniTest::Test
|
2889
2899
|
def setup
|
2890
2900
|
@klass = Class.new
|
2891
2901
|
@machine = EnumStateMachine::Machine.new(@klass, :initial => :parked)
|
@@ -2903,7 +2913,7 @@ class MachineWithExistingMachinesWithSameAttributesOnOwnerSubclassTest < Test::U
|
|
2903
2913
|
def test_should_copy_sibling_machines_to_subclass_after_new_state
|
2904
2914
|
subclass_machine = @subclass.state_machine(:state) {}
|
2905
2915
|
subclass_machine.state :first_gear
|
2906
|
-
|
2916
|
+
refute_equal @klass.state_machine(:public_state), @subclass.state_machine(:public_state)
|
2907
2917
|
end
|
2908
2918
|
|
2909
2919
|
def test_should_copy_new_states_to_sibling_machines
|
@@ -2915,7 +2925,7 @@ class MachineWithExistingMachinesWithSameAttributesOnOwnerSubclassTest < Test::U
|
|
2915
2925
|
end
|
2916
2926
|
end
|
2917
2927
|
|
2918
|
-
class MachineWithNamespaceTest < Test
|
2928
|
+
class MachineWithNamespaceTest < MiniTest::Test
|
2919
2929
|
def setup
|
2920
2930
|
@klass = Class.new
|
2921
2931
|
@machine = EnumStateMachine::Machine.new(@klass, :namespace => 'alarm', :initial => :active) do
|
@@ -2961,7 +2971,7 @@ class MachineWithNamespaceTest < Test::Unit::TestCase
|
|
2961
2971
|
end
|
2962
2972
|
end
|
2963
2973
|
|
2964
|
-
class MachineWithCustomAttributeTest < Test
|
2974
|
+
class MachineWithCustomAttributeTest < MiniTest::Test
|
2965
2975
|
def setup
|
2966
2976
|
EnumStateMachine::Integrations.const_set('Custom', Module.new do
|
2967
2977
|
include EnumStateMachine::Integrations::Base
|
@@ -3056,7 +3066,7 @@ class MachineWithCustomAttributeTest < Test::Unit::TestCase
|
|
3056
3066
|
end
|
3057
3067
|
end
|
3058
3068
|
|
3059
|
-
class MachineFinderWithoutExistingMachineTest < Test
|
3069
|
+
class MachineFinderWithoutExistingMachineTest < MiniTest::Test
|
3060
3070
|
def setup
|
3061
3071
|
@klass = Class.new
|
3062
3072
|
@machine = EnumStateMachine::Machine.find_or_create(@klass)
|
@@ -3072,7 +3082,7 @@ class MachineFinderWithoutExistingMachineTest < Test::Unit::TestCase
|
|
3072
3082
|
end
|
3073
3083
|
|
3074
3084
|
def test_should_create_a_new_machine
|
3075
|
-
|
3085
|
+
refute_nil @machine
|
3076
3086
|
end
|
3077
3087
|
|
3078
3088
|
def test_should_use_default_state
|
@@ -3080,7 +3090,7 @@ class MachineFinderWithoutExistingMachineTest < Test::Unit::TestCase
|
|
3080
3090
|
end
|
3081
3091
|
end
|
3082
3092
|
|
3083
|
-
class MachineFinderWithExistingOnSameClassTest < Test
|
3093
|
+
class MachineFinderWithExistingOnSameClassTest < MiniTest::Test
|
3084
3094
|
def setup
|
3085
3095
|
@klass = Class.new
|
3086
3096
|
@existing_machine = EnumStateMachine::Machine.new(@klass)
|
@@ -3101,7 +3111,7 @@ class MachineFinderWithExistingOnSameClassTest < Test::Unit::TestCase
|
|
3101
3111
|
end
|
3102
3112
|
end
|
3103
3113
|
|
3104
|
-
class MachineFinderWithExistingMachineOnSuperclassTest < Test
|
3114
|
+
class MachineFinderWithExistingMachineOnSuperclassTest < MiniTest::Test
|
3105
3115
|
def setup
|
3106
3116
|
integration = Module.new do
|
3107
3117
|
include EnumStateMachine::Integrations::Base
|
@@ -3141,13 +3151,13 @@ class MachineFinderWithExistingMachineOnSuperclassTest < Test::Unit::TestCase
|
|
3141
3151
|
def test_should_create_a_new_machine_if_given_options
|
3142
3152
|
machine = EnumStateMachine::Machine.find_or_create(@klass, :status, :initial => :parked)
|
3143
3153
|
|
3144
|
-
|
3145
|
-
|
3154
|
+
refute_nil machine
|
3155
|
+
refute_same machine, @base_machine
|
3146
3156
|
end
|
3147
3157
|
|
3148
3158
|
def test_should_create_a_new_machine_if_given_block
|
3149
|
-
|
3150
|
-
|
3159
|
+
refute_nil @machine
|
3160
|
+
refute_same @machine, @base_machine
|
3151
3161
|
end
|
3152
3162
|
|
3153
3163
|
def test_should_copy_the_base_attribute
|
@@ -3180,7 +3190,7 @@ class MachineFinderWithExistingMachineOnSuperclassTest < Test::Unit::TestCase
|
|
3180
3190
|
end
|
3181
3191
|
end
|
3182
3192
|
|
3183
|
-
class MachineFinderCustomOptionsTest < Test
|
3193
|
+
class MachineFinderCustomOptionsTest < MiniTest::Test
|
3184
3194
|
def setup
|
3185
3195
|
@klass = Class.new
|
3186
3196
|
@machine = EnumStateMachine::Machine.find_or_create(@klass, :status, :initial => :parked)
|
@@ -3200,7 +3210,7 @@ begin
|
|
3200
3210
|
# Load library
|
3201
3211
|
require 'graphviz'
|
3202
3212
|
|
3203
|
-
class MachineDrawingTest < Test
|
3213
|
+
class MachineDrawingTest < MiniTest::Test
|
3204
3214
|
def setup
|
3205
3215
|
@klass = Class.new do
|
3206
3216
|
def self.name; @name ||= "Vehicle_#{rand(1000000)}"; end
|
@@ -3212,7 +3222,7 @@ begin
|
|
3212
3222
|
end
|
3213
3223
|
|
3214
3224
|
def test_should_raise_exception_if_invalid_option_specified
|
3215
|
-
|
3225
|
+
assert_raises(ArgumentError) {@machine.draw(:invalid => true)}
|
3216
3226
|
end
|
3217
3227
|
|
3218
3228
|
def test_should_save_file_with_class_name_by_default
|
@@ -3269,7 +3279,7 @@ begin
|
|
3269
3279
|
end
|
3270
3280
|
end
|
3271
3281
|
|
3272
|
-
class MachineDrawingWithIntegerStatesTest < Test
|
3282
|
+
class MachineDrawingWithIntegerStatesTest < MiniTest::Test
|
3273
3283
|
def setup
|
3274
3284
|
@klass = Class.new do
|
3275
3285
|
def self.name; @name ||= "Vehicle_#{rand(1000000)}"; end
|
@@ -3300,7 +3310,7 @@ begin
|
|
3300
3310
|
end
|
3301
3311
|
end
|
3302
3312
|
|
3303
|
-
class MachineDrawingWithNilStatesTest < Test
|
3313
|
+
class MachineDrawingWithNilStatesTest < MiniTest::Test
|
3304
3314
|
def setup
|
3305
3315
|
@klass = Class.new do
|
3306
3316
|
def self.name; @name ||= "Vehicle_#{rand(1000000)}"; end
|
@@ -3330,7 +3340,7 @@ begin
|
|
3330
3340
|
end
|
3331
3341
|
end
|
3332
3342
|
|
3333
|
-
class MachineDrawingWithDynamicStatesTest < Test
|
3343
|
+
class MachineDrawingWithDynamicStatesTest < MiniTest::Test
|
3334
3344
|
def setup
|
3335
3345
|
@klass = Class.new do
|
3336
3346
|
def self.name; @name ||= "Vehicle_#{rand(1000000)}"; end
|
@@ -3360,7 +3370,10 @@ begin
|
|
3360
3370
|
end
|
3361
3371
|
end
|
3362
3372
|
|
3363
|
-
class MachineClassDrawingTest < Test
|
3373
|
+
class MachineClassDrawingTest < MiniTest::Test
|
3374
|
+
# Needed explicitly because of Simplecov weirdness
|
3375
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../files/switch")
|
3376
|
+
|
3364
3377
|
def setup
|
3365
3378
|
@klass = Class.new do
|
3366
3379
|
def self.name; @name ||= "Vehicle_#{rand(1000000)}"; end
|
@@ -3372,7 +3385,7 @@ begin
|
|
3372
3385
|
end
|
3373
3386
|
|
3374
3387
|
def test_should_raise_exception_if_no_class_names_specified
|
3375
|
-
exception =
|
3388
|
+
exception = assert_raises(ArgumentError) {EnumStateMachine::Machine.draw(nil)}
|
3376
3389
|
assert_equal 'At least one class must be specified', exception.message
|
3377
3390
|
end
|
3378
3391
|
|
@@ -3383,11 +3396,11 @@ begin
|
|
3383
3396
|
|
3384
3397
|
def test_should_allow_path_and_format_to_be_customized
|
3385
3398
|
EnumStateMachine::Machine.draw('Switch', :file => File.expand_path("#{File.dirname(__FILE__)}/../files/switch.rb"), :path => "#{File.dirname(__FILE__)}/", :format => 'jpg')
|
3386
|
-
assert File.exist?("#{File.dirname(__FILE__)}/#{Switch.name}_state.jpg")
|
3399
|
+
assert File.exist?("#{File.dirname(__FILE__)}/#{::Switch.name}_state.jpg")
|
3387
3400
|
end
|
3388
3401
|
|
3389
3402
|
def teardown
|
3390
|
-
FileUtils.rm Dir["{.,#{File.dirname(__FILE__)}}/#{Switch.name}_state.{jpg,png}"]
|
3403
|
+
FileUtils.rm Dir["{.,#{File.dirname(__FILE__)}}/#{::Switch.name}_state.{jpg,png}"]
|
3391
3404
|
end
|
3392
3405
|
end
|
3393
3406
|
rescue LoadError
|