mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Update to ruby/spec@875a09e
This commit is contained in:
parent
a06301b103
commit
5c276e1cc9
1247 changed files with 5316 additions and 5028 deletions
|
@ -1,5 +1,7 @@
|
|||
require_relative '../../spec_helper'
|
||||
|
||||
require 'bigdecimal'
|
||||
|
||||
describe "Integer#coerce" do
|
||||
context "fixnum" do
|
||||
describe "when given a Fixnum" do
|
||||
|
@ -11,7 +13,7 @@ describe "Integer#coerce" do
|
|||
|
||||
describe "when given a String" do
|
||||
it "raises an ArgumentError when trying to coerce with a non-number String" do
|
||||
lambda { 1.coerce(":)") }.should raise_error(ArgumentError)
|
||||
-> { 1.coerce(":)") }.should raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
it "returns an array containing two Floats" do
|
||||
|
@ -21,7 +23,7 @@ describe "Integer#coerce" do
|
|||
end
|
||||
|
||||
it "raises a TypeError when trying to coerce with nil" do
|
||||
lambda { 1.coerce(nil) }.should raise_error(TypeError)
|
||||
-> { 1.coerce(nil) }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "tries to convert the given Object into a Float by using #to_f" do
|
||||
|
@ -29,13 +31,13 @@ describe "Integer#coerce" do
|
|||
2.coerce(obj).should == [1.0, 2.0]
|
||||
|
||||
(obj = mock('0')).should_receive(:to_f).and_return('0')
|
||||
lambda { 2.coerce(obj).should == [1.0, 2.0] }.should raise_error(TypeError)
|
||||
-> { 2.coerce(obj).should == [1.0, 2.0] }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "raises a TypeError when given an Object that does not respond to #to_f" do
|
||||
lambda { 1.coerce(mock('x')) }.should raise_error(TypeError)
|
||||
lambda { 1.coerce(1..4) }.should raise_error(TypeError)
|
||||
lambda { 1.coerce(:test) }.should raise_error(TypeError)
|
||||
-> { 1.coerce(mock('x')) }.should raise_error(TypeError)
|
||||
-> { 1.coerce(1..4) }.should raise_error(TypeError)
|
||||
-> { 1.coerce(:test) }.should raise_error(TypeError)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -62,10 +64,10 @@ describe "Integer#coerce" do
|
|||
it "raises a TypeError when not passed a Fixnum or Bignum" do
|
||||
a = bignum_value
|
||||
|
||||
lambda { a.coerce(nil) }.should raise_error(TypeError)
|
||||
lambda { a.coerce(mock('str')) }.should raise_error(TypeError)
|
||||
lambda { a.coerce(1..4) }.should raise_error(TypeError)
|
||||
lambda { a.coerce(:test) }.should raise_error(TypeError)
|
||||
-> { a.coerce(nil) }.should raise_error(TypeError)
|
||||
-> { a.coerce(mock('str')) }.should raise_error(TypeError)
|
||||
-> { a.coerce(1..4) }.should raise_error(TypeError)
|
||||
-> { a.coerce(:test) }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "coerces both values to Floats and returns [other, self] when passed a Float" do
|
||||
|
@ -88,4 +90,15 @@ describe "Integer#coerce" do
|
|||
ary.should == [1.2, a.to_f]
|
||||
end
|
||||
end
|
||||
|
||||
context "bigdecimal" do
|
||||
it "produces Floats" do
|
||||
x, y = 3.coerce(BigDecimal("3.4"))
|
||||
x.class.should == Float
|
||||
x.should == 3.4
|
||||
y.class.should == Float
|
||||
y.should == 3.0
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue