All Downloads are FREE. Search and download functionalities are using the official Maven repository.

gems.virtus-1.0.5.spec.integration.required_attributes_spec.rb Maven / Gradle / Ivy

The newest version!
require 'spec_helper'

describe 'Using required attributes' do
  before do
    module Examples
      class User
        include Virtus.model(:strict => true)

        attribute :name, String
        attribute :age,  Integer, :required => false
      end
    end
  end

  it 'raises coercion error when required attribute is nil' do
    expect { Examples::User.new(:name => nil) }.to raise_error(Virtus::CoercionError, "Failed to coerce attribute `name' from nil into String")
  end

  it 'does not raise coercion error when not required attribute is nil' do
    user = Examples::User.new(:name => 'Jane', :age => nil)

    expect(user.name).to eql('Jane')
    expect(user.age).to be(nil)
  end
end




© 2015 - 2024 Weber Informatics LLC | Privacy Policy