Support Ruby 2.6 endless range syntax in Result#[]

This commit is contained in:
Thomas Walpole 2018-11-15 16:42:07 -08:00
parent 72155bd82f
commit e65c6c0547
2 changed files with 7 additions and 1 deletions

View File

@ -59,7 +59,7 @@ module Capybara
nil
end
when Range
idx.max
idx.end && idx.max # endless range will have end == nil
end
if max_idx.nil?

View File

@ -72,6 +72,12 @@ RSpec.describe Capybara::Result do
expect(result[-1].text).to eq '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...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
it 'works with filter blocks' do