Sha256: f0e1efebf0d4559028e75aa92ce9eee832f84e01d5ea818ae06de33b05127ca8

Contents?: true

Size: 1.5 KB

Versions: 52

Compression:

Stored size: 1.5 KB

Contents

require 'test_helper'

class HooksTest < Test::Unit::TestCase
  context "Hooks.define_hook" do
    setup do
      @klass = Class.new(Object) do
        extend Hooks::InheritableAttribute
      end

      @mum = @klass.new
      @klass.inheritable_attr :drinks
    end

    should "provide a reader with empty inherited attributes, already" do
      assert_equal nil, @klass.drinks
    end

    should "provide a reader with empty inherited attributes in a derived class" do
      assert_equal nil, Class.new(@klass).drinks
      #@klass.drinks = true
      #Class.new(@klass).drinks # TODO: crashes.
    end

    should "provide an attribute copy in subclasses" do
      @klass.drinks = []
      assert @klass.drinks.object_id != Class.new(@klass).drinks.object_id
    end

    should "provide a writer" do
      @klass.drinks = [:cabernet]
      assert_equal [:cabernet], @klass.drinks
    end

    should "inherit attributes" do
      @klass.drinks = [:cabernet]

      subklass_a = Class.new(@klass)
      subklass_a.drinks << :becks

      subklass_b = Class.new(@klass)

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

    should "not inherit attributes if we set explicitely" do
      @klass.drinks = [:cabernet]
      subklass = Class.new(@klass)

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

Version data entries

52 entries across 52 versions & 2 rubygems

Version Path
middleman-core-3.0.13 lib/middleman-core/vendor/hooks-0.2.0/test/inheritable_attribute_test.rb
middleman-core-x86-mingw32-3.0.12 lib/middleman-core/vendor/hooks-0.2.0/test/inheritable_attribute_test.rb
middleman-core-3.0.12 lib/middleman-core/vendor/hooks-0.2.0/test/inheritable_attribute_test.rb
middleman-core-x86-mingw32-3.0.12.pre.1 lib/middleman-core/vendor/hooks-0.2.0/test/inheritable_attribute_test.rb
middleman-core-3.0.12.pre.1 lib/middleman-core/vendor/hooks-0.2.0/test/inheritable_attribute_test.rb
middleman-core-x86-mingw32-3.0.11 lib/middleman-core/vendor/hooks-0.2.0/test/inheritable_attribute_test.rb
middleman-core-3.0.11 lib/middleman-core/vendor/hooks-0.2.0/test/inheritable_attribute_test.rb
middleman-core-x86-mingw32-3.0.10 lib/middleman-core/vendor/hooks-0.2.0/test/inheritable_attribute_test.rb
middleman-core-x86-mingw32-3.0.10.pre.1 lib/middleman-core/vendor/hooks-0.2.0/test/inheritable_attribute_test.rb
middleman-core-3.0.10.pre.1 lib/middleman-core/vendor/hooks-0.2.0/test/inheritable_attribute_test.rb
middleman-core-x86-mingw32-3.0.9 lib/middleman-core/vendor/hooks-0.2.0/test/inheritable_attribute_test.rb
middleman-core-3.0.9 lib/middleman-core/vendor/hooks-0.2.0/test/inheritable_attribute_test.rb
middleman-core-x86-mingw32-3.0.8 lib/middleman-core/vendor/hooks-0.2.0/test/inheritable_attribute_test.rb
middleman-core-3.0.8 lib/middleman-core/vendor/hooks-0.2.0/test/inheritable_attribute_test.rb
middleman-core-x86-mingw32-3.0.8.pre.2 lib/middleman-core/vendor/hooks-0.2.0/test/inheritable_attribute_test.rb
middleman-core-3.0.8.pre.2 lib/middleman-core/vendor/hooks-0.2.0/test/inheritable_attribute_test.rb
middleman-core-x86-mingw32-3.0.8.pre.1 lib/middleman-core/vendor/hooks-0.2.0/test/inheritable_attribute_test.rb
middleman-core-3.0.8.pre.1 lib/middleman-core/vendor/hooks-0.2.0/test/inheritable_attribute_test.rb
middleman-core-x86-mingw32-3.0.7 lib/middleman-core/vendor/hooks-0.2.0/test/inheritable_attribute_test.rb
middleman-core-3.0.7 lib/middleman-core/vendor/hooks-0.2.0/test/inheritable_attribute_test.rb