Sha256: e341a1b74ed4b11e473e2962c8d8b913bc9dfbf546df03bc938730c6a9fb364d
Contents?: true
Size: 824 Bytes
Versions: 11
Compression:
Stored size: 824 Bytes
Contents
require 'spec_helper' describe 'custom attributes' do before do module Examples class NoisyString < Virtus::Attribute lazy true def coerce(input) input.to_s.upcase end end class RegularExpression < Virtus::Attribute primitive Regexp end class User include Virtus attribute :name, String attribute :scream, NoisyString attribute :expression, RegularExpression end end end subject { Examples::User.new } specify 'allows you to define custom attributes' do regexp = /awesome/ subject.expression = regexp subject.expression.should == regexp end specify 'allows you to define coercion methods' do subject.scream = 'welcome' subject.scream.should == 'WELCOME' end end
Version data entries
11 entries across 11 versions & 1 rubygems