Skip to content

Commit

Permalink
Remove locator from query description if unset (#2716)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbliard committed Dec 11, 2023
1 parent fafcb58 commit 10c097f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/capybara/queries/selector_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ def description(only_applied = false) # rubocop:disable Style/OptionalBooleanPar
desc << 'non-visible ' if visible == :hidden
end

desc << "#{label} #{locator.inspect}"
desc << label.to_s
desc << " #{locator.inspect}" unless locator.nil?

if show_for[:any]
desc << " with#{' exact' if exact_text == true} text #{options[:text].inspect}" if options[:text]
Expand Down
8 changes: 8 additions & 0 deletions lib/capybara/spec/session/find_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,14 @@
end.to raise_error(Capybara::ElementNotFound, 'Unable to find xpath "//div[@id=\\"nosuchthing\\"]"')
end

context 'without locator' do
it 'should not output `nil` in the ElementNotFound message if nothing was found' do
expect do
@session.find(:label, text: 'no such thing').to be_nil
end.to raise_error(Capybara::ElementNotFound, 'Unable to find label')
end
end

it 'should accept an XPath instance' do
@session.visit('/form')
@xpath = Capybara::Selector.new(:fillable_field, config: {}, format: :xpath).call('First Name')
Expand Down
2 changes: 1 addition & 1 deletion lib/capybara/spec/session/node_wrapper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ def to_capybara_node(); @element end
end.to raise_error(/^expected to find css "#second" within #<Capybara::Node::Element/)
expect do
expect(para).to have_link(href: %r{/without_simple_html})
end.to raise_error(%r{^expected to find link nil with href matching /\\/without_simple_html/ within #<Capybara::Node::Element})
end.to raise_error(%r{^expected to find link with href matching /\\/without_simple_html/ within #<Capybara::Node::Element})
end
end

0 comments on commit 10c097f

Please sign in to comment.