Sha256: c800b19c8e1ec843d061fcad887ab949d46ec3abcda9159a27f44b3e02faf942

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

require "test_helper"

class HeritageTest < Minitest::Spec
  module Hello
    def hello
      "Hello!"
    end
  end

  module Ciao
    def ciao
      "Ciao!"
    end
  end

  class A < Representable::Decorator
    include Representable::Hash

    feature Hello

    property :id do
    end
  end

  class B < A
    feature Ciao # does NOT extend id, of course.

    property :id, inherit: true do

    end
  end

  class C < A
    property :id do end # overwrite old :id.
  end

  it "B must inherit Hello! feature from A" do
    B.representable_attrs.get(:id)[:extend].(nil).new(nil).hello.must_equal "Hello!"
  end

  it "B must have Ciao from module (feauture) Ciao" do
    B.representable_attrs.get(:id)[:extend].(nil).new(nil).ciao.must_equal "Ciao!"
  end

  it "C must inherit Hello! feature from A" do
    C.representable_attrs.get(:id)[:extend].(nil).new(nil).hello.must_equal "Hello!"
  end

  module M
    include Representable
    feature Hello
  end

  module N
    include Representable
    include M
    feature Ciao
  end

  let(:obj_extending_N) { Object.new.extend(N) }

  it "obj should inherit from N, and N from M" do
    obj_extending_N.hello.must_equal "Hello!"
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
representable-3.0.4 test/heritage_test.rb