Make selenium matchers handle negative match more consistently with positive match

This commit is contained in:
lukemelia 2010-01-05 18:33:45 -05:00
parent b64d68a2a8
commit f9985cd488
5 changed files with 44 additions and 12 deletions

View File

@ -1,3 +1,7 @@
* Bug fixes
* Make selenium matchers handle negative match more consistently with positive match (Luke Melia)
== 0.6.0 / 2009-11-28
REMOVED: Support for Hpricot + REXML as an alternative to Nokogiri.

View File

@ -7,29 +7,33 @@ module Webrat
end
def matches?(response)
if @content.is_a?(Regexp)
text_finder = "regexp:#{@content.source}"
else
text_finder = @content
end
response.session.wait_for do
response.selenium.is_text_present(text_finder)
end
rescue Webrat::TimeoutError
rescue Webrat::TimeoutError => e
@error_message = e.message
false
end
def does_not_match?(response)
response.session.wait_for do
!response.selenium.is_text_present(text_finder)
end
rescue Webrat::TimeoutError => e
@error_message = e.message
false
end
# ==== Returns
# String:: The failure message.
def failure_message
"expected the following element's content to #{content_message}:\n#{@element}"
"expected the response to #{content_message}:\n#{@error_message}"
end
# ==== Returns
# String:: The failure message to be displayed in negative matches.
def negative_failure_message
"expected the following element's content to not #{content_message}:\n#{@element}"
"expected the response to not #{content_message}"
end
def content_message
@ -40,6 +44,14 @@ module Webrat
"match #{@content.inspect}"
end
end
def text_finder
if @content.is_a?(Regexp)
"regexp:#{@content.source}"
else
@content
end
end
end
# Matches the contents of an HTML document with

View File

@ -14,6 +14,14 @@ module Webrat
false
end
def does_not_match?(response)
response.session.wait_for do
!response.selenium.is_element_present("css=#{@expected}")
end
rescue Webrat::TimeoutError
false
end
# ==== Returns
# String:: The failure message.
def failure_message

View File

@ -14,6 +14,14 @@ module Webrat
false
end
def does_not_match?(response)
response.session.wait_for do
!response.selenium.is_element_present("xpath=#{@expected}")
end
rescue Webrat::TimeoutError
false
end
# ==== Returns
# String:: The failure message.
def failure_message

View File

@ -61,7 +61,7 @@ module Webrat
TCPSocket.wait_for_service_with_timeout \
:host => (Webrat.configuration.selenium_server_address || "0.0.0.0"),
:port => Webrat.configuration.selenium_server_port,
:timeout => 15 # seconds
:timeout => 45 # seconds
end
end