Sha256: 2fa3dfbbff29d1a95a6908220b543b717046aa42587898d274b1e84fada58a17

Contents?: true

Size: 1.15 KB

Versions: 10

Compression:

Stored size: 1.15 KB

Contents

require 'spec_helper'

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

  let(:described_class) { Class.new(Virtus::Attribute::Collection) }
  let(:object)          { described_class.new(:things) }
  let(:value)           { [ entry ] }
  let(:entry)           { mock('entry') }

  before do
    described_class.primitive ::Array
    value.should_receive(:respond_to?).with(:inject).and_return(respond_to_inject)
  end

  context 'when coerced value responds to #inject' do
    let(:respond_to_inject) { true }

    context 'when the object has not implemented #coerce_and_append_member' do
      specify { expect { subject }.to raise_error(NotImplementedError, "#{object.class}#coerce_and_append_member has not been implemented") }
    end

    context 'when the object has implemented #coerce_and_append_member' do
      before do
        def object.coerce_and_append_member(collection, entry)
          collection << entry
        end
      end

      it { should eql(value) }
    end
  end

  context 'when coerced value does not respond to #inject' do
    let(:respond_to_inject) { false }

    it { should eql(value) }
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

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