Skip to content

Commit 2b4545b

Browse files
committed
Cleanup and add spec for (0...Float::INFINITY).minmax
1 parent c6339d8 commit 2b4545b

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

core/range/minmax_spec.rb

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require_relative '../../spec_helper'
22

3+
# These specs use Range.new instead of the literal notation so they parse fine on Ruby < 2.6
34
describe 'Range#minmax' do
45
before(:each) do
56
@x = mock('x')
@@ -13,11 +14,8 @@
1314

1415
describe 'on an inclusive range' do
1516
ruby_version_is '2.6'...'2.7' do
16-
# Endless ranges introduced in 2.6
1717
it 'should try to iterate endlessly on an endless range' do
1818
@x.should_receive(:succ).once.and_return(@y)
19-
20-
# Endless range literal would cause SyntaxError prior to 2.6
2119
range = Range.new(@x, nil)
2220

2321
-> { range.minmax }.should raise_error(NoMethodError, /^undefined method `succ' for/)
@@ -28,7 +26,6 @@
2826
it 'should raise RangeError on an endless range without iterating the range' do
2927
@x.should_not_receive(:succ)
3028

31-
# Endless range literal would cause SyntaxError prior to 2.6
3229
range = Range.new(@x, nil)
3330

3431
-> { range.minmax }.should raise_error(RangeError, 'cannot get the maximum of endless range')
@@ -37,7 +34,6 @@
3734

3835
ruby_version_is '2.7'...'3.0' do
3936
it 'raises ArgumentError on a beginless range' do
40-
# Beginless range literal would cause SyntaxError prior to 2.7
4137
range = Range.new(nil, @x)
4238

4339
-> { range.minmax }.should raise_error(ArgumentError)
@@ -46,7 +42,6 @@
4642

4743
ruby_version_is '3.0' do
4844
it 'should raise RangeError on a beginless range' do
49-
# Beginless range literal would cause SyntaxError prior to 2.7
5045
range = Range.new(nil, @x)
5146

5247
-> { range.minmax }.should raise_error(RangeError, 'cannot get the minimum of beginless range')
@@ -107,8 +102,6 @@
107102
# Endless ranges introduced in 2.6
108103
it 'should try to iterate endlessly on an endless range' do
109104
@x.should_receive(:succ).once.and_return(@y)
110-
111-
# Endless range literal would cause SyntaxError prior to 2.6
112105
range = Range.new(@x, nil, true)
113106

114107
-> { range.minmax }.should raise_error(NoMethodError, /^undefined method `succ' for/)
@@ -118,16 +111,12 @@
118111
ruby_version_is '2.7' do
119112
it 'should raise RangeError on an endless range' do
120113
@x.should_not_receive(:succ)
121-
122-
# Endless range literal would cause SyntaxError prior to 2.6
123114
range = Range.new(@x, nil, true)
124115

125116
-> { range.minmax }.should raise_error(RangeError, 'cannot get the maximum of endless range')
126117
end
127118

128-
# Beginless ranges introduced in 2.7
129119
it 'should raise RangeError on a beginless range' do
130-
# Beginless range literal would cause SyntaxError prior to 2.7
131120
range = Range.new(nil, @x, true)
132121

133122
-> { range.minmax }.should raise_error(RangeError,
@@ -163,11 +152,15 @@
163152
it 'should return the minimum and maximum values for a numeric range without iterating the range' do
164153
# We cannot set expectations on integers,
165154
# so we "prevent" iteration by picking a value that would iterate until the spec times out.
166-
# Since we cannot exclude a non Integer end value, we use a HUGE Integer.
167-
range_end = 123_456_789_012_345_678_901_234_567_890
155+
range_end = bignum_value
168156

169157
(1...range_end).minmax.should == [1, range_end - 1]
170158
end
159+
160+
it 'raises TypeError if the end value is not an integer' do
161+
range = (0...Float::INFINITY)
162+
-> { range.minmax }.should raise_error(TypeError, 'cannot exclude non Integer end value')
163+
end
171164
end
172165

173166
it 'should return the minimum and maximum values according to the provided block by iterating the range' do

0 commit comments

Comments
 (0)