Sha256: ebb180d5643376312f94d960a2712cc956782f75593a64a032b92dbada7668b5

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

require_relative '../../test_helper'
DuckPuncher.punch! Object

class ObjectTest < MiniTest::Test
  def setup
    @animal = Animal.new
    @dog = Dog.new
    @kaia = Kaia.new
  end

  def teardown
    DuckPuncher.deregister Animal, Dog, Kaia
  end

  def test_clone!
    cloned = @dog.clone!
    assert_equal cloned.class, @dog.class
    refute_equal cloned, @dog
  end

  def test_punch_with_a_core_duck
    assert [].punch.respond_to?(:m)
  end

  def test_punch_on_a_custom_duck
    DuckPuncher.register Animal, CustomPunch2
    assert @animal.punch.respond_to?(:quack)
  end

  def test_punch_with_multiple_custom_duck
    DuckPuncher.register Animal, CustomPunch2
    DuckPuncher.register Animal, CustomPunch3
    assert @animal.punch.respond_to?(:wobble)
  end

  def test_punch_call_stack
    Animal.send(:define_method, :foo) { quack }
    Animal.send(:define_method, :quack) { 'foo' }
    assert_equal 'foo', @animal.foo
    DuckPuncher.register Animal, CustomPunch2
    @animal.punch!
    assert_equal 'quack', @animal.foo
  end

  def test_punch_on_ancestor_only
    DuckPuncher.register Dog, CustomPunch2
    assert_respond_to @dog.punch, :quack
  end

  def test_punch_includes_all_ancestors
    DuckPuncher.register Animal, CustomPunch2
    DuckPuncher.register Dog, CustomPunch
    DuckPuncher.register Kaia, CustomPunch3
    @kaia = Kaia.new
    @kaia.punch!
    assert_respond_to @kaia, :wobble
    assert_respond_to @kaia, :talk
    assert_respond_to @kaia, :quack
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
duck_puncher-4.0.0 test/lib/duck_puncher/object_test.rb