Sha256: 7410905240cabb0439746ae9e55f323aeff7afff144acab008dcd8157191ad75

Contents?: true

Size: 1.97 KB

Versions: 13

Compression:

Stored size: 1.97 KB

Contents

require 'spec_helper'

describe Virtus::Attribute, '#set' do
  subject { object.set(instance, value) }

  let(:object)          { described_class.new(:name, options)                              }
  let(:options)         { { :primitive => primitive, :coercion_method => coercion_method } }
  let(:primitive)       { stub('primitive')                                                }
  let(:coercion_method) { stub('coercion_method')                                          }
  let(:instance)        { Object.new                                                       }
  let(:value)           { stub('value')                                                    }
  let(:coerced)         { stub('coerced')                                                  }

  before do
    object.stub(:coerce).with(value).and_return(coerced)
    object.stub(:set!).with(instance, coerced).and_return(object)
  end

  it { should be(object) }

  it 'coerces the value' do
    object.should_receive(:coerce).with(value)
    subject
  end

  it 'sets the instance variable to the coerced value' do
    object.should_receive(:set!).with(instance, coerced)
    subject
  end
end

describe Virtus::Attribute, '#set!' do
  subject { object.set!(instance, value) }

  let(:object)          { described_class.new(:name, options)                              }
  let(:options)         { { :primitive => primitive, :coercion_method => coercion_method } }
  let(:primitive)       { stub('primitive')                                                }
  let(:coercion_method) { stub('coercion_method')                                          }
  let(:instance)        { Object.new                                                       }
  let(:value)           { stub('value')                                                    }

  it { should be(object) }

  it 'sets the instance variable to the value' do
    instance.instance_variable_get(:@name).should be_nil
    subject
    instance.instance_variable_get(:@name).should be(value)
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
virtus-0.5.5 spec/unit/virtus/attribute/set_spec.rb
virtus-0.5.4 spec/unit/virtus/attribute/set_spec.rb
virtus-0.5.3 spec/unit/virtus/attribute/set_spec.rb
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/virtus-0.5.2/spec/unit/virtus/attribute/set_spec.rb
virtus-0.5.2 spec/unit/virtus/attribute/set_spec.rb
virtus-0.5.1 spec/unit/virtus/attribute/set_spec.rb
virtus-0.5.0 spec/unit/virtus/attribute/set_spec.rb
virtus-0.4.2 spec/unit/virtus/attribute/set_spec.rb
virtus-0.4.1 spec/unit/virtus/attribute/set_spec.rb
virtus-0.4.0 spec/unit/virtus/attribute/set_spec.rb
virtus-0.3.0 spec/unit/virtus/attribute/set_spec.rb
virtus-0.2.0 spec/unit/virtus/attribute/set_spec.rb
virtus-0.1.0 spec/unit/virtus/attribute/set_spec.rb