Support Ruby 2.6 endless range syntax in Result#[]
This commit is contained in:
parent
72155bd82f
commit
e65c6c0547
|
@ -59,7 +59,7 @@ module Capybara
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
when Range
|
when Range
|
||||||
idx.max
|
idx.end && idx.max # endless range will have end == nil
|
||||||
end
|
end
|
||||||
|
|
||||||
if max_idx.nil?
|
if max_idx.nil?
|
||||||
|
|
|
@ -72,6 +72,12 @@ RSpec.describe Capybara::Result do
|
||||||
expect(result[-1].text).to eq 'Delta'
|
expect(result[-1].text).to eq 'Delta'
|
||||||
expect(result[-2, 3].map(&:text)).to eq %w[Gamma Delta]
|
expect(result[-2, 3].map(&:text)).to eq %w[Gamma Delta]
|
||||||
expect(result[1..7].map(&:text)).to eq %w[Beta Gamma Delta]
|
expect(result[1..7].map(&:text)).to eq %w[Beta Gamma Delta]
|
||||||
|
expect(result[1...3].map(&:text)).to eq %w[Beta Gamma]
|
||||||
|
expect(result[2..-1].map(&:text)).to eq %w[Gamma Delta]
|
||||||
|
expect(result[2...-1].map(&:text)).to eq %w[Gamma]
|
||||||
|
eval <<~TEST if RUBY_VERSION.to_f > 2.5
|
||||||
|
expect(result[2..].map(&:text)).to eq %w[Gamma Delta]
|
||||||
|
TEST
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'works with filter blocks' do
|
it 'works with filter blocks' do
|
||||||
|
|
Loading…
Reference in New Issue