From 54f6522b2c0be754131ce1ee491c6245a34a174d Mon Sep 17 00:00:00 2001 From: Kyle Hargraves Date: Mon, 10 Mar 2008 19:47:05 -0500 Subject: [PATCH] support have_tag(".foo", :count => 0) --- lib/rspec_hpricot_matchers/have_tag.rb | 4 +++- spec/rspec_hpricot_matchers/have_tag_spec.rb | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/rspec_hpricot_matchers/have_tag.rb b/lib/rspec_hpricot_matchers/have_tag.rb index 0db37d5..86eb95a 100644 --- a/lib/rspec_hpricot_matchers/have_tag.rb +++ b/lib/rspec_hpricot_matchers/have_tag.rb @@ -16,7 +16,9 @@ def matches?(actual, &block) @hdoc = hdoc_for(@actual) matched_elements = @hdoc.search(@selector) - return false if matched_elements.empty? + if matched_elements.empty? + return @options[:count] == 0 + end if @inner_text matched_elements = filter_on_inner_text(matched_elements) diff --git a/spec/rspec_hpricot_matchers/have_tag_spec.rb b/spec/rspec_hpricot_matchers/have_tag_spec.rb index f4bf28e..2238a96 100644 --- a/spec/rspec_hpricot_matchers/have_tag_spec.rb +++ b/spec/rspec_hpricot_matchers/have_tag_spec.rb @@ -157,6 +157,10 @@ def body @html.should_not have_tag('li', :count => 2..3) end + it "should treat a :count of zero as if a negative match were expected" do + @html.should have_tag('dd', :count => 0) + end + it "should treat :minimum as expecting at least n matched elements" do (0..4).each { |n| @html.should have_tag('li', :minimum => n) } @html.should_not have_tag('li', :minimum => 5)