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)
|
def raise_find_error(*args)
|
||||||
query = Capybara::Query.new(*args)
|
query = Capybara::Query.new(*args)
|
||||||
raise Capybara::ElementNotFound, query.failure_message(self)
|
raise Capybara::ElementNotFound, query.failure_message(:find, self)
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_in_base(query, xpath)
|
def find_in_base(query, xpath)
|
||||||
|
|
|
@ -28,15 +28,25 @@ module Capybara
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def failure_message(node)
|
def failure_message(type, node)
|
||||||
message = selector.failure_message.call(node, self) if selector.failure_message
|
message = selector.failure_message.call(node, self) if selector.failure_message
|
||||||
message ||= options[: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
|
message
|
||||||
end
|
end
|
||||||
|
|
||||||
def name; selector.name; 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)
|
def matches_filters?(node)
|
||||||
return false if options[:text] and not node.text.match(options[:text])
|
return false if options[:text] and not node.text.match(options[:text])
|
||||||
return false if options[:visible] and not node.visible?
|
return false if options[:visible] and not node.visible?
|
||||||
|
|
|
@ -16,25 +16,15 @@ module Capybara
|
||||||
end
|
end
|
||||||
|
|
||||||
def failure_message_for_should
|
def failure_message_for_should
|
||||||
if normalized.failure_message
|
query.failure_message(:assert, @actual)
|
||||||
normalized.failure_message.call(@actual, normalized)
|
|
||||||
else
|
|
||||||
"expected #{selector_name} to return something"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def failure_message_for_should_not
|
def failure_message_for_should_not
|
||||||
"expected #{selector_name} not to return anything"
|
"expected #{query.description} not to return anything"
|
||||||
end
|
end
|
||||||
|
|
||||||
def description
|
def description
|
||||||
"has #{selector_name}"
|
"has #{query.description}"
|
||||||
end
|
|
||||||
|
|
||||||
def selector_name
|
|
||||||
name = "#{normalized.name} #{normalized.locator.inspect}"
|
|
||||||
name << " with text #{normalized.options[:text].inspect}" if normalized.options[:text]
|
|
||||||
name
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def wrap(actual)
|
def wrap(actual)
|
||||||
|
@ -45,8 +35,8 @@ module Capybara
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def normalized
|
def query
|
||||||
@normalized ||= Capybara::Selector.normalize(*@args)
|
@query ||= Capybara::Query.new(*@args)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue