Sha256: b78d9bb1b11407b42fdf8a7812bb5f0727d3b7d9ec7560d8ed77e318b8d1c793

Contents?: true

Size: 1.45 KB

Versions: 2

Compression:

Stored size: 1.45 KB

Contents

shared_examples_for 'Attribute.accept_options' do
  let(:sub_attribute) { Class.new(described_class) }
  let(:new_option)    { :width }

  specify { described_class.should respond_to(:accept_options) }

  before :all do
    described_class.accepted_options.should_not include(new_option)
    described_class.accept_options(new_option)
  end

  it "sets new accepted options on itself" do
    described_class.accepted_options.should include(new_option)
  end

  it "sets new accepted option on its descendants" do
    sub_attribute.accepted_options.should include(new_option)
  end

  it "creates option accessors" do
    described_class.should respond_to(new_option)
  end

  it "creates option accessors on descendants" do
    sub_attribute.should respond_to(new_option)
  end

  context 'with default option value' do
    let(:option) { :height }
    let(:value)  { 10 }

    before :all do
      sub_attribute.accept_options(option)
      sub_attribute.height(value)
    end

    context "when new attribute is created" do
      subject { sub_attribute.new(attribute_name) }

      it "sets the default value" do
        subject.options[option].should eql(value)
      end
    end

    context "when new attribute is created and overrides option's default value" do
      let(:new_value) { 11 }

      subject { sub_attribute.new(attribute_name, option => new_value) }

      it "sets the new value" do
        subject.options[option].should eql(new_value)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
virtus-0.0.5 spec/unit/shared/attribute/accept_options.rb
virtus-0.0.4 spec/unit/shared/attribute/accept_options.rb