Pulling :content functionality up from have_selector into have_xpath

This commit is contained in:
Bryan Helmkamp 2009-02-23 20:22:36 -05:00
parent a688c28b19
commit 1625e3e9ba
2 changed files with 5 additions and 7 deletions

View File

@ -43,13 +43,7 @@ module Webrat
selector << "[#{key}='#{value}']" selector << "[#{key}='#{value}']"
end end
q = Nokogiri::CSS::Parser.parse(selector).map { |ast| ast.to_xpath }.first Nokogiri::CSS::Parser.parse(selector).map { |ast| ast.to_xpath }.first
if options[:content]
q << "[contains(., #{xpath_escape(options[:content])})]"
end
q
end end
def xpath_escape(string) def xpath_escape(string)

View File

@ -55,6 +55,10 @@ module Webrat
@query = query @query = query
end end
if @options[:content]
query << "[contains(., #{xpath_escape(@options[:content])})]"
end
@document = Webrat::XML.document(stringlike) @document = Webrat::XML.document(stringlike)
@document.xpath(*@query) @document.xpath(*@query)
end end