class StateCollectionTest
Public Instance Methods
setup()
click to toggle source
# File test/unit/state_collection_test.rb, line 23 def setup @klass = Class.new @machine = StateMachine::Machine.new(@klass) @states = StateMachine::StateCollection.new(@machine) @states << @nil = StateMachine::State.new(@machine, nil) @states << @parked = StateMachine::State.new(@machine, :parked) @states << @idling = StateMachine::State.new(@machine, :idling) @machine.states.concat(@states) @object = @klass.new end
test_raise_exception_if_matching_invalid_state()
click to toggle source
# File test/unit/state_collection_test.rb, line 65 def test_raise_exception_if_matching_invalid_state assert_raise(IndexError) { @states.matches?(@object, :invalid) } end
test_should_find_bang_state_for_object_if_value_is_known()
click to toggle source
# File test/unit/state_collection_test.rb, line 74 def test_should_find_bang_state_for_object_if_value_is_known @object.state = 'parked' assert_equal @parked, @states.match!(@object) end
test_should_find_state_for_object_if_value_is_known()
click to toggle source
# File test/unit/state_collection_test.rb, line 69 def test_should_find_state_for_object_if_value_is_known @object.state = 'parked' assert_equal @parked, @states.match(@object) end
test_should_index_by_name()
click to toggle source
# File test/unit/state_collection_test.rb, line 36 def test_should_index_by_name assert_equal @parked, @states[:parked, :name] end
test_should_index_by_name_by_default()
click to toggle source
# File test/unit/state_collection_test.rb, line 40 def test_should_index_by_name_by_default assert_equal @parked, @states[:parked] end
test_should_index_by_qualified_name()
click to toggle source
# File test/unit/state_collection_test.rb, line 48 def test_should_index_by_qualified_name assert_equal @parked, @states[:parked, :qualified_name] end
test_should_index_by_string_name()
click to toggle source
# File test/unit/state_collection_test.rb, line 44 def test_should_index_by_string_name assert_equal @parked, @states['parked'] end
test_should_index_by_value()
click to toggle source
# File test/unit/state_collection_test.rb, line 52 def test_should_index_by_value assert_equal @parked, @states['parked', :value] end
test_should_match_if_value_matches()
click to toggle source
# File test/unit/state_collection_test.rb, line 61 def test_should_match_if_value_matches assert @states.matches?(@object, nil) end
test_should_not_find_state_for_object_with_unknown_value()
click to toggle source
# File test/unit/state_collection_test.rb, line 79 def test_should_not_find_state_for_object_with_unknown_value @object.state = 'invalid' assert_nil @states.match(@object) end
test_should_not_match_if_value_does_not_match()
click to toggle source
# File test/unit/state_collection_test.rb, line 56 def test_should_not_match_if_value_does_not_match assert !@states.matches?(@object, :parked) assert !@states.matches?(@object, :idling) end
test_should_raise_exception_if_finding_bang_state_for_object_with_unknown_value()
click to toggle source
# File test/unit/state_collection_test.rb, line 84 def test_should_raise_exception_if_finding_bang_state_for_object_with_unknown_value @object.state = 'invalid' exception = assert_raise(ArgumentError) { @states.match!(@object) } assert_equal '"invalid" is not a known state value', exception.message end