Skip to content

Commit

Permalink
Pulling :content functionality up from have_selector into have_xpath
Browse files Browse the repository at this point in the history
  • Loading branch information
brynary committed Feb 24, 2009
1 parent a688c28 commit 1625e3e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
8 changes: 1 addition & 7 deletions lib/webrat/core/matchers/have_selector.rb
Expand Up @@ -43,13 +43,7 @@ def query
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)
Expand Down
4 changes: 4 additions & 0 deletions lib/webrat/core/matchers/have_xpath.rb
Expand Up @@ -55,6 +55,10 @@ def nokogiri_matches(stringlike)
@query = query
end

if @options[:content]
query << "[contains(., #{xpath_escape(@options[:content])})]"
end

@document = Webrat::XML.document(stringlike)
@document.xpath(*@query)
end
Expand Down

0 comments on commit 1625e3e

Please sign in to comment.