From 43b19eeafa44311b01d4755c43a74972dea07302 Mon Sep 17 00:00:00 2001 From: Luismi Cavalle Date: Tue, 14 Apr 2009 00:11:01 +0200 Subject: [PATCH] Fix have_xpath not matching negative expectation in the block. [#182 state:resolved] --- lib/webrat/core/matchers/have_xpath.rb | 6 ++++-- spec/public/matchers/have_xpath_spec.rb | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) 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|