From fbb74a5a988f7e0b09619898a253cb440cb46c13 Mon Sep 17 00:00:00 2001 From: Amos King Date: Fri, 9 Jan 2009 22:13:34 -0600 Subject: [PATCH 1/6] 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/6] 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/6] 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/6] 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/6] 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) From 04b765976b7f70d6ad6aded0fe8c33239d088706 Mon Sep 17 00:00:00 2001 From: Amos King Date: Wed, 14 Jan 2009 11:38:38 -0600 Subject: [PATCH 6/6] change matchers to use assert so that assertion count is incremented --- lib/webrat/selenium/matchers.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/webrat/selenium/matchers.rb b/lib/webrat/selenium/matchers.rb index 753ae72..9f3b65a 100644 --- a/lib/webrat/selenium/matchers.rb +++ b/lib/webrat/selenium/matchers.rb @@ -32,12 +32,12 @@ module Webrat def assert_have_xpath(expected) hs = HaveXpath.new(expected) - raise Test::Unit::AssertionFailedError.new(hs.failure_message) unless hs.matches?(response) + assert hs.matches?(response), hs.failure_message end def assert_have_no_xpath(expected) hs = HaveXpath.new(expected) - raise Test::Unit::AssertionFailedError.new(hs.negative_failure_message) if hs.matches?(response) + assert !hs.matches?(response), hs.negative_failure_message end class HaveSelector @@ -72,14 +72,14 @@ module Webrat # the supplied selector def assert_have_selector(expected) hs = HaveSelector.new(expected) - raise Test::Unit::AssertionFailedError.new(hs.failure_message) unless hs.matches?(response) + 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) - raise Test::Unit::AssertionFailedError.new(hs.negative_failure_message) if hs.matches?(response) + assert !hs.matches?(response), hs.negative_failure_message end class HasContent #:nodoc: @@ -131,14 +131,14 @@ module Webrat # 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) + 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) - raise Test::Unit::AssertionFailedError.new(hc.negative_failure_message) if hc.matches?(response) + assert !hc.matches?(response), hc.negative_failure_message end end