class EventWithMultipleTransitionsTest

Public Instance Methods

setup() click to toggle source
# File test/unit/event_test.rb, line 769
def setup
  @klass = Class.new
  @machine = StateMachine::Machine.new(@klass)
  @machine.state :parked, :idling
  
  @machine.events << @event = StateMachine::Event.new(@machine, :ignite)
  @event.transition(:idling => :idling)
  @event.transition(:parked => :idling) # This one should get used
  @event.transition(:parked => :parked)
  
  @object = @klass.new
  @object.state = 'parked'
end
test_should_allow_specific_transition_selection_using_from() click to toggle source
# File test/unit/event_test.rb, line 795
def test_should_allow_specific_transition_selection_using_from
  transition = @event.transition_for(@object, :from => :idling)
  
  assert_not_nil transition
  assert_equal 'idling', transition.from
  assert_equal 'idling', transition.to
  assert_equal :ignite, transition.event
end
test_should_allow_specific_transition_selection_using_to() click to toggle source
# File test/unit/event_test.rb, line 804
def test_should_allow_specific_transition_selection_using_to
  transition = @event.transition_for(@object, :from => :parked, :to => :parked)
  
  assert_not_nil transition
  assert_equal 'parked', transition.from
  assert_equal 'parked', transition.to
  assert_equal :ignite, transition.event
end
test_should_be_able_to_fire() click to toggle source
# File test/unit/event_test.rb, line 783
def test_should_be_able_to_fire
  assert @event.can_fire?(@object)
end
test_should_change_the_current_state() click to toggle source
# File test/unit/event_test.rb, line 822
def test_should_change_the_current_state
  @event.fire(@object)
  assert_equal 'idling', @object.state
end
test_should_fire() click to toggle source
# File test/unit/event_test.rb, line 818
def test_should_fire
  assert @event.fire(@object)
end
test_should_have_a_transition() click to toggle source
# File test/unit/event_test.rb, line 787
def test_should_have_a_transition
  transition = @event.transition_for(@object)
  assert_not_nil transition
  assert_equal 'parked', transition.from
  assert_equal 'idling', transition.to
  assert_equal :ignite, transition.event
end
test_should_not_allow_specific_transition_selection_using_on() click to toggle source
# File test/unit/event_test.rb, line 813
def test_should_not_allow_specific_transition_selection_using_on
  exception = assert_raise(ArgumentError) { @event.transition_for(@object, :on => :park) }
  assert_equal 'Invalid key(s): on', exception.message
end