Sha256: 427e84b44fbc277e025f85c01e6492698c3b87fb6f6eeb8d9994a3e19fcfd3fb
Contents?: true
Size: 996 Bytes
Versions: 1
Compression:
Stored size: 996 Bytes
Contents
require 'spec_helper' describe Domain, "coerce" do class Point extend Domain::Scalar.new(:x, :y) coercions do |c| c.coercion(String){|v,_| Point.new(*v.split(',').map(&:to_i)) } c.coercion(Array) {|v,_| Point.new(*v) } end EMPTY = Point.new(0, 0) end let(:point_1_1){ Point.new(1, 1) } let(:point_2_2){ Point.new(2, 2) } it 'should delegate to coercions' do Point.coerce("1, 1").should eq(point_1_1) end it 'raises a TypeError if something goes wrong' do lambda{ Point.coerce(12) }.should raise_error(TypeError, /Can't convert `12`/) end describe "the [] alias" do it 'delegates to coerce when one argument' do Point["1,1"].should eq(point_1_1) end it 'supports Array' do Point[[2, 2]].should eq(point_2_2) end it 'supports Array literals' do Point[2, 2].should eq(point_2_2) end it 'supports empty Array literals' do Point[].should be(Point::EMPTY) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
myrrha-3.0.0.rc4 | spec/ext/domain/test_coerce.rb |