Sha256: 5261cdc16b58a25d85fbb0f2e602f6b235606fcc7e221572f865f67e24f1b7ce

Contents?: true

Size: 855 Bytes

Versions: 14

Compression:

Stored size: 855 Bytes

Contents

require 'helper'

class Car
  include Transitions

  state_machine do
    state :parked
    state :driving
    state :switched_off

    event :start_driving do
      transitions :from => :parked, :to => :driving
    end

    event :switch_off_engine do
      transitions :from => :parked, :to => :switched_off
    end
  end
end

class TestStateTransitionEventFailedCallback < Test::Unit::TestCase
  def setup
    @car = Car.new
  end

 test "should execute the event_failed_callback and don't raise error if callback is defined" do
    @car.start_driving
    @car.expects(:event_failed).with(:switch_off_engine)
    @car.switch_off_engine
  end

  test "should just re-raise any error on transition if the event_failed_callback isn't defined" do
    @car.start_driving
    assert_raise(Transitions::InvalidTransition) { @car.switch_off_engine }
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
transitions-0.2.0 test/state_transition/test_state_transition_event_failed_callback.rb
transitions-0.1.13 test/state_transition/test_state_transition_event_failed_callback.rb
transitions-0.1.12 test/state_transition/test_state_transition_event_failed_callback.rb
transitions-0.1.11 test/state_transition/test_state_transition_event_failed_callback.rb
transitions-0.1.10 test/state_transition/test_state_transition_event_failed_callback.rb
transitions-0.1.9 test/state_transition/test_state_transition_event_failed_callback.rb
transitions-0.1.8 test/state_transition/test_state_transition_event_failed_callback.rb
transitions-0.1.7 test/state_transition/test_state_transition_event_failed_callback.rb
transitions-0.1.6 test/state_transition/test_state_transition_event_failed_callback.rb
transitions-0.1.5 test/state_transition/test_state_transition_event_failed_callback.rb
transitions-0.1.4 test/state_transition/test_state_transition_event_failed_callback.rb
transitions-0.1.3 test/state_transition/test_state_transition_event_failed_callback.rb
transitions-0.1.2 test/state_transition/test_state_transition_event_failed_callback.rb
transitions-0.1.1 test/state_transition/test_state_transition_event_failed_callback.rb