mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Work on moving more failure message stuff to Query
This commit is contained in:
parent
4083ed1afa
commit
18191c3223
3 changed files with 19 additions and 19 deletions
|
@ -139,7 +139,7 @@ module Capybara
|
|||
|
||||
def raise_find_error(*args)
|
||||
query = Capybara::Query.new(*args)
|
||||
raise Capybara::ElementNotFound, query.failure_message(self)
|
||||
raise Capybara::ElementNotFound, query.failure_message(:find, self)
|
||||
end
|
||||
|
||||
def find_in_base(query, xpath)
|
||||
|
|
|
@ -28,15 +28,25 @@ module Capybara
|
|||
end
|
||||
end
|
||||
|
||||
def failure_message(node)
|
||||
def failure_message(type, node)
|
||||
message = selector.failure_message.call(node, self) if selector.failure_message
|
||||
message ||= options[:message]
|
||||
message ||= "Unable to find #{name} #{locator.inspect}"
|
||||
if type == :assert
|
||||
message ||= "expected #{description} to return something"
|
||||
else
|
||||
message ||= "Unable to find #{description}"
|
||||
end
|
||||
message
|
||||
end
|
||||
|
||||
def name; selector.name; end
|
||||
|
||||
def description
|
||||
@description = "#{name} #{locator.inspect}"
|
||||
@description << " with text #{options[:text].inspect}" if options[:text]
|
||||
@description
|
||||
end
|
||||
|
||||
def matches_filters?(node)
|
||||
return false if options[:text] and not node.text.match(options[:text])
|
||||
return false if options[:visible] and not node.visible?
|
||||
|
|
|
@ -16,25 +16,15 @@ module Capybara
|
|||
end
|
||||
|
||||
def failure_message_for_should
|
||||
if normalized.failure_message
|
||||
normalized.failure_message.call(@actual, normalized)
|
||||
else
|
||||
"expected #{selector_name} to return something"
|
||||
end
|
||||
query.failure_message(:assert, @actual)
|
||||
end
|
||||
|
||||
def failure_message_for_should_not
|
||||
"expected #{selector_name} not to return anything"
|
||||
"expected #{query.description} not to return anything"
|
||||
end
|
||||
|
||||
def description
|
||||
"has #{selector_name}"
|
||||
end
|
||||
|
||||
def selector_name
|
||||
name = "#{normalized.name} #{normalized.locator.inspect}"
|
||||
name << " with text #{normalized.options[:text].inspect}" if normalized.options[:text]
|
||||
name
|
||||
"has #{query.description}"
|
||||
end
|
||||
|
||||
def wrap(actual)
|
||||
|
@ -45,8 +35,8 @@ module Capybara
|
|||
end
|
||||
end
|
||||
|
||||
def normalized
|
||||
@normalized ||= Capybara::Selector.normalize(*@args)
|
||||
def query
|
||||
@query ||= Capybara::Query.new(*@args)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue