Sha256: edf3ef21408f5b3c0818d5b5951b2c83864b3ef5ea0ce055cacca533fe0bc41e

Contents?: true

Size: 911 Bytes

Versions: 8

Compression:

Stored size: 911 Bytes

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 '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

8 entries across 8 versions & 1 rubygems

Version Path
virtus-0.5.1 spec/unit/virtus/attribute/class_methods/build_spec.rb
virtus-0.5.0 spec/unit/virtus/attribute/class_methods/build_spec.rb
virtus-0.4.2 spec/unit/virtus/attribute/class_methods/build_spec.rb
virtus-0.4.1 spec/unit/virtus/attribute/class_methods/build_spec.rb
virtus-0.4.0 spec/unit/virtus/attribute/class_methods/build_spec.rb
virtus-0.3.0 spec/unit/virtus/attribute/class_methods/build_spec.rb
virtus-0.2.0 spec/unit/virtus/attribute/class_methods/build_spec.rb
virtus-0.1.0 spec/unit/virtus/attribute/class_methods/build_spec.rb