diff --git a/lib/webrat/core/matchers/have_xpath.rb b/lib/webrat/core/matchers/have_xpath.rb index 7256109..71ac4b0 100644 --- a/lib/webrat/core/matchers/have_xpath.rb +++ b/lib/webrat/core/matchers/have_xpath.rb @@ -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 diff --git a/spec/public/matchers/have_xpath_spec.rb b/spec/public/matchers/have_xpath_spec.rb index e1c880e..144c6d5 100644 --- a/spec/public/matchers/have_xpath_spec.rb +++ b/spec/public/matchers/have_xpath_spec.rb @@ -88,6 +88,12 @@ describe "have_xpath" do end }.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|