summaryrefslogtreecommitdiff
path: root/spec/ruby/core/range/max_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/range/max_spec.rb')
-rw-r--r--spec/ruby/core/range/max_spec.rb64
1 files changed, 36 insertions, 28 deletions
diff --git a/spec/ruby/core/range/max_spec.rb b/spec/ruby/core/range/max_spec.rb
index f2672170d9..57714967ce 100644
--- a/spec/ruby/core/range/max_spec.rb
+++ b/spec/ruby/core/range/max_spec.rb
@@ -14,56 +14,66 @@ describe "Range#max" do
end
it "raises TypeError when called on an exclusive range and a non Integer value" do
- -> { (303.20...908.1111).max }.should raise_error(TypeError)
+ -> { (303.20...908.1111).max }.should.raise(TypeError)
end
it "returns nil when the endpoint is less than the start point" do
- (100..10).max.should be_nil
- ('z'..'l').max.should be_nil
+ (100..10).max.should == nil
+ ('z'..'l').max.should == nil
end
it "returns nil when the endpoint equals the start point and the range is exclusive" do
- (5...5).max.should be_nil
+ (5...5).max.should == nil
end
it "returns the endpoint when the endpoint equals the start point and the range is inclusive" do
- (5..5).max.should equal(5)
+ (5..5).max.should.equal?(5)
end
it "returns nil when the endpoint is less than the start point in a Float range" do
- (3003.20..908.1111).max.should be_nil
+ (3003.20..908.1111).max.should == nil
end
it "returns end point when the range is Time..Time(included end point)" do
time_start = Time.now
time_end = Time.now + 1.0
- (time_start..time_end).max.should equal(time_end)
+ (time_start..time_end).max.should.equal?(time_end)
end
it "raises TypeError when called on a Time...Time(excluded end point)" do
time_start = Time.now
time_end = Time.now + 1.0
- -> { (time_start...time_end).max }.should raise_error(TypeError)
+ -> { (time_start...time_end).max }.should.raise(TypeError)
end
- ruby_version_is "2.6" do
- it "raises RangeError when called on an endless range" do
- -> { eval("(1..)").max }.should raise_error(RangeError)
- end
+ it "raises RangeError when called on an endless range" do
+ -> { eval("(1..)").max }.should.raise(RangeError)
end
- ruby_version_is "3.0" do
- it "returns the end point for beginless ranges" do
- eval("(..1)").max.should == 1
- eval("(..1.0)").max.should == 1.0
- end
+ it "returns the end point for beginless ranges" do
+ (..1).max.should == 1
+ (..1.0).max.should == 1.0
+ end
- it "raises for an exclusive beginless range" do
+ ruby_version_is ""..."4.0" do
+ it "raises for an exclusive beginless Integer range" do
-> {
- eval("(...1)").max
- }.should raise_error(TypeError, 'cannot exclude end value with non Integer begin value')
+ (...1).max
+ }.should.raise(TypeError, 'cannot exclude end value with non Integer begin value')
end
end
+
+ ruby_version_is "4.0" do
+ it "returns the end point for exclusive beginless Integer ranges" do
+ (...1).max.should == 0
+ end
+ end
+
+ it "raises for an exclusive beginless non Integer range" do
+ -> {
+ (...1.0).max
+ }.should.raise(TypeError, 'cannot exclude non Integer end value')
+ end
end
describe "Range#max given a block" do
@@ -72,7 +82,7 @@ describe "Range#max given a block" do
(1..10).max {|a,b| acc << [a,b]; a }
acc.flatten!
(1..10).each do |value|
- acc.include?(value).should be_true
+ acc.include?(value).should == true
end
end
@@ -94,14 +104,12 @@ describe "Range#max given a block" do
end
it "returns nil when the endpoint is less than the start point" do
- (100..10).max {|x,y| x <=> y}.should be_nil
- ('z'..'l').max {|x,y| x <=> y}.should be_nil
- (5...5).max {|x,y| x <=> y}.should be_nil
+ (100..10).max {|x,y| x <=> y}.should == nil
+ ('z'..'l').max {|x,y| x <=> y}.should == nil
+ (5...5).max {|x,y| x <=> y}.should == nil
end
- ruby_version_is "2.7" do
- it "raises RangeError when called with custom comparison method on an beginless range" do
- -> { eval("(..1)").max {|a, b| a} }.should raise_error(RangeError)
- end
+ it "raises RangeError when called with custom comparison method on an beginless range" do
+ -> { (..1).max {|a, b| a} }.should.raise(RangeError)
end
end