Fix have_xpath not matching negative expectation in the block.

[#182 state:resolved]
This commit is contained in:
Luismi Cavalle 2009-04-14 00:11:01 +02:00 committed by Damian Janowski
parent 107bdf7cf9
commit 43b19eeafa
2 changed files with 10 additions and 2 deletions

View File

@ -14,10 +14,12 @@ module Webrat
@block ||= block
matched = matches(stringlike)
@block.call(matched) if @block
if @options[:count]
matched.size == @options[:count].to_i && (!@block || @block.call(matched))
matched.size == @options[:count].to_i
else
matched.any? && (!@block || @block.call(matched))
matched.any?
end
end

View File

@ -89,6 +89,12 @@ describe "have_xpath" do
}.should raise_error(Spec::Expectations::ExpectationNotMetError)
end
it "should match negative expectations in the block" do
@body.should have_xpath("//div") do |node|
node.should_not have_xpath("//div[@id='main']")
end
end
it "should match descendants of the matched elements in the block" do
@body.should have_xpath("//ul") do |node|
node.should have_xpath("//a[@href='http://example.org']")