class CallbackWithAroundTypeAndBlockTest

Public Instance Methods

setup() click to toggle source
# File test/unit/callback_test.rb, line 510
def setup
  @object = Object.new
  @callbacks = []
end
test_should_call_block_after_before() click to toggle source
# File test/unit/callback_test.rb, line 532
def test_should_call_block_after_before
  callback = StateMachine::Callback.new(:around, lambda {|block| @callbacks << :before; block.call})
  assert callback.call(@object) { @callbacks << :block }
  assert_equal [:before, :block], @callbacks
end
test_should_call_block_before_after() click to toggle source
# File test/unit/callback_test.rb, line 538
def test_should_call_block_before_after
  @callbacks = []
  callback = StateMachine::Callback.new(:around, lambda {|block| block.call; @callbacks << :after})
  assert callback.call(@object) { @callbacks << :block }
  assert_equal [:block, :after], @callbacks
end
test_should_evaluate_after_without_before() click to toggle source
# File test/unit/callback_test.rb, line 521
def test_should_evaluate_after_without_before
  callback = StateMachine::Callback.new(:around, lambda {|*args| block = args.pop; block.call; @args = args})
  assert callback.call(@object)
  assert_equal [@object], @args
end
test_should_evaluate_before_without_after() click to toggle source
# File test/unit/callback_test.rb, line 515
def test_should_evaluate_before_without_after
  callback = StateMachine::Callback.new(:around, lambda {|*args| block = args.pop; @args = args; block.call})
  assert callback.call(@object)
  assert_equal [@object], @args
end
test_should_halt_if_block_halts() click to toggle source
# File test/unit/callback_test.rb, line 545
def test_should_halt_if_block_halts
  callback = StateMachine::Callback.new(:around, lambda {|block| block.call; @callbacks << :after})
  assert_throws(:halt) { callback.call(@object) { throw :halt }  }
  assert_equal [], @callbacks
end
test_should_halt_if_not_yielded() click to toggle source
# File test/unit/callback_test.rb, line 527
def test_should_halt_if_not_yielded
  callback = StateMachine::Callback.new(:around, lambda {|block|})
  assert_throws(:halt) { callback.call(@object) }
end