Skip to content

Commit f258709

Browse files
committed
test: Work around a Ruby 3.1 bug in Range#size
(.."z").size is supposed to return nil, but in Ruby 3.1 it returns Infinity.
1 parent c5109f7 commit f258709

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ RSpec/ImplicitSubject:
3535
RSpec/MultipleExpectations:
3636
Max: 5
3737

38+
RSpec/MultipleMemoizedHelpers:
39+
Max: 10
40+
3841
# %i[foo bar baz] is more difficult to understand than [:foo, :bar, :baz]
3942
Style/SymbolArray:
4043
Enabled: false

spec/time_range_spec.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
end
99
let(:range) { described_class.new(first, last).by(**by) }
1010

11+
# Range#size is supposed to always return nil when the range
12+
# isn't numeric, but some versions of Ruby have a bug.
13+
let(:range_size_return) { nil }
14+
1115
shared_examples 'it is infinite' do
1216
describe '#count' do
1317
subject { range.count }
@@ -80,7 +84,7 @@
8084
describe '#size' do
8185
subject { range.size }
8286

83-
it { is_expected.to be_nil }
87+
it { is_expected.to eq range_size_return }
8488
end
8589
end
8690

@@ -182,6 +186,9 @@
182186

183187
context 'with no begin' do
184188
let(:first) { nil }
189+
# Ruby 3.1 has a bug where #size returns Infinity for
190+
# beginless non-Numeric ranges.
191+
let(:range_size_return) { (.."z").size }
185192

186193
it_behaves_like 'a Range'
187194
it_behaves_like 'it has an end'

0 commit comments

Comments
 (0)