Support Ruby 2.6 endless range in query :between option

This commit is contained in:
Thomas Walpole 2018-11-16 12:42:41 -08:00
parent ebbeeb8918
commit 4e0fb16eb4
3 changed files with 10 additions and 3 deletions

View File

@ -79,7 +79,7 @@ module Capybara
if count
message << " #{occurrences count}"
elsif between
message << " between #{between.first} and #{between.last} times"
message << " between #{between.first} and #{between.end ? between.last : "infinite"} times"
elsif maximum
message << " at most #{occurrences maximum}"
elsif minimum

View File

@ -92,8 +92,8 @@ module Capybara
end
if between
min, max = between.minmax
size = load_up_to(max + 1)
min, max = between.min, (between.end && between.max)
size = load_up_to(max ? max + 1 : min)
return between.include?(size) ? 0 : size <=> min
end

View File

@ -135,6 +135,13 @@ Capybara::SpecHelper.spec '#all' do
it 'should raise ExpectationNotMet when the number of elements founds does not match the expectation' do
expect { @session.all(:css, 'h1, p', between: 0..3) }.to raise_error(Capybara::ExpectationNotMet)
end
eval <<~TEST, binding, __FILE__, __LINE__ + 1 if RUBY_VERSION.to_f > 2.5
it'treats an endless range as minimum' do
expect { @session.all(:css, 'h1, p', between: 2..) }.not_to raise_error
expect { @session.all(:css, 'h1, p', between: 5..) }.to raise_error(Capybara::ExpectationNotMet)
end
TEST
end
context 'with multiple count filters' do