Pulling :count option up from have_selector to have_xpath

This commit is contained in:
Bryan Helmkamp 2009-02-23 20:18:36 -05:00
parent 66d39b851c
commit 9761b64b60
2 changed files with 15 additions and 23 deletions

View File

@ -16,30 +16,17 @@ module Webrat
"expected following output to omit a #{tag_inspect}:\n#{@document}"
end
def matches?(stringlike, &block)
@block ||= block
matched = matches(stringlike)
options = @expected.last.dup
if options[:count]
matched.size == options[:count] && (!@block || @block.call(matched))
else
matched.any? && (!@block || @block.call(matched))
end
end
def tag_inspect
options = @expected.last.dup
options = @options.dup
content = options.delete(:content)
html = "<#{@expected.first}"
html = "<#{@expected}"
options.each do |k,v|
html << " #{k}='#{v}'"
end
if content
html << ">#{content}</#{@expected.first}>"
html << ">#{content}</#{@expected}>"
else
html << "/>"
end
@ -48,8 +35,8 @@ module Webrat
end
def query
options = @expected.last.dup
selector = @expected.first.to_s
options = @options.dup
selector = @expected.to_s
options.each do |key, value|
next if [:content, :count].include?(key)
@ -84,7 +71,7 @@ module Webrat
# ==== Returns
# HaveSelector:: A new have selector matcher.
def have_selector(name, attributes = {}, &block)
HaveSelector.new([name, attributes], &block)
HaveSelector.new(name, attributes, &block)
end
alias_method :match_selector, :have_selector
@ -92,14 +79,14 @@ module Webrat
# Asserts that the body of the response contains
# the supplied selector
def assert_have_selector(name, attributes = {}, &block)
matcher = HaveSelector.new([name, attributes], &block)
matcher = HaveSelector.new(name, attributes, &block)
assert matcher.matches?(response_body), matcher.failure_message
end
# Asserts that the body of the response
# does not contain the supplied string or regepx
def assert_have_no_selector(name, attributes = {}, &block)
matcher = HaveSelector.new([name, attributes], &block)
matcher = HaveSelector.new(name, attributes, &block)
assert !matcher.matches?(response_body), matcher.negative_failure_message
end

View File

@ -7,15 +7,20 @@ module Webrat
class HaveXpath #:nodoc:
def initialize(expected, options = {}, &block)
@expected = expected
@options = {}
@options = options
@block = block
end
def matches?(stringlike, &block)
@block ||= block
matched = matches(stringlike)
if @options[:count]
matched.size == @options[:count] && (!@block || @block.call(matched))
else
matched.any? && (!@block || @block.call(matched))
end
end
def matches(stringlike)
if Webrat.configuration.parse_with_nokogiri?