Support beginless ranges
This commit is contained in:
parent
ffa7c2f207
commit
4a380967fd
|
@ -1,10 +1,16 @@
|
|||
# Version 3.31.0
|
||||
Release date: unreleased
|
||||
|
||||
### Added
|
||||
|
||||
* Support setting range inputs with the selenium driver [Andrew White]
|
||||
* Support setting range inputs with the rack driver
|
||||
* Support drop modifier keys in drag & drop with selenium driver [Elliot Crosby-McCullough]
|
||||
* `enabled_options` and `disabled options` filters for select selector
|
||||
* Support beingless ranges
|
||||
|
||||
### Fixed
|
||||
|
||||
* Fix Ruby 2.7 deprecation notices around keyword arguments. I have tried to do this without
|
||||
any breaking changes, but due to the nature of the 2.7 changes and some selector types accepting
|
||||
Hashes as locators there are a lot of edge cases. If you find any broken cases please report
|
||||
|
|
|
@ -79,7 +79,8 @@ module Capybara
|
|||
if count
|
||||
message << " #{occurrences count}"
|
||||
elsif between
|
||||
message << " between #{between.first} and #{between.end ? between.last : 'infinite'} times"
|
||||
message << " between #{between.begin ? between.first : 1} and" \
|
||||
" #{between.end ? between.last : 'infinite'} times"
|
||||
elsif maximum
|
||||
message << " at most #{occurrences maximum}"
|
||||
elsif minimum
|
||||
|
|
|
@ -60,7 +60,11 @@ module Capybara
|
|||
nil
|
||||
end
|
||||
when Range
|
||||
idx.end && idx.max # endless range will have end == nil
|
||||
# idx.max is broken with beginless ranges
|
||||
# idx.end && idx.max # endless range will have end == nil
|
||||
max = idx.end
|
||||
max -= 1 if max && idx.exclude_end?
|
||||
max
|
||||
end
|
||||
|
||||
if max_idx.nil?
|
||||
|
@ -95,7 +99,9 @@ module Capybara
|
|||
end
|
||||
|
||||
if between
|
||||
min, max = between.min, (between.end && between.max)
|
||||
min, max = (between.begin && between.min) || 1, between.end
|
||||
max -= 1 if max && between.exclude_end?
|
||||
|
||||
size = load_up_to(max ? max + 1 : min)
|
||||
return size <=> min unless between.include?(size)
|
||||
end
|
||||
|
|
|
@ -209,6 +209,13 @@ Capybara::SpecHelper.spec '#all' do
|
|||
expect { @session.all(:css, 'h1, p', between: 5..) }.to raise_error(Capybara::ExpectationNotMet)
|
||||
end
|
||||
TEST
|
||||
|
||||
eval <<~TEST, binding, __FILE__, __LINE__ + 1 if RUBY_VERSION.to_f > 2.6
|
||||
it'treats a beginless range as maximum' do
|
||||
expect { @session.all(:css, 'h1, p', between: ..7) }.not_to raise_error
|
||||
expect { @session.all(:css, 'h1, p', between: ..3) }.to raise_error(Capybara::ExpectationNotMet)
|
||||
end
|
||||
TEST
|
||||
end
|
||||
|
||||
context 'with multiple count filters' do
|
||||
|
|
|
@ -78,6 +78,10 @@ RSpec.describe Capybara::Result do
|
|||
eval <<~TEST, binding, __FILE__, __LINE__ + 1 if RUBY_VERSION.to_f > 2.5
|
||||
expect(result[2..].map(&:text)).to eq %w[Gamma Delta]
|
||||
TEST
|
||||
eval <<~TEST, binding, __FILE__, __LINE__ + 1 if RUBY_VERSION.to_f > 2.6
|
||||
expect(result[..2].map(&:text)).to eq %w[Alpha Beta Gamma]
|
||||
expect(result[...2].map(&:text)).to eq %w[Alpha Beta]
|
||||
TEST
|
||||
end
|
||||
|
||||
it 'works with filter blocks' do
|
||||
|
|
Loading…
Reference in New Issue