Sha256: 21671d499837210843ecf6061baa6d524d322e644d3881b6c6199d4f44a730a4

Contents?: true

Size: 872 Bytes

Versions: 5

Compression:

Stored size: 872 Bytes

Contents

require 'test_helper'

describe MicroFSM do
  let (:fsm) {
    MicroFSM.new(:pending)
            .when(:confirm, pending: :confirmed) { @state = "Confirmed" }
            .when(:reset, confirmed: :pending) { @state = "Pending" }
  }

  def test_executes_callbacks_during_transition
    fsm.trigger(:confirm)
    assert_equal "Confirmed", @state

    fsm.trigger(:reset)
    assert_equal "Pending", @state
  end

  def test_two_callbacks_during_transition
    fsm.when(:confirm, pending: :confirmed) { @state2 = "Confirmed2" }

    fsm.trigger(:confirm)
    assert_equal "Confirmed", @state
    assert_equal "Confirmed2", @state2
  end

  def test_passing_the_event_name_to_the_callbacks
    event_name = nil
    fsm.when(:confirm, pending: :confirmed) do |event|
      event_name = event
    end

    fsm.trigger(:confirm)
    assert_equal :confirm, event_name
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
microfsm-0.1.3 test/callbacks_test.rb
microfsm-0.1.2 test/callbacks_test.rb
microfsm-0.1.1 test/callbacks_test.rb
microfsm-0.1.0 test/callbacks_test.rb
microfsm-0.0.1 test/callbacks_test.rb