Sha256: 7793ad4616ec512e863c3d9e128e264816ca5dd67e77c21af80c4e87f68e3172

Contents?: true

Size: 1.03 KB

Versions: 4

Compression:

Stored size: 1.03 KB

Contents

shared_examples_for 'Attribute#get' do
  subject { attribute.get(instance) }

  let(:model)     { Class.new }
  let(:instance)  { model.new }

  context 'without default value' do
    let(:attribute) { described_class.new(attribute_name) }

    before { attribute.set(instance, value) }

    context "when a non-nil value is set" do
      let(:value) { attribute_value }
      it { should eql(attribute_value) }
    end

    context "when nil is set" do
      let(:value) { nil }
      it { should be(value) }
    end
  end

  context 'with default value' do
    context 'set to proc' do
      let(:attribute) do
        described_class.new(attribute_name, :default => attribute_default_proc)
      end

      let(:evaluated_proc_value) do
        attribute.default.evaluate(attribute)
      end

      it { should == evaluated_proc_value }
    end

    context 'not set to proc' do
      let(:attribute) do
        described_class.new(attribute_name, :default => attribute_default)
      end

      it { should == attribute_default }
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
virtus-0.0.10 spec/unit/shared/attribute/get.rb
virtus-0.0.9 spec/unit/shared/attribute/get.rb
virtus-0.0.8 spec/unit/shared/attribute/get.rb
virtus-0.0.7 spec/unit/shared/attribute/get.rb