diff --git a/lib/webrat/core/matchers/have_xpath.rb b/lib/webrat/core/matchers/have_xpath.rb
index 92adc38..efc9a8d 100644
--- a/lib/webrat/core/matchers/have_xpath.rb
+++ b/lib/webrat/core/matchers/have_xpath.rb
@@ -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
diff --git a/spec/public/matchers/have_selector_spec.rb b/spec/public/matchers/have_selector_spec.rb
index aad8e48..d7008a9 100644
--- a/spec/public/matchers/have_selector_spec.rb
+++ b/spec/public/matchers/have_selector_spec.rb
@@ -13,6 +13,7 @@ describe "have_selector" do
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
diff --git a/spec/public/matchers/have_xpath_spec.rb b/spec/public/matchers/have_xpath_spec.rb
index 5fe9282..c51e385 100644
--- a/spec/public/matchers/have_xpath_spec.rb
+++ b/spec/public/matchers/have_xpath_spec.rb
@@ -13,6 +13,7 @@ describe "have_xpath" do
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