1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Warn when count options passed to find

This commit is contained in:
Thomas Walpole 2022-05-08 13:53:48 -07:00
parent 72b70fa058
commit f973c9f1f4
3 changed files with 14 additions and 1 deletions

View file

@ -50,6 +50,13 @@ module Capybara
#
def find(*args, **options, &optional_filter_block)
options[:session_options] = session_options
count_options = options.slice(*Capybara::Queries::BaseQuery::COUNT_KEYS)
unless count_options.empty?
Capybara::Helpers.warn(
"'find' does not support count options (#{count_options}) ignoring. " \
"Called from: #{Capybara::Helpers.filter_backtrace(caller)}"
)
end
synced_resolve Capybara::Queries::SelectorQuery.new(*args, **options, &optional_filter_block)
end

View file

@ -528,4 +528,10 @@ Capybara::SpecHelper.spec '#find' do
expect(@session.find(:link, 'test-foo')[:id]).to eq 'foo'
end
end
it 'should warn if passed count options' do
allow(Capybara::Helpers).to receive(:warn)
@session.find('//h1', count: 44)
expect(Capybara::Helpers).to have_received(:warn).with(/'find' does not support count options/)
end
end

View file

@ -471,7 +471,7 @@ RSpec.describe Capybara do
end
it 'includes wildcarded keys in description' do
expect { string.find(:element, 'input', not_there: 'bad', presence: true, absence: false, count: 1) }
expect { string.all(:element, 'input', not_there: 'bad', presence: true, absence: false, count: 1) }
.to(raise_error do |e|
expect(e).to be_a(Capybara::ElementNotFound)
expect(e.message).to include 'not_there => bad'