Skip to content

Commit

Permalink
support have_tag(".foo", :count => 0)
Browse files Browse the repository at this point in the history
  • Loading branch information
pd committed Mar 11, 2008
1 parent 72534ea commit 54f6522
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/rspec_hpricot_matchers/have_tag.rb
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions spec/rspec_hpricot_matchers/have_tag_spec.rb
Expand Up @@ -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)
Expand Down

0 comments on commit 54f6522

Please sign in to comment.