Sha256: ca40f235b215dba771c5be9a1c62a52213f9aea71f336f564866bf450a8acad6

Contents?: true

Size: 1.15 KB

Versions: 14

Compression:

Stored size: 1.15 KB

Contents

require 'helper'

class DrivingInstructor
  def self.applause!
  end
end

class DrivingSchoolCar
  include Transitions

  state_machine do
    state :parked
    state :running
    state :driving
    state :switched_off

    event :start_driving, :success => lambda { |car| DrivingInstructor.applause! } do
      transitions :from => :parked, :to => :driving, :on_transition => [:start_engine, :loosen_handbrake, :push_gas_pedal]
    end

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

  %w!start_engine loosen_handbrake push_gas_pedal!.each do |m|
    define_method(m){}
  end
end

class TestStateTransitionSuccessCallback < Test::Unit::TestCase
  def setup
    @car = DrivingSchoolCar.new
  end

  test "should execute the success callback after successfull event execution" do
    DrivingInstructor.expects(:applause!)

    @car.start_driving!
  end

  test "should not execute the success callback after event execution failed" do
    DrivingInstructor.expects(:applause!).never

    @car.stubs(:event_failed)
    @car.expects(:loosen_handbrake).raises("Drive with handbrake fail!")
    @car.start_driving!
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

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