Sha256: c4179b424b5b76ffb6b8700302d2d8009faa38166914b89c970fd6fbe457864c

Contents?: true

Size: 624 Bytes

Versions: 1

Compression:

Stored size: 624 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 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

1 entries across 1 versions & 1 rubygems

Version Path
virtus-0.5.0 spec/unit/virtus/attribute/embedded_value/from_struct/coerce_spec.rb