Skip to content

Commit

Permalink
moved have content
Browse files Browse the repository at this point in the history
  • Loading branch information
adkron committed Jan 24, 2009
1 parent 3a5d34e commit 118b522
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 67 deletions.
68 changes: 1 addition & 67 deletions lib/webrat/selenium/matchers.rb
@@ -1,70 +1,4 @@
require "webrat/selenium/matchers/have_xpath"
require "webrat/selenium/matchers/have_selector"
# require "webrat/core/matchers/have_tag"
# require "webrat/core/matchers/have_content"

module Webrat
module Selenium
module Matchers
class HasContent #:nodoc:
def initialize(content)
@content = content
end

def matches?(response)
if @content.is_a?(Regexp)
text_finder = "regexp:#{@content.source}"
else
text_finder = @content
end

response.session.wait_for do
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

# Asserts that the body of the response contain
# the supplied string or regexp
def assert_contain(content)
hc = HasContent.new(content)
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)
assert !hc.matches?(response), hc.negative_failure_message
end

end
end
end
require "webrat/selenium/matchers/have_content"
64 changes: 64 additions & 0 deletions lib/webrat/selenium/matchers/have_content.rb
@@ -0,0 +1,64 @@
module Webrat
module Selenium
module Matchers
class HasContent #:nodoc:
def initialize(content)
@content = content
end

def matches?(response)
if @content.is_a?(Regexp)
text_finder = "regexp:#{@content.source}"
else
text_finder = @content
end

response.session.wait_for do
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

# Asserts that the body of the response contain
# the supplied string or regexp
def assert_contain(content)
hc = HasContent.new(content)
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)
assert !hc.matches?(response), hc.negative_failure_message
end
end
end
end

0 comments on commit 118b522

Please sign in to comment.