Sha256: 27845c998639cb426cf7d78556f778ff4147598fff512625a16fe844b2dbada9

Contents?: true

Size: 1.56 KB

Versions: 20

Compression:

Stored size: 1.56 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

20 entries across 20 versions & 3 rubygems

Version Path
hooks-0.2.2 test/inheritable_attribute_test.rb
hooks-0.2.1 test/inheritable_attribute_test.rb
middleman-core-3.0.0 lib/middleman-core/vendor/hooks-0.2.0/test/inheritable_attribute_test.rb
middleman-core-3.0.0.rc.4 lib/middleman-core/vendor/hooks-0.2.0/test/inheritable_attribute_test.rb
middleman-core-3.0.0.rc.3 lib/middleman-core/vendor/hooks-0.2.0/test/inheritable_attribute_test.rb
middleman-core-3.0.0.rc.2 lib/middleman-core/vendor/hooks-0.2.0/test/inheritable_attribute_test.rb
middleman-core-3.0.0.rc.1 lib/middleman-core/vendor/hooks-0.2.0/test/inheritable_attribute_test.rb
middleman-core-3.0.0.beta.3 lib/middleman-core/vendor/hooks-0.2.0/test/inheritable_attribute_test.rb
middleman-core-3.0.0.beta.2 lib/middleman-core/vendor/hooks-0.2.0/test/inheritable_attribute_test.rb
middleman-core-3.0.0.beta.1 lib/middleman-core/vendor/hooks-0.2.0/test/inheritable_attribute_test.rb
middleman-core-3.0.0.alpha.9 lib/middleman-core/vendor/hooks-0.2.0/test/inheritable_attribute_test.rb
middleman-core-3.0.0.alpha.8 lib/middleman-core/vendor/hooks-0.2.0/test/inheritable_attribute_test.rb
middleman-core-3.0.0.alpha.7 lib/middleman-core/vendor/hooks-0.2.0/test/inheritable_attribute_test.rb
middleman-3.0.0.alpha.6 lib/middleman/vendor/hooks-0.2.0/test/inheritable_attribute_test.rb
middleman-3.0.0.alpha.5 lib/middleman/vendor/hooks-0.2.0/test/inheritable_attribute_test.rb
middleman-3.0.0.alpha.4 lib/middleman/vendor/hooks-0.2.0/test/inheritable_attribute_test.rb
middleman-3.0.0.alpha.3 lib/middleman/vendor/hooks-0.2.0/test/inheritable_attribute_test.rb
middleman-3.0.0.alpha.2 lib/middleman/vendor/hooks-0.2.0/test/inheritable_attribute_test.rb
hooks-0.2.0 test/inheritable_attribute_test.rb
hooks-0.1.4 test/inheritable_attribute_test.rb