From 932fdab8844b866c55262d890eb808b513fff9ac Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Sun, 15 Feb 2009 19:32:25 -0500 Subject: [PATCH] Get quoting working for content --- lib/webrat/core/matchers/have_tag.rb | 23 ++++++++++++++++++----- spec/public/matchers_spec.rb | 15 +++++++++++++++ 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/lib/webrat/core/matchers/have_tag.rb b/lib/webrat/core/matchers/have_tag.rb index 3f809521..7529fcc3 100644 --- a/lib/webrat/core/matchers/have_tag.rb +++ b/lib/webrat/core/matchers/have_tag.rb @@ -36,14 +36,27 @@ def tag_inspect def query options = @expected.last.dup selector = @expected.first.to_s - - selector << ":contains('#{options.delete(:content)}')" if options[:content] - + options.each do |key, value| + next if key == :content selector << "[#{key}='#{value}']" end - - Nokogiri::CSS::Parser.parse(selector).map { |ast| ast.to_xpath } + + q = Nokogiri::CSS::Parser.parse(selector).map { |ast| ast.to_xpath }.first + + if options[:content] && options[:content].include?("'") && options[:content].include?('"') + parts = options[:content].split("'").map do |part| + "'#{part}'" + end + + string = "concat(" + parts.join(", \"'\", ") + ")" + q << "[contains(., #{string})]" + elsif options[:content] && options[:content].include?("'") + q << "[contains(., \"#{options[:content]}\")]" + elsif options[:content] + q << "[contains(., '#{options[:content]}')]" + end + q end end diff --git a/spec/public/matchers_spec.rb b/spec/public/matchers_spec.rb index 59642768..ed36c6f9 100644 --- a/spec/public/matchers_spec.rb +++ b/spec/public/matchers_spec.rb @@ -8,6 +8,9 @@ @body = <<-HTML
hello, world!
+

Welcome "Bryan"

+

Welcome 'Bryan'

+

Welcome 'Bryan"