Sha256: 979586f8fdb924864ad64852334e53dd3ce831c8ff2bb7c6a28686020ba6084c

Contents?: true

Size: 1.8 KB

Versions: 14

Compression:

Stored size: 1.8 KB

Contents

require_relative '../../test_helper'

class BranchWithMultipleImplicitRequirementsTest < StateMachinesTest
  def setup
    @object = Object.new
    @branch = StateMachines::Branch.new(parked: :idling, idling: :first_gear, on: :ignite)
  end

  def test_should_create_multiple_state_requirements
    assert_equal 2, @branch.state_requirements.length
  end

  def test_should_not_match_event_as_state_requirement
    refute @branch.matches?(@object, from: :on, to: :ignite)
  end

  def test_should_match_if_from_included_in_any
    assert @branch.matches?(@object, from: :parked)
    assert @branch.matches?(@object, from: :idling)
  end

  def test_should_not_match_if_from_not_included_in_any
    refute @branch.matches?(@object, from: :first_gear)
  end

  def test_should_match_if_to_included_in_any
    assert @branch.matches?(@object, to: :idling)
    assert @branch.matches?(@object, to: :first_gear)
  end

  def test_should_not_match_if_to_not_included_in_any
    refute @branch.matches?(@object, to: :parked)
  end

  def test_should_match_if_all_options_match
    assert @branch.matches?(@object, from: :parked, to: :idling, on: :ignite)
    assert @branch.matches?(@object, from: :idling, to: :first_gear, on: :ignite)
  end

  def test_should_not_match_if_any_options_do_not_match
    refute @branch.matches?(@object, from: :parked, to: :idling, on: :park)
    refute @branch.matches?(@object, from: :parked, to: :first_gear, on: :park)
  end

  def test_should_include_all_known_states
    assert_equal [:first_gear, :idling, :parked], @branch.known_states.sort_by { |state| state.to_s }
  end

  def test_should_not_duplicate_known_statse
    branch = StateMachines::Branch.new(parked: :idling, first_gear: :idling)
    assert_equal [:first_gear, :idling, :parked], branch.known_states.sort_by { |state| state.to_s }
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

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