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}']"
end
q = Nokogiri::CSS::Parser.parse(selector).map { |ast| ast.to_xpath }.first
if options[:content]
q << "[contains(., #{xpath_escape(options[:content])})]"
end
q
Nokogiri::CSS::Parser.parse(selector).map { |ast| ast.to_xpath }.first
end
def xpath_escape(string)

View File

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