Skip to content

Commit

Permalink
Make selenium matchers handle negative match more consistently with p…
Browse files Browse the repository at this point in the history
…ositive match
  • Loading branch information
lukemelia committed Jan 5, 2010
1 parent b64d68a commit f9985cd
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 12 deletions.
4 changes: 4 additions & 0 deletions History.txt
@@ -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.
Expand Down
34 changes: 23 additions & 11 deletions lib/webrat/selenium/matchers/have_content.rb
Expand Up @@ -7,29 +7,33 @@ def initialize(content)
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
false
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
Expand All @@ -40,6 +44,14 @@ def content_message
"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
Expand All @@ -52,7 +64,7 @@ def contain(content)
# the supplied string or regexp
def assert_contain(content)
hc = HasContent.new(content)
assert hc.matches?(response), hc.failure_message
assert hc.matches?(response), hc.failure_message
end

# Asserts that the body of the response
Expand Down
8 changes: 8 additions & 0 deletions lib/webrat/selenium/matchers/have_selector.rb
Expand Up @@ -14,6 +14,14 @@ def matches?(response)
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
Expand Down
8 changes: 8 additions & 0 deletions lib/webrat/selenium/matchers/have_xpath.rb
Expand Up @@ -14,6 +14,14 @@ def matches?(response)
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
Expand Down
2 changes: 1 addition & 1 deletion lib/webrat/selenium/selenium_rc_server.rb
Expand Up @@ -61,7 +61,7 @@ def wait_for_socket
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

Expand Down

0 comments on commit f9985cd

Please sign in to comment.