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 @block ||= block
matched = matches(stringlike) matched = matches(stringlike)
@block.call(matched) if @block
if @options[:count] if @options[:count]
matched.size == @options[:count].to_i && (!@block || @block.call(matched)) matched.size == @options[:count].to_i
else else
matched.any? && (!@block || @block.call(matched)) matched.any?
end end
end end

View File

@ -89,6 +89,12 @@ describe "have_xpath" do
}.should raise_error(Spec::Expectations::ExpectationNotMetError) }.should raise_error(Spec::Expectations::ExpectationNotMetError)
end 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 it "should match descendants of the matched elements in the block" do
@body.should have_xpath("//ul") do |node| @body.should have_xpath("//ul") do |node|
node.should have_xpath("//a[@href='http://example.org']") node.should have_xpath("//a[@href='http://example.org']")