Sha256: ae2bcfa50009bd3a914682450131dfc80d57e4031eb196b51747a74a7d7d5f46

Contents?: true

Size: 1.65 KB

Versions: 1

Compression:

Stored size: 1.65 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe Attribute, '.coerce' do
  subject { object.coerce(argument) }

  let(:object) { described_class }

  context 'when the argument is an Attribute' do
    let(:argument) { Attribute::Integer.new(:id) }

    it { should equal(argument) }
  end

  context 'when the argument responds to #to_ary' do
    let(:argument) { [ :id, Integer ] }

    it { should be_kind_of(Attribute::Integer) }

    its(:name) { should == :id }
  end

  context 'when the argument does not respond to #to_ary, but does respond to #to_sym' do
    let(:argument) { :id }

    it { should be_kind_of(Attribute::Object) }

    its(:name) { should == :id }
  end

  context 'when the argument does not respond to #to_ary or #to_sym' do
    let(:argument) { Integer }

    specify { expect { subject }.to raise_error(NoMethodError) }
  end
end

describe Attribute::Boolean, '.coerce' do
  subject { object.coerce(argument) }

  let(:object) { described_class }

  context 'when the argument is an Attribute' do
    let(:argument) { Attribute::Integer.new(:id) }

    it { should equal(argument) }
  end

  context 'when the argument responds to #to_ary' do
    let(:argument) { [ :id, Integer ] }

    it { should be_kind_of(Attribute::Integer) }

    its(:name) { should == :id }
  end

  context 'when the argument does not respond to #to_ary, but does respond to #to_sym' do
    let(:argument) { :id }

    it { should be_kind_of(described_class) }

    its(:name) { should == :id }
  end

  context 'when the argument does not respond to #to_ary or #to_sym' do
    let(:argument) { Integer }

    specify { expect { subject }.to raise_error(NoMethodError) }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
veritas-0.0.4 spec/unit/veritas/attribute/class_methods/coerce_spec.rb