Began moving selenium matchers to their own files to be consistent with core matchers and for maintainability.

This commit is contained in:
Amos King 2009-01-23 20:59:30 -06:00
parent 0b8e378fb2
commit 5a91f10a99
2 changed files with 48 additions and 39 deletions

View File

@ -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 Webrat
module Selenium module Selenium
module Matchers 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 class HaveSelector
def initialize(expected) def initialize(expected)
@expected = expected @expected = expected

View File

@ -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