Sha256: f5ef7d70a320480ca39f0ac19ee5db8ef727a055d72ab6ebf4892ac2c2e0c05b

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

require 'helper'
require 'dyna_mo/module'

class ModulePrependTest < Test::Unit::TestCase
  module P1
    def name
      val = super
      "p1:" + val
    end
  end

  module P2
    def name
      val = super
      "p2:" + val
    end
  end

  class X
    def name
      "x"
    end
  end

  class Y < X
    def name
      "y"
    end
  end

  def test_base
    assert { X.new.name == "x" }
    assert { Y.new.name == "y" }
  end

  def test_normal_prepend
    X.send(:prepend, P1)

    assert { X.new.name == "p1:x" }
    assert X.include?(P1)
    assert X.prepend?(P1)

    assert { Y.new.name == "y" } # not prepend
    assert Y.include?(P1)
    assert (not Y.prepend?(P1))

    Y.send(:prepend, P2)

    assert { Y.new.name == "p2:y" }
    assert Y.include?(P2)
    assert Y.prepend?(P2)
  end

  def test_prepend_duplicated_module
    assert X.prepend?(P1)
    assert (not Y.prepend?(P1))
    assert Y.prepend?(P2)

    assert { Y.new.name == "p2:y" }
    dup_mod = P1.dup

    Y.send(:prepend, dup_mod)

    assert Y.prepend?(dup_mod)
    assert { Y.new.name == "p1:p2:y" }
  end
end


Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dyna_mo-0.0.1 test/test_prepend.rb