Get quoting working for content
This commit is contained in:
parent
7ba620f38b
commit
932fdab884
@ -37,13 +37,26 @@ module Webrat
|
||||
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
|
||||
|
||||
|
@ -8,6 +8,9 @@ describe Webrat::Matchers do
|
||||
@body = <<-HTML
|
||||
<div id='main'>
|
||||
<div class='inner'>hello, world!</div>
|
||||
<h2>Welcome "Bryan"</h2>
|
||||
<h3>Welcome 'Bryan'</h3>
|
||||
<h4>Welcome 'Bryan"</h4>
|
||||
<ul>
|
||||
<li>First</li>
|
||||
<li>Second</li>
|
||||
@ -178,6 +181,18 @@ describe Webrat::Matchers do
|
||||
@body.should have_tag("div", :content => "hello, world!")
|
||||
end
|
||||
|
||||
it "should be able to specify the content of the tag with double quotes in it" do
|
||||
@body.should have_tag("h2", :content => 'Welcome "Bryan"')
|
||||
end
|
||||
|
||||
it "should be able to specify the content of the tag with single quotes in it" do
|
||||
@body.should have_tag("h3", :content => "Welcome 'Bryan'")
|
||||
end
|
||||
|
||||
it "should be able to specify the content of the tag with both kinds of quotes" do
|
||||
@body.should have_tag("h4", :content => "Welcome 'Bryan\"")
|
||||
end
|
||||
|
||||
it "should be able to specify the attributes of the tag" do
|
||||
@body.should have_tag("div", :class => "inner")
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user