Merge commit 'origin/lh_116_selenium_asserts' into test_unit_integrations

This commit is contained in:
Mike Gaffney 2009-01-12 23:14:37 -06:00
commit 86089d90b6
2 changed files with 40 additions and 0 deletions

View File

@ -20,6 +20,8 @@
* Use Hpricot and REXML when not parsing with Nokogiri (on JRuby, for example)
* Minor enhancements
* Added assert_* matchers to selenium matchers [#110] (Amos King)
* Added assert_contain, assert_not_contain [#86] (Mike Gaffney, Amos King)
* Add configuration options for the Selenium environment and port (Kieran Pilkington)
* Maximize the browser window after initializing Selenium (Luke Melia)

View File

@ -30,6 +30,16 @@ module Webrat
HaveXpath.new(xpath)
end
def assert_have_xpath(expected)
hs = HaveXpath.new(expected)
raise Test::Unit::AssertionFailedError.new(hs.failure_message) unless hs.matches?(response)
end
def assert_have_no_xpath(expected)
hs = HaveXpath.new(expected)
raise Test::Unit::AssertionFailedError.new(hs.negative_failure_message) if hs.matches?(response)
end
class HaveSelector
def initialize(expected)
@expected = expected
@ -58,6 +68,20 @@ module Webrat
HaveSelector.new(content)
end
# Asserts that the body of the response contains
# the supplied selector
def assert_have_selector(expected)
hs = HaveSelector.new(expected)
raise Test::Unit::AssertionFailedError.new(hs.failure_message) unless hs.matches?(response)
end
# Asserts that the body of the response
# does not contain the supplied string or regepx
def assert_have_no_selector(expected)
hs = HaveSelector.new(expected)
raise Test::Unit::AssertionFailedError.new(hs.negative_failure_message) if hs.matches?(response)
end
class HasContent #:nodoc:
def initialize(content)
@content = content
@ -103,6 +127,20 @@ module Webrat
HasContent.new(content)
end
# Asserts that the body of the response contain
# the supplied string or regexp
def assert_contain(content)
hc = HasContent.new(content)
raise Test::Unit::AssertionFailedError.new(hc.failure_message) unless hc.matches?(response)
end
# Asserts that the body of the response
# does not contain the supplied string or regepx
def assert_not_contain(content)
hc = HasContent.new(content)
raise Test::Unit::AssertionFailedError.new(hc.negative_failure_message) if hc.matches?(response)
end
end
end
end