Sha256: 5b4ccb9c52ce451a6cd29e8d25b15eabbc6a96c4bfe88b647ca59261472f1a7e

Contents?: true

Size: 1.78 KB

Versions: 14

Compression:

Stored size: 1.78 KB

Contents

require_relative '../../test_helper'

class EventWithMultipleTransitionsTest < StateMachinesTest
  def setup
    @klass = Class.new
    @machine = StateMachines::Machine.new(@klass)
    @machine.state :parked, :idling

    @machine.events << @event = StateMachines::Event.new(@machine, :ignite)
    @event.transition(idling: :idling)
    @event.transition(parked: :idling)
    @event.transition(parked: :parked)

    @object = @klass.new
    @object.state = 'parked'
  end

  def test_should_be_able_to_fire
    assert @event.can_fire?(@object)
  end

  def test_should_have_a_transition
    transition = @event.transition_for(@object)
    refute_nil transition
    assert_equal 'parked', transition.from
    assert_equal 'idling', transition.to
    assert_equal :ignite, transition.event
  end

  def test_should_allow_specific_transition_selection_using_from
    transition = @event.transition_for(@object, from: :idling)

    refute_nil transition
    assert_equal 'idling', transition.from
    assert_equal 'idling', transition.to
    assert_equal :ignite, transition.event
  end

  def test_should_allow_specific_transition_selection_using_to
    transition = @event.transition_for(@object, from: :parked, to: :parked)

    refute_nil transition
    assert_equal 'parked', transition.from
    assert_equal 'parked', transition.to
    assert_equal :ignite, transition.event
  end

  def test_should_not_allow_specific_transition_selection_using_on
    exception = assert_raises(ArgumentError) { @event.transition_for(@object, on: :park) }
    assert_equal 'Unknown key: :on. Valid keys are: :from, :to, :guard', exception.message
  end

  def test_should_fire
    assert @event.fire(@object)
  end

  def test_should_change_the_current_state
    @event.fire(@object)
    assert_equal 'idling', @object.state
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
state_machines-0.5.0 test/unit/event/event_with_multiple_transitions_test.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/state_machines-0.2.2/test/unit/event/event_with_multiple_transitions_test.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/state_machines-0.2.2/test/unit/event/event_with_multiple_transitions_test.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/state_machines-0.2.2/test/unit/event/event_with_multiple_transitions_test.rb
state_machines-0.4.0 test/unit/event/event_with_multiple_transitions_test.rb
state_machines-0.3.0 test/unit/event/event_with_multiple_transitions_test.rb
state_machines-0.2.2 test/unit/event/event_with_multiple_transitions_test.rb
state_machines-0.2.1 test/unit/event/event_with_multiple_transitions_test.rb
state_machines-0.2.0 test/unit/event/event_with_multiple_transitions_test.rb
state_machines-0.1.4 test/unit/event/event_with_multiple_transitions_test.rb
state_machines-0.1.3 test/unit/event/event_with_multiple_transitions_test.rb
state_machines-0.1.2 test/unit/event/event_with_multiple_transitions_test.rb
state_machines-0.1.1 test/unit/event/event_with_multiple_transitions_test.rb
state_machines-0.1.0 test/unit/event/event_with_multiple_transitions_test.rb