Sha256: 0f37089b9d7effc21b00a025170bedaf3ea9f85cf3ac3a8190f44da11cc2ff4f

Contents?: true

Size: 1.12 KB

Versions: 5

Compression:

Stored size: 1.12 KB

Contents

require 'spec_helper'

describe Virtus::Attribute, '.build' do
  let(:object) { described_class }
  let(:name)   { :name           }
  let(:type)   { String          }

  context 'without options' do
    subject { object.build(name, type) }

    it { should be_instance_of(Virtus::Attribute::String) }

    its(:name) { should be(name) }

    its(:options) { should == Virtus::Attribute::String.options }
  end

  context 'with options' do
    subject { object.build(name, type, options) }

    let(:options) { {} }

    it { should be_instance_of(Virtus::Attribute::String) }

    its(:name) { should be(name) }

    its(:options) { should == Virtus::Attribute::String.options }
  end

  context 'without a type' do
    subject { object.build(name) }

    it { should be_instance_of(Virtus::Attribute::Object) }

    its(:name) { should be(name) }

    its(:options) { should == Virtus::Attribute::Object.options }
  end

  context 'with an invalid type' do
    subject { object.build(name, type) }

    let(:type) { 'test' }

    specify { expect { subject }.to raise_error(ArgumentError, '"test" does not map to an attribute type') }
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
virtus-0.5.5 spec/unit/virtus/attribute/class_methods/build_spec.rb
virtus-0.5.4 spec/unit/virtus/attribute/class_methods/build_spec.rb
virtus-0.5.3 spec/unit/virtus/attribute/class_methods/build_spec.rb
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/virtus-0.5.2/spec/unit/virtus/attribute/class_methods/build_spec.rb
virtus-0.5.2 spec/unit/virtus/attribute/class_methods/build_spec.rb