Skip to content

Commit b7681a5

Browse files
committed
test: Work around a Ruby 2.7 bug in Range#max
1 parent f258709 commit b7681a5

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

spec/time_range_spec.rb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
# isn't numeric, but some versions of Ruby have a bug.
1313
let(:range_size_return) { nil }
1414

15+
# Range#max can have a bug where it sometimes errors.
16+
let(:has_range_max_bug) { false }
17+
1518
shared_examples 'it is infinite' do
1619
describe '#count' do
1720
subject { range.count }
@@ -180,7 +183,10 @@
180183
describe '#max' do
181184
subject { range.max }
182185

183-
it { is_expected.to eq last }
186+
it 'has a max' do
187+
skip "Range#max has a bug" if has_range_max_bug
188+
expect(range.max).to eq last
189+
end
184190
end
185191
end
186192

@@ -190,6 +196,15 @@
190196
# beginless non-Numeric ranges.
191197
let(:range_size_return) { (.."z").size }
192198

199+
# Ruby 2.7 has a bug where #max will raise
200+
# ArgumentError (comparison of NilClass with String failed)
201+
let(:has_range_max_bug) do
202+
(.."z").max
203+
false
204+
rescue ArgumentError
205+
true
206+
end
207+
193208
it_behaves_like 'a Range'
194209
it_behaves_like 'it has an end'
195210
it_behaves_like 'it is infinite'

0 commit comments

Comments
 (0)