Sha256: 2b01262ea7a475b8f7d1fcf328a2babfa8ac8e44884566c44b61c277346de054

Contents?: true

Size: 1020 Bytes

Versions: 1

Compression:

Stored size: 1020 Bytes

Contents

require 'inheritable_attr'

class Base
  inheritable_attr :numbers, default: []
  inheritable_attr :letters
end

class Sub < Base

end

describe InheritableAttr do
  subject { Base }

  its(:numbers) { should == [] }
  its(:letters) { should be_nil }
  its('new.numbers') { should == [] }
  its('new.letters') { should be_nil }

  its(:numbers) { should_not equal subject.new.numbers }

  context "with a subclass" do
    before do
      Base.numbers = [1, 2, 3]
      Base.letters = %w(a b c)
    end

    subject { Sub }

    # Objects should be cloned
    its(:numbers) { should_not equal Base.numbers }
    its(:letters) { should_not equal Base.letters }

    its(:numbers) { should == [1, 2, 3] }
    its(:letters) { should == %w(a b c) }

    context "when changing subclass values" do
      subject { Sub.new }
      before { subject.numbers << 4 }

      its(:numbers) { should == [1, 2, 3, 4] }

      it "should not affect the superclass" do
        Base.numbers.should == [1, 2, 3]
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
inheritable_attr-1.0.0 spec/inheritable_attr_spec.rb