Moved have selector
This commit is contained in:
parent
5a91f10a99
commit
3a5d34e759
@ -1,53 +1,11 @@
|
|||||||
require "webrat/selenium/matchers/have_xpath"
|
require "webrat/selenium/matchers/have_xpath"
|
||||||
# require "webrat/core/matchers/have_selector"
|
require "webrat/selenium/matchers/have_selector"
|
||||||
# require "webrat/core/matchers/have_tag"
|
# require "webrat/core/matchers/have_tag"
|
||||||
# require "webrat/core/matchers/have_content"
|
# require "webrat/core/matchers/have_content"
|
||||||
|
|
||||||
module Webrat
|
module Webrat
|
||||||
module Selenium
|
module Selenium
|
||||||
module Matchers
|
module Matchers
|
||||||
class HaveSelector
|
|
||||||
def initialize(expected)
|
|
||||||
@expected = expected
|
|
||||||
end
|
|
||||||
|
|
||||||
def matches?(response)
|
|
||||||
response.session.wait_for do
|
|
||||||
response.selenium.is_element_present("css=#{@expected}")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# ==== Returns
|
|
||||||
# String:: The failure message.
|
|
||||||
def failure_message
|
|
||||||
"expected following text to match selector #{@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 selector #{@expected}:\n#{@document}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def have_selector(content)
|
|
||||||
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:
|
class HasContent #:nodoc:
|
||||||
def initialize(content)
|
def initialize(content)
|
||||||
@content = content
|
@content = content
|
||||||
|
47
lib/webrat/selenium/matchers/have_selector.rb
Normal file
47
lib/webrat/selenium/matchers/have_selector.rb
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
module Webrat
|
||||||
|
module Selenium
|
||||||
|
module Matchers
|
||||||
|
class HaveSelector
|
||||||
|
def initialize(expected)
|
||||||
|
@expected = expected
|
||||||
|
end
|
||||||
|
|
||||||
|
def matches?(response)
|
||||||
|
response.session.wait_for do
|
||||||
|
response.selenium.is_element_present("css=#{@expected}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# ==== Returns
|
||||||
|
# String:: The failure message.
|
||||||
|
def failure_message
|
||||||
|
"expected following text to match selector #{@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 selector #{@expected}:\n#{@document}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def have_selector(content)
|
||||||
|
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
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user