Sha256: 86022559358b537d05a2c1185c6c3e0aa0be921d856a31c402f2c3af66124759

Contents?: true

Size: 1.5 KB

Versions: 9

Compression:

Stored size: 1.5 KB

Contents

require 'test_helper'
require "uber/inheritable_attr"

class InheritableAttrTest < MiniTest::Spec
  describe "::inheritable_attr" do
    subject {
      Class.new(Object) do
        extend Uber::InheritableAttribute
        inheritable_attr :drinks
      end
    }

    it "provides a reader with empty inherited attributes, already" do
      assert_equal nil, subject.drinks
    end

    it "provides a reader with empty inherited attributes in a derived class" do
      assert_equal nil, Class.new(subject).drinks
      #subject.drinks = true
      #Class.new(subject).drinks # TODO: crashes.
    end

    it "provides an attribute copy in subclasses" do
      subject.drinks = []
      assert subject.drinks.object_id != Class.new(subject).drinks.object_id
    end

    it "provides a writer" do
      subject.drinks = [:cabernet]
      assert_equal [:cabernet], subject.drinks
    end

    it "inherits attributes" do
      subject.drinks = [:cabernet]

      subklass_a = Class.new(subject)
      subklass_a.drinks << :becks

      subklass_b = Class.new(subject)

      assert_equal [:cabernet],         subject.drinks
      assert_equal [:cabernet, :becks], subklass_a.drinks
      assert_equal [:cabernet],         subklass_b.drinks
    end

    it "does not inherit attributes if we set explicitely" do
      subject.drinks = [:cabernet]
      subklass = Class.new(subject)

      subklass.drinks = [:merlot] # we only want merlot explicitely.
      assert_equal [:merlot], subklass.drinks # no :cabernet, here
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
uber-0.0.10 test/inheritable_attr_test.rb
uber-0.0.9 test/inheritable_attr_test.rb
uber-0.0.8 test/inheritable_attr_test.rb
uber-0.0.7 test/inheritable_attr_test.rb
uber-0.0.6 test/inheritable_attr_test.rb
uber-0.0.5 test/inheritable_attr_test.rb
uber-0.0.4 test/inheritable_attr_test.rb
uber-0.0.3 test/inheritable_attr_test.rb
uber-0.0.2 test/inheritable_attr_test.rb