Sha256: b0706c9c40e07413ef7f5362068ddbff76a9b6be32b22aaf29a1f1c8ffb48603

Contents?: true

Size: 718 Bytes

Versions: 6

Compression:

Stored size: 718 Bytes

Contents

require 'spec_helper'

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

  let(:primitive) { Struct.new(:x, :y) }

  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 an array' do
    let(:value)    { [ 1 ,2 ] }
    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_struct/coerce_spec.rb
virtus-0.5.4 spec/unit/virtus/attribute/embedded_value/from_struct/coerce_spec.rb
virtus-0.5.3 spec/unit/virtus/attribute/embedded_value/from_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_struct/coerce_spec.rb
virtus-0.5.2 spec/unit/virtus/attribute/embedded_value/from_struct/coerce_spec.rb
virtus-0.5.1 spec/unit/virtus/attribute/embedded_value/from_struct/coerce_spec.rb