class PathWithAvailableTransitionsTest

Public Instance Methods

setup() click to toggle source
# File test/unit/path_test.rb, line 174
def setup
  @klass = Class.new
  @machine = StateMachine::Machine.new(@klass)
  @machine.state :parked, :idling, :first_gear
  @machine.event :ignite
  @machine.event :shift_up do
    transition :idling => :first_gear
  end
  @machine.event :park do
    transition :idling => :parked
  end
  
  @object = @klass.new
  @object.state = 'parked'
  
  @path = StateMachine::Path.new(@object, @machine)
  @path.concat([
    @ignite_transition = StateMachine::Transition.new(@object, @machine, :ignite, :parked, :idling)
  ])
end
test_should_not_be_complete() click to toggle source
# File test/unit/path_test.rb, line 195
def test_should_not_be_complete
  assert !@path.complete?
end
test_should_not_modify_current_path_after_walking() click to toggle source
# File test/unit/path_test.rb, line 215
def test_should_not_modify_current_path_after_walking
  @path.walk {}
  assert_equal [@ignite_transition], @path
end
test_should_not_modify_object_after_walking() click to toggle source
# File test/unit/path_test.rb, line 220
def test_should_not_modify_object_after_walking
  @path.walk {}
  assert_equal 'parked', @object.state
end
test_should_walk_each_available_transition() click to toggle source
# File test/unit/path_test.rb, line 199
def test_should_walk_each_available_transition
  paths = []
  @path.walk {|path| paths << path}
  
  assert_equal [
    [@ignite_transition, StateMachine::Transition.new(@object, @machine, :shift_up, :idling, :first_gear)],
    [@ignite_transition, StateMachine::Transition.new(@object, @machine, :park, :idling, :parked)]
  ], paths
end
test_should_yield_path_instances_when_walking() click to toggle source
# File test/unit/path_test.rb, line 209
def test_should_yield_path_instances_when_walking
  @path.walk do |path|
    assert_instance_of StateMachine::Path, path
  end
end