From fbb74a5a988f7e0b09619898a253cb440cb46c13 Mon Sep 17 00:00:00 2001 From: Amos King Date: Fri, 9 Jan 2009 22:13:34 -0600 Subject: [PATCH 1/5] include Webrat::Matchers in selinium mode --- lib/webrat/selenium.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/webrat/selenium.rb b/lib/webrat/selenium.rb index 28a9485..9dd487d 100644 --- a/lib/webrat/selenium.rb +++ b/lib/webrat/selenium.rb @@ -88,6 +88,7 @@ module ActionController #:nodoc: IntegrationTest.class_eval do include Webrat::Methods include Webrat::Selenium::Methods + include Webrat::Matchers include Webrat::Selenium::Matchers end end From 10b31be511f7d93669c2dd6defd0a39abc3d111b Mon Sep 17 00:00:00 2001 From: Amos King Date: Fri, 9 Jan 2009 22:14:12 -0600 Subject: [PATCH 2/5] remove duplicated code from the Has Content matchers in selenium matchers file. --- lib/webrat/selenium/matchers.rb | 31 ------------------------------- 1 file changed, 31 deletions(-) diff --git a/lib/webrat/selenium/matchers.rb b/lib/webrat/selenium/matchers.rb index a3d38f8..53455b9 100644 --- a/lib/webrat/selenium/matchers.rb +++ b/lib/webrat/selenium/matchers.rb @@ -59,10 +59,6 @@ module Webrat end class HasContent #:nodoc: - def initialize(content) - @content = content - end - def matches?(response) if @content.is_a?(Regexp) text_finder = "regexp:#{@content.source}" @@ -74,33 +70,6 @@ module Webrat response.selenium.is_text_present(text_finder) end end - - # ==== Returns - # String:: The failure message. - def failure_message - "expected the following element's content to #{content_message}:\n#{@element}" - 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}" - end - - def content_message - case @content - when String - "include \"#{@content}\"" - when Regexp - "match #{@content.inspect}" - end - end - end - - # Matches the contents of an HTML document with - # whatever string is supplied - def contain(content) - HasContent.new(content) end end From 928b2242376db177d2c2fa9c72162c5d124562e1 Mon Sep 17 00:00:00 2001 From: Amos King Date: Fri, 9 Jan 2009 23:11:33 -0600 Subject: [PATCH 3/5] Revert "include Webrat::Matchers in selinium mode" And Revert "getting assert_* to work with selenium" --- lib/webrat/selenium.rb | 1 - lib/webrat/selenium/matchers.rb | 31 +++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/lib/webrat/selenium.rb b/lib/webrat/selenium.rb index 9dd487d..28a9485 100644 --- a/lib/webrat/selenium.rb +++ b/lib/webrat/selenium.rb @@ -88,7 +88,6 @@ module ActionController #:nodoc: IntegrationTest.class_eval do include Webrat::Methods include Webrat::Selenium::Methods - include Webrat::Matchers include Webrat::Selenium::Matchers end end diff --git a/lib/webrat/selenium/matchers.rb b/lib/webrat/selenium/matchers.rb index 53455b9..a3d38f8 100644 --- a/lib/webrat/selenium/matchers.rb +++ b/lib/webrat/selenium/matchers.rb @@ -59,6 +59,10 @@ module Webrat end class HasContent #:nodoc: + def initialize(content) + @content = content + end + def matches?(response) if @content.is_a?(Regexp) text_finder = "regexp:#{@content.source}" @@ -70,6 +74,33 @@ module Webrat response.selenium.is_text_present(text_finder) end end + + # ==== Returns + # String:: The failure message. + def failure_message + "expected the following element's content to #{content_message}:\n#{@element}" + 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}" + end + + def content_message + case @content + when String + "include \"#{@content}\"" + when Regexp + "match #{@content.inspect}" + end + end + end + + # Matches the contents of an HTML document with + # whatever string is supplied + def contain(content) + HasContent.new(content) end end From d4008ebc06ab59d8b13d643b2a62994130c28509 Mon Sep 17 00:00:00 2001 From: Amos King Date: Fri, 9 Jan 2009 23:13:57 -0600 Subject: [PATCH 4/5] oops didn't notice I was using the wrong matchers. Matchers now using Selenium mode. --- lib/webrat/selenium/matchers.rb | 38 +++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/lib/webrat/selenium/matchers.rb b/lib/webrat/selenium/matchers.rb index a3d38f8..753ae72 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) + 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 \ No newline at end of file From 8b6477a0c6e44faefc0e8a9e23c38f19719d7fab Mon Sep 17 00:00:00 2001 From: Amos King Date: Mon, 12 Jan 2009 15:57:42 -0600 Subject: [PATCH 5/5] change History file --- History.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/History.txt b/History.txt index 1937bf8..9cf850f 100644 --- a/History.txt +++ b/History.txt @@ -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)