Sha256: 072b16f3f6cc47d81bd0cfa568ad2d38b60e9f5ab24ec647c630299a207a426b

Contents?: true

Size: 1.19 KB

Versions: 10

Compression:

Stored size: 1.19 KB

Contents

require 'spec_helper'

describe Virtus::Attribute, '#coerce' do
  subject { object.coerce(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(:value)           { mock('value', :class => value_class)                             }
  let(:value_class)     { stub('value_class')                                              }
  let(:coercer)         { mock('coercer', :public_send => coerced)                         }
  let(:coerced)         { stub('coerced')                                                  }

  before do
    Virtus::Coercion.stub(:[]).with(value_class).and_return(coercer)
  end

  it { should be(coerced) }

  it 'asks for a coercer object' do
    Virtus::Coercion.should_receive(:[]).with(value_class)
    subject
  end

  it 'asks the coercer to coerce the value' do
    coercer.should_receive(:public_send).with(coercion_method, value)
    subject
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

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