Sha256: 51818cd237822e27202f669229145badf4d108c45b9cab77f8819aff9430f09a
Contents?: true
Size: 904 Bytes
Versions: 4
Compression:
Stored size: 904 Bytes
Contents
require 'moosex' class CoerceTest include MooseX has attribute_ro: { is: :ro, isa: Integer, coerce: lambda {|value| value.to_i }, } has attribute_rw: { is: :rw, isa: Integer, coerce: lambda {|value| value.to_i }, } has attribute_lazy: { is: :lazy, isa: Integer, coerce: lambda {|value| value.to_i }, builder: lambda{|object| "2048" }, } end describe "CoerceTest" do it "should coerce the argument using to_i on constructor" do ct = CoerceTest.new(attribute_ro: "12") ct.attribute_ro.should == 12 end it "should coerce the argument using to_i on constructor" do ct = CoerceTest.new(attribute_rw: "12") ct.attribute_rw.should == 12 end it "should coerce in the setter" do ct = CoerceTest.new ct.attribute_rw= "128" ct.attribute_rw.should == 128 end it "should coerce from builder" do ct = CoerceTest.new ct.attribute_lazy.should == 2048 end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
moosex-0.0.15 | spec/coerce_spec.rb |
moosex-0.0.14 | spec/coerce_spec.rb |
moosex-0.0.13 | spec/coerce_spec.rb |
moosex-0.0.12 | spec/coerce_spec.rb |