Sha256: 00869e52348999829fb02f1c088d314a2f65cee189cd4aa56560c3755db975d3

Contents?: true

Size: 1.57 KB

Versions: 14

Compression:

Stored size: 1.57 KB

Contents

class BlockArgsTest < Minitest::Test
  def test_supplying_block_argument_explicitly
    actual = Invokr.invoke(
      method: :block_argument,
      on:     TestMethodBank,
      with:   { album_block: -> { 'farmhouse' } },
    )

    assert_equal 'farmhouse', actual
  end

  def test_supplying_block_argument_implicitly
    actual = Invokr.invoke(
      method: :block_argument,
      on:     TestMethodBank,
      with:   {},
      block:  -> { 'farmhouse' },
    )

    assert_equal 'farmhouse', actual
  end

  def test_failing_to_supply_block_argument
    error = assert_raises Invokr::MissingArgumentsError do
      Invokr.invoke(
        method: :block_argument,
        on:     TestMethodBank,
        with:   {},
      )
    end

    assert_equal(
      "missing required argument(s) `album_block' when invoking method `block_argument' on #<TestMethodBank:0xdeadbeef>",
      error.message,
    )
  end

  def test_supplying_block_argument_implicitly_and_explicitly
    error = assert_raises Invokr::ExtraArgumentsError do
      Invokr.invoke(
        method: :block_argument,
        on:     TestMethodBank,
        with:   { album_block: -> { 'farmhouse' } },
        block:  -> { 'farmhouse' },
      )
    end

    assert_equal(
      "unused argument(s) `album_block' when invoking method `block_argument' on #<TestMethodBank:0xdeadbeef>",
      error.message,
    )
  end

  def test_implicit_block
    actual = Invokr.invoke(
      method: :just_yields,
      on:     TestMethodBank,
      with:   {},
      block:  -> { 'farmhouse' },
    )

    assert_equal 'farmhouse', actual
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
invokr-0.9.7 test/block_args_test.rb
invokr-0.9.6 test/block_args_test.rb
invokr-0.9.5 test/block_args_test.rb
invokr-0.9.4 test/block_args_test.rb
invokr-0.9.3 test/block_args_test.rb
invokr-0.9.2 test/block_args_test.rb
invokr-0.9.1 test/block_args_test.rb
invokr-0.9.0 test/block_args_test.rb
invokr-0.1.0 test/block_args_test.rb
invokr-0.0.6 test/block_args_test.rb
invokr-0.0.5 test/block_args_test.rb
invokr-0.0.4 test/block_args_test.rb
invokr-0.0.2 test/block_args_test.rb
invokr-0.0.1 test/block_args_test.rb