summaryrefslogtreecommitdiff
path: root/spec/ruby/shared
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-28 15:15:48 +0000
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-28 15:15:48 +0000
commit8c5b60eb22d6d661e87992a65d54e3a5bc0aeed4 (patch)
tree7905b284cb5b3d62c17ad8a939e339621a498a2c /spec/ruby/shared
parent6530b14cee76e2512424d225e64d3c61dd1f6511 (diff)
Update to ruby/spec@a6b8805
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60525 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/shared')
-rw-r--r--spec/ruby/shared/fiber/resume.rb12
-rw-r--r--spec/ruby/shared/rational/minus.rb6
-rw-r--r--spec/ruby/shared/rational/plus.rb6
-rw-r--r--spec/ruby/shared/rational/round.rb25
4 files changed, 37 insertions, 12 deletions
diff --git a/spec/ruby/shared/fiber/resume.rb b/spec/ruby/shared/fiber/resume.rb
index a680839a4b..058ef4e15a 100644
--- a/spec/ruby/shared/fiber/resume.rb
+++ b/spec/ruby/shared/fiber/resume.rb
@@ -10,13 +10,13 @@ describe :fiber_resume, shared: true do
end
it "raises a FiberError if invoked from a different Thread" do
- fiber = Fiber.new { }
- lambda do
- Thread.new do
+ fiber = Fiber.new { 42 }
+ Thread.new do
+ -> {
fiber.resume
- end.join
- end.should raise_error(FiberError)
- fiber.resume
+ }.should raise_error(FiberError)
+ end.join
+ fiber.resume.should == 42
end
it "passes control to the beginning of the block on first invocation" do
diff --git a/spec/ruby/shared/rational/minus.rb b/spec/ruby/shared/rational/minus.rb
index 01c743be72..e23430111e 100644
--- a/spec/ruby/shared/rational/minus.rb
+++ b/spec/ruby/shared/rational/minus.rb
@@ -1,7 +1,7 @@
require File.expand_path('../../../spec_helper', __FILE__)
describe :rational_minus_rat, shared: true do
- it "returns the result of substracting other from self as a Rational" do
+ it "returns the result of subtracting other from self as a Rational" do
(Rational(3, 4) - Rational(0, 1)).should eql(Rational(3, 4))
(Rational(3, 4) - Rational(1, 4)).should eql(Rational(1, 2))
@@ -10,14 +10,14 @@ describe :rational_minus_rat, shared: true do
end
describe :rational_minus_int, shared: true do
- it "returns the result of substracting other from self as a Rational" do
+ it "returns the result of subtracting other from self as a Rational" do
(Rational(3, 4) - 1).should eql(Rational(-1, 4))
(Rational(3, 4) - 2).should eql(Rational(-5, 4))
end
end
describe :rational_minus_float, shared: true do
- it "returns the result of substracting other from self as a Float" do
+ it "returns the result of subtracting other from self as a Float" do
(Rational(3, 4) - 0.2).should eql(0.55)
(Rational(3, 4) - 2.5).should eql(-1.75)
end
diff --git a/spec/ruby/shared/rational/plus.rb b/spec/ruby/shared/rational/plus.rb
index d078a41425..e37c757c13 100644
--- a/spec/ruby/shared/rational/plus.rb
+++ b/spec/ruby/shared/rational/plus.rb
@@ -1,7 +1,7 @@
require File.expand_path('../../../spec_helper', __FILE__)
describe :rational_plus_rat, shared: true do
- it "returns the result of substracting other from self as a Rational" do
+ it "returns the result of subtracting other from self as a Rational" do
(Rational(3, 4) + Rational(0, 1)).should eql(Rational(3, 4))
(Rational(3, 4) + Rational(1, 4)).should eql(Rational(1, 1))
@@ -10,14 +10,14 @@ describe :rational_plus_rat, shared: true do
end
describe :rational_plus_int, shared: true do
- it "returns the result of substracting other from self as a Rational" do
+ it "returns the result of subtracting other from self as a Rational" do
(Rational(3, 4) + 1).should eql(Rational(7, 4))
(Rational(3, 4) + 2).should eql(Rational(11, 4))
end
end
describe :rational_plus_float, shared: true do
- it "returns the result of substracting other from self as a Float" do
+ it "returns the result of subtracting other from self as a Float" do
(Rational(3, 4) + 0.2).should eql(0.95)
(Rational(3, 4) + 2.5).should eql(3.25)
end
diff --git a/spec/ruby/shared/rational/round.rb b/spec/ruby/shared/rational/round.rb
index 8874daceea..c7a4cc6d07 100644
--- a/spec/ruby/shared/rational/round.rb
+++ b/spec/ruby/shared/rational/round.rb
@@ -68,4 +68,29 @@ describe :rational_round, shared: true do
Rational(3, 2).round(2_097_171).should == Rational(3, 2)
end
end
+
+ ruby_version_is "2.4" do
+ describe "with half option" do
+ it "returns an Integer when precision is not passed" do
+ Rational(10, 4).round(half: :up).should == 3
+ Rational(10, 4).round(half: :down).should == 2
+ Rational(10, 4).round(half: :even).should == 2
+ Rational(-10, 4).round(half: :up).should == -3
+ Rational(-10, 4).round(half: :down).should == -2
+ Rational(-10, 4).round(half: :even).should == -2
+ end
+
+ it "returns a Rational when the precision is greater than 0" do
+ Rational(25, 100).round(1, half: :up).should == Rational(3, 10)
+ Rational(25, 100).round(1, half: :down).should == Rational(1, 5)
+ Rational(25, 100).round(1, half: :even).should == Rational(1, 5)
+ Rational(35, 100).round(1, half: :up).should == Rational(2, 5)
+ Rational(35, 100).round(1, half: :down).should == Rational(3, 10)
+ Rational(35, 100).round(1, half: :even).should == Rational(2, 5)
+ Rational(-25, 100).round(1, half: :up).should == Rational(-3, 10)
+ Rational(-25, 100).round(1, half: :down).should == Rational(-1, 5)
+ Rational(-25, 100).round(1, half: :even).should == Rational(-1, 5)
+ end
+ end
+ end
end