match descendents in have_selector/have_xpath blocks
This commit is contained in:
parent
481bfe03c0
commit
9a3668be92
|
@ -32,7 +32,7 @@ module Webrat
|
|||
|
||||
def rexml_matches(stringlike)
|
||||
if REXML::Node === stringlike || Array === stringlike
|
||||
@query = query.map { |q| q.gsub(%r'//', './') }
|
||||
@query = query.map { |q| q.gsub(%r'^//', './/') }
|
||||
else
|
||||
@query = query
|
||||
end
|
||||
|
@ -52,7 +52,7 @@ module Webrat
|
|||
|
||||
def nokogiri_matches(stringlike)
|
||||
if Nokogiri::XML::NodeSet === stringlike
|
||||
@query = query.gsub(%r'//', './')
|
||||
@query = query.gsub(%r'^//', './/')
|
||||
else
|
||||
@query = query
|
||||
end
|
||||
|
|
|
@ -13,6 +13,7 @@ describe "have_selector" do
|
|||
<ul>
|
||||
<li>First</li>
|
||||
<li>Second</li>
|
||||
<li><a href="http://example.org/">Third</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
HTML
|
||||
|
@ -52,12 +53,12 @@ describe "have_selector" do
|
|||
|
||||
describe "specifying counts" do
|
||||
it "should be able to specify the number of occurences of the tag" do
|
||||
@body.should have_selector("li", :count => 2)
|
||||
@body.should have_selector("li", :count => 3)
|
||||
end
|
||||
|
||||
it "should not match if the count is wrong" do
|
||||
lambda {
|
||||
@body.should have_selector("li", :count => 3)
|
||||
@body.should have_selector("li", :count => 4)
|
||||
}.should raise_error(Spec::Expectations::ExpectationNotMetError)
|
||||
end
|
||||
end
|
||||
|
@ -97,6 +98,12 @@ describe "have_selector" do
|
|||
n.should have_selector("li", :content => "Second")
|
||||
end
|
||||
end
|
||||
|
||||
it "should work with descendants of the matched elements" do
|
||||
@body.should have_selector("ul") do |n|
|
||||
n.should have_selector("a", :content => "Third")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "Test::Unit assertions" do
|
||||
|
|
|
@ -13,6 +13,7 @@ describe "have_xpath" do
|
|||
<ul>
|
||||
<li>First</li>
|
||||
<li>Second</li>
|
||||
<li><a href="http://example.org">Third</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
HTML
|
||||
|
@ -88,6 +89,12 @@ describe "have_xpath" do
|
|||
}.should raise_error(Spec::Expectations::ExpectationNotMetError)
|
||||
end
|
||||
|
||||
it "should work with descendants of the matched elements" do
|
||||
@body.should have_xpath("//ul") do |node|
|
||||
node.should have_xpath("//a[@href='http://example.org']")
|
||||
end
|
||||
end
|
||||
|
||||
describe 'asserts for xpath' do
|
||||
include Test::Unit::Assertions
|
||||
|
||||
|
|
Loading…
Reference in New Issue