From e65c6c0547dd8e29c78ed566d2ae46babd55a1a3 Mon Sep 17 00:00:00 2001 From: Thomas Walpole Date: Thu, 15 Nov 2018 16:42:07 -0800 Subject: [PATCH] Support Ruby 2.6 endless range syntax in Result#[] --- lib/capybara/result.rb | 2 +- spec/result_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/capybara/result.rb b/lib/capybara/result.rb index f20c0ec1..8d7dafaf 100644 --- a/lib/capybara/result.rb +++ b/lib/capybara/result.rb @@ -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? diff --git a/spec/result_spec.rb b/spec/result_spec.rb index 616ef81c..4a8e7018 100644 --- a/spec/result_spec.rb +++ b/spec/result_spec.rb @@ -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