From 5a91f10a9902dbdae270b17f70e7900be2579bff Mon Sep 17 00:00:00 2001 From: Amos King Date: Fri, 23 Jan 2009 20:59:30 -0600 Subject: [PATCH] Began moving selenium matchers to their own files to be consistent with core matchers and for maintainability. --- lib/webrat/selenium/matchers.rb | 44 +++------------------- lib/webrat/selenium/matchers/have_xpath.rb | 43 +++++++++++++++++++++ 2 files changed, 48 insertions(+), 39 deletions(-) create mode 100644 lib/webrat/selenium/matchers/have_xpath.rb diff --git a/lib/webrat/selenium/matchers.rb b/lib/webrat/selenium/matchers.rb index 9f3b65a..376812b 100644 --- a/lib/webrat/selenium/matchers.rb +++ b/lib/webrat/selenium/matchers.rb @@ -1,45 +1,11 @@ +require "webrat/selenium/matchers/have_xpath" +# require "webrat/core/matchers/have_selector" +# require "webrat/core/matchers/have_tag" +# require "webrat/core/matchers/have_content" + module Webrat module Selenium module Matchers - - class HaveXpath - def initialize(expected) - @expected = expected - end - - def matches?(response) - response.session.wait_for do - response.selenium.is_element_present("xpath=#{@expected}") - end - end - - # ==== Returns - # String:: The failure message. - def failure_message - "expected following text to match xpath #{@expected}:\n#{@document}" - end - - # ==== Returns - # String:: The failure message to be displayed in negative matches. - def negative_failure_message - "expected following text to not match xpath #{@expected}:\n#{@document}" - end - end - - def have_xpath(xpath) - 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 diff --git a/lib/webrat/selenium/matchers/have_xpath.rb b/lib/webrat/selenium/matchers/have_xpath.rb new file mode 100644 index 0000000..40cf9b8 --- /dev/null +++ b/lib/webrat/selenium/matchers/have_xpath.rb @@ -0,0 +1,43 @@ +module Webrat + module Selenium + module Matchers + class HaveXpath + def initialize(expected) + @expected = expected + end + + def matches?(response) + response.session.wait_for do + response.selenium.is_element_present("xpath=#{@expected}") + end + end + + # ==== Returns + # String:: The failure message. + def failure_message + "expected following text to match xpath #{@expected}:\n#{@document}" + end + + # ==== Returns + # String:: The failure message to be displayed in negative matches. + def negative_failure_message + "expected following text to not match xpath #{@expected}:\n#{@document}" + end + end + + def have_xpath(xpath) + 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 + end + end +end \ No newline at end of file