Sha256: 948564861b6c3fbc3b0e0f883ef2cf0764606045fd5514d9cba90227f4f12cb7

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

require 'spec_helper'
require 'virtus'

class DummyPost
  include Virtus.model

  attribute :title, String
  attribute :body, String
  attribute :comments, Array[String]
  attribute :greeting, String, default: 'Hello!'
  attribute :default_lambda, String, default: ->(_, _) { 'Wow!' }
  attribute :customs, String, default: :custom_default_via_method
  attribute :some_required, String, default: 'FooBar', required: true

  def custom_default_via_method
    'Foo!'
  end

end

describe ::DummyPost do
  it { is_expected.to have_attribute(:title) }
  it { is_expected.to have_attribute(:body).of_type(String) }
  it { is_expected.to have_attribute(:comments).of_type(Array[String]) }
  it { is_expected.to have_attribute(:greeting).of_type(String).with_default('Hello!') }
  it { is_expected.to have_attribute(:default_lambda).of_type(String).with_default('Wow!') }
  it { is_expected.to have_attribute(:customs).of_type(String).with_default('Foo!') }
  it { is_expected.to have_attribute(:some_required).of_type(String).with_default('FooBar').with_required(true) }
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rspec_virtus-1.1.0 spec/acceptance/rspec_virtus_spec.rb