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

Add calling location when locators fail validation

This commit is contained in:
Thomas Walpole 2022-05-08 13:04:24 -07:00
parent 2f4a426ee7
commit 72b70fa058
3 changed files with 12 additions and 2 deletions

View file

@ -73,7 +73,7 @@ module Capybara
def filter_backtrace(trace)
return 'No backtrace' unless trace
filter = %r{lib/capybara/|lib/rspec/|lib/minitest/}
filter = %r{lib/capybara/|lib/rspec/|lib/minitest/|delegate.rb}
new_trace = trace.take_while { |line| line !~ filter }
new_trace = trace.grep_v(filter) if new_trace.empty?
new_trace = trace.dup if new_trace.empty?

View file

@ -66,7 +66,11 @@ module Capybara
end
ensure
unless locator_valid?(locator)
warn "Locator #{locator.class}:#{locator.inspect} for selector #{name.inspect} must #{locator_description}. This will raise an error in a future version of Capybara."
Capybara::Helpers.warn(
"Locator #{locator.class}:#{locator.inspect} for selector #{name.inspect} must #{locator_description}. " \
'This will raise an error in a future version of Capybara. ' \
"Called from: #{Capybara::Helpers.filter_backtrace(caller)}"
)
end
end

View file

@ -19,6 +19,12 @@ Capybara::SpecHelper.spec '#has_link?' do
expect(@session).not_to have_link('A link', href: /nonexistent/)
end
it 'should notify if an invalid locator is specified' do
allow(Capybara::Helpers).to receive(:warn).and_return(nil)
@session.has_link?(@session)
expect(Capybara::Helpers).to have_received(:warn).with(/Called from: .+/)
end
context 'with focused:', requires: [:active_element] do
it 'should be true if the given link is on the page and has focus' do
@session.send_keys(:tab)