Sha256: c02ba67f9a931a266aa9498733c9410f0b51807ec8c53b7b862ed947418574ad

Contents?: true

Size: 722 Bytes

Versions: 6

Compression:

Stored size: 722 Bytes

Contents

require 'spec_helper'

describe Virtus::Attribute::EmbeddedValue::FromOpenStruct, '#coerce' do
  subject { object.coerce(value) }

  let(:primitive) { OpenStruct }

  let(:object) do
    described_class.new(:name, :primitive => primitive)
  end

  context 'when the value is nil' do
    let(:value) { nil }

    it { should be_nil }
  end

  context 'when the value is a primitive instance' do
    let(:value) { primitive.new }

    it { should be(value) }
  end

  context 'when the value is a hash' do
    let(:value)    { Hash[:foo => 'bar'] }
    let(:instance) { mock('instance') }

    before do
      primitive.should_receive(:new).with(value).and_return(instance)
    end

    it { should be(instance) }
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
virtus-0.5.5 spec/unit/virtus/attribute/embedded_value/from_open_struct/coerce_spec.rb
virtus-0.5.4 spec/unit/virtus/attribute/embedded_value/from_open_struct/coerce_spec.rb
virtus-0.5.3 spec/unit/virtus/attribute/embedded_value/from_open_struct/coerce_spec.rb
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/virtus-0.5.2/spec/unit/virtus/attribute/embedded_value/from_open_struct/coerce_spec.rb
virtus-0.5.2 spec/unit/virtus/attribute/embedded_value/from_open_struct/coerce_spec.rb
virtus-0.5.1 spec/unit/virtus/attribute/embedded_value/from_open_struct/coerce_spec.rb