Sha256: 997a614cf0f0a3159876b1f29a2a2a73e13220d8f217eb6b883e30360a3f3f22

Contents?: true

Size: 1.27 KB

Versions: 14

Compression:

Stored size: 1.27 KB

Contents

require_relative '../../test_helper'
require_relative '../../files/node'

class NodeCollectionAfterBeingCopiedTest < StateMachinesTest
  def setup
    machine = StateMachines::Machine.new(Class.new)
    @collection = StateMachines::NodeCollection.new(machine)
    @collection << @parked = Node.new(:parked)

    @contexts_run = contexts_run = []
    @collection.context([:parked]) { contexts_run << :parked }
    @contexts_run.clear

    @copied_collection = @collection.dup
    @copied_collection << @idling = Node.new(:idling)
    @copied_collection.context([:first_gear]) { contexts_run << :first_gear }
  end

  def test_should_not_modify_the_original_list
    assert_equal 1, @collection.length
    assert_equal 2, @copied_collection.length
  end

  def test_should_not_modify_the_indices
    assert_nil @collection[:idling]
    assert_equal @idling, @copied_collection[:idling]
  end

  def test_should_copy_each_node
    refute_same @parked, @copied_collection[:parked]
  end

  def test_should_not_run_contexts
    assert_equal [], @contexts_run
  end

  def test_should_not_modify_contexts
    @collection << Node.new(:first_gear)
    assert_equal [], @contexts_run
  end

  def test_should_copy_contexts
    @copied_collection << Node.new(:parked)
    refute @contexts_run.empty?
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

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