diff --git a/History.txt b/History.txt index 263c53d..22fb15f 100644 --- a/History.txt +++ b/History.txt @@ -24,6 +24,7 @@ * Support passing an ActiveRecord model to #within when in Rails mode [#68] (Luke Melia) * Make assert_* matchers in rails mode increment the assertions count [#123] (Amos King) + * 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) diff --git a/lib/webrat/selenium/matchers.rb b/lib/webrat/selenium/matchers.rb index a3d38f8..9f3b65a 100644 --- a/lib/webrat/selenium/matchers.rb +++ b/lib/webrat/selenium/matchers.rb @@ -30,6 +30,16 @@ module Webrat HaveXpath.new(xpath) end + def assert_have_xpath(expected) + hs = HaveXpath.new(expected) + assert hs.matches?(response), hs.failure_message + end + + def assert_have_no_xpath(expected) + hs = HaveXpath.new(expected) + assert !hs.matches?(response), hs.negative_failure_message + 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) + assert hs.matches?(response), hs.failure_message + 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) + assert !hs.matches?(response), hs.negative_failure_message + 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) + assert hc.matches?(response), hc.failure_message + 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) + assert !hc.matches?(response), hc.negative_failure_message + end + end end end \ No newline at end of file