summaryrefslogtreecommitdiff
path: root/spec/ruby/library/bigdecimal/to_i_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/library/bigdecimal/to_i_spec.rb')
-rw-r--r--spec/ruby/library/bigdecimal/to_i_spec.rb14
1 files changed, 12 insertions, 2 deletions
diff --git a/spec/ruby/library/bigdecimal/to_i_spec.rb b/spec/ruby/library/bigdecimal/to_i_spec.rb
index 09481fce15..b6d9e43e57 100644
--- a/spec/ruby/library/bigdecimal/to_i_spec.rb
+++ b/spec/ruby/library/bigdecimal/to_i_spec.rb
@@ -1,7 +1,17 @@
require_relative '../../spec_helper'
-require_relative 'shared/to_int'
require 'bigdecimal'
describe "BigDecimal#to_i" do
- it_behaves_like :bigdecimal_to_int, :to_i
+ it "raises FloatDomainError if BigDecimal is infinity or NaN" do
+ -> { BigDecimal("Infinity").to_i }.should.raise(FloatDomainError)
+ -> { BigDecimal("NaN").to_i }.should.raise(FloatDomainError)
+ end
+
+ it "returns Integer otherwise" do
+ BigDecimal("3E-20001").to_i.should == 0
+ BigDecimal("2E4000").to_i.should == 2 * 10 ** 4000
+ BigDecimal("2").to_i.should == 2
+ BigDecimal("2E10").to_i.should == 20000000000
+ BigDecimal("3.14159").to_i.should == 3
+ end
end