Sha256: 0e4e1571ab48b9befe257504bf8c23f1fd7cd8e24c8f483e92fdfd6f770ea1c1

Contents?: true

Size: 1.12 KB

Versions: 4

Compression:

Stored size: 1.12 KB

Contents

require "helper"

class TestStateTransitionGuardCheck < Test::Unit::TestCase
  args = [:foo, "bar"]

  test "should return true of there is no guard" do
    opts = {:from => "foo", :to => "bar"}
      st = Transitions::StateTransition.new(opts)

    assert st.perform(nil, *args)
  end

  test "should call the method on the object if guard is a symbol" do
    opts = {:from => "foo", :to => "bar", :guard => :test_guard}
    st = Transitions::StateTransition.new(opts)

    obj = stub
    obj.expects(:test_guard).with(*args)

    st.perform(obj, *args)
  end

  test "should call the method on the object if guard is a string" do
    opts = {:from => "foo", :to => "bar", :guard => "test_guard"}
    st = Transitions::StateTransition.new(opts)

    obj = stub
    obj.expects(:test_guard).with(*args)

    st.perform(obj, *args)
  end

  test "should call the proc passing the object if the guard is a proc" do
    opts = {:from => "foo", :to => "bar", :guard => Proc.new {|o, *args| o.test_guard(*args)}}
    st = Transitions::StateTransition.new(opts)

    obj = stub
    obj.expects(:test_guard).with(*args)

    st.perform(obj, *args)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
transitions-0.1.9 test/state_transition/test_state_transition_guard_check.rb
transitions-0.1.8 test/state_transition/test_state_transition_guard_check.rb
transitions-0.1.7 test/state_transition/test_state_transition_guard_check.rb
transitions-0.1.6 test/state_transition/test_state_transition_guard_check.rb