Sha256: 3571160806407f49e4bfdabd0bec05a2dfe35f7b7ddd5f6d141e2e571bc7d8df
Contents?: true
Size: 1.75 KB
Versions: 5
Compression:
Stored size: 1.75 KB
Contents
require 'spec_helper' module Alf module Types describe Size do describe "===" do it 'should recognize 0' do (Size === 0).should be_true end it 'should recognize any positive integer' do (Size === 10).should be_true end it 'should not recognize negative integers' do (Size === -1).should be_false end it 'should not recognize non integers' do (Size === 10.0).should be_false (Size === "12").should be_false end end # === describe "coerce" do it 'should coerce strings correctly' do Size.coerce("0").should eq(0) Size.coerce("10").should eq(10) end it 'should raise ArgumentError on negative integers' do lambda{ Size.coerce("-1") }.should raise_error(ArgumentError) end it 'should raise ArgumentError on non integers' do lambda{ Size.coerce("hello") }.should raise_error(ArgumentError) end end # coerce describe "from_argv" do it 'should allow an empty array' do Size.from_argv([]).should eq(0) end it 'should use the default value on empty array' do Size.from_argv([], :default => 10).should eq(10) end it 'correctly coerce when non empty' do Size.from_argv(["12"]).should eq(12) end it 'raise an ArgumentError on big array' do lambda{ Size.from_argv(["12", "hello"]) }.should raise_error(ArgumentError) end it 'raise an ArgumentError on non coercable' do lambda{ Size.from_argv(["hello"]) }.should raise_error(ArgumentError) end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems