Sha256: 3597c558994149a48d88d97116b496877b3461b542ff5d064f6d723e6394e2bb

Contents?: true

Size: 970 Bytes

Versions: 14

Compression:

Stored size: 970 Bytes

Contents

require_relative '../../test_helper'

class CallbackWithBoundMethodAndArgumentsTest < StateMachinesTest
  def setup
    @object = Object.new
  end

  def test_should_include_single_argument_if_specified
    context = nil
    callback = StateMachines::Callback.new(:before, do: lambda { |arg1| context = [arg1] }, bind_to_object: true)
    callback.call(@object, {}, 1)
    assert_equal [1], context
  end

  def test_should_include_multiple_arguments_if_specified
    context = nil
    callback = StateMachines::Callback.new(:before, do: lambda { |arg1, arg2, arg3| context = [arg1, arg2, arg3] }, bind_to_object: true)
    callback.call(@object, {}, 1, 2, 3)
    assert_equal [1, 2, 3], context
  end

  def test_should_include_arguments_if_splat_used
    context = nil
    callback = StateMachines::Callback.new(:before, do: lambda { |*args| context = args }, bind_to_object: true)
    callback.call(@object, {}, 1, 2, 3)
    assert_equal [1, 2, 3], context
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

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