Sha256: 8a0234f041766c2ea51c2cd42caf6e6271287ffc1eede1ae6bf3cf5b1e6a2ae2

Contents?: true

Size: 1.42 KB

Versions: 14

Compression:

Stored size: 1.42 KB

Contents

require 'helper'

class Car
  include Transitions

  state_machine do
    state :parked
    state :driving

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

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

  test "should execute the event_fired callback after successfull event execution if it callback is defined" do
    @car.stubs(:event_fired)
    @car.expects(:event_fired).with(:parked, :driving, :start_driving).once

    @car.start_driving!
  end

  test "should not execute the event_fired callback after successfull event execution if it callback is not defined" do
    pend 'Test fails right now although functionality is working as expected'
    # This test fails right now even though it works as expected in the console.
    # The reason for this is, that mocha's `expects` does a little bit more than just set up an expectation,
    # it actually defines this method if it doesn't exist or at least it overwrites respond_to?
    #   @car.respond_to?(:event_fired)
    # returns false before the `expects` call, but true after.
    # Hence, this test fails.
    # Something like
    #   @car.instance_eval { undef :event_fired }
    # doesn't work either, probably because expects just overwrites respond_to?
    # but does not define the method
    # How to fix?
    @car.expects(:event_fired).never
    @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_event_fired_callback.rb
transitions-0.1.13 test/state_transition/test_state_transition_event_fired_callback.rb
transitions-0.1.12 test/state_transition/test_state_transition_event_fired_callback.rb
transitions-0.1.11 test/state_transition/test_state_transition_event_fired_callback.rb
transitions-0.1.10 test/state_transition/test_state_transition_event_fired_callback.rb
transitions-0.1.9 test/state_transition/test_state_transition_event_fired_callback.rb
transitions-0.1.8 test/state_transition/test_state_transition_event_fired_callback.rb
transitions-0.1.7 test/state_transition/test_state_transition_event_fired_callback.rb
transitions-0.1.6 test/state_transition/test_state_transition_event_fired_callback.rb
transitions-0.1.5 test/state_transition/test_state_transition_event_fired_callback.rb
transitions-0.1.4 test/state_transition/test_state_transition_event_fired_callback.rb
transitions-0.1.3 test/state_transition/test_state_transition_event_fired_callback.rb
transitions-0.1.2 test/state_transition/test_state_transition_event_fired_callback.rb
transitions-0.1.1 test/state_transition/test_state_transition_event_fired_callback.rb