File: node_collection_with_predefined_contexts_test.rb

package info (click to toggle)
ruby-state-machines 0.100.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,600 kB
  • sloc: ruby: 18,854; sh: 17; makefile: 4
file content (27 lines) | stat: -rw-r--r-- 729 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# frozen_string_literal: true

require 'test_helper'
require 'files/node'

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

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

  def test_should_run_contexts_in_the_order_defined
    @collection << Node.new(:parked)

    assert_equal %i[parked second_parked], @contexts_run
  end

  def test_should_not_run_contexts_if_not_matched
    @collection << Node.new(:idling)

    assert_empty @contexts_run
  end
end