Skip to content

Commit

Permalink
Add spec for Virtus::Attribute#set
Browse files Browse the repository at this point in the history
  • Loading branch information
dkubb committed Jan 22, 2012
1 parent 9cff64b commit bb9ab91
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
1 change: 0 additions & 1 deletion TODO
@@ -1,6 +1,5 @@
* Add missing specs:
* Add spec file spec/unit/virtus/attribute/coercion_method_spec.rb for Virtus::Attribute#coercion_method
* Add spec file spec/unit/virtus/attribute/set_spec.rb for Virtus::Attribute#set
* Add spec file spec/unit/virtus/attribute/get_spec.rb for Virtus::Attribute#get!
* Add spec file spec/unit/virtus/attribute/define_writer_method_spec.rb for Virtus::Attribute#define_writer_method
* Add spec file spec/unit/virtus/attribute/name_spec.rb for Virtus::Attribute#name
Expand Down
29 changes: 29 additions & 0 deletions spec/unit/virtus/attribute/set_spec.rb
@@ -1,5 +1,34 @@
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) }

Expand Down

0 comments on commit bb9ab91

Please sign in to comment.