Skip to content

Commit

Permalink
Abstract check for length of matches into method
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Apolzon committed Mar 24, 2012
1 parent 3ad46c6 commit 3e424a4
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/rspec/tag_matchers/has_tag.rb
Expand Up @@ -133,7 +133,7 @@ def matches?(rendered)
matches = Nokogiri::HTML::Document.parse(@rendered.to_s).css(@name).select do |element|
matches_attributes?(element) && matches_criteria?(element)
end
return true if (@count.nil? && matches.length > 0) || matches.length == @count
return matches_count?(matches)
end

# Adds a constraint that the matched elements must match certain attributes. The +attributes+
Expand Down Expand Up @@ -254,6 +254,15 @@ def matches_criteria?(element)
end
end

# Answers whether or not +element+ appears the number of times set by {#with_count}.
#
# @param [[Nokogiri::XML::Node]] matches The matched elements to be tested.
#
# @return [Boolean]
def matches_count?(matches)
true if (@count.nil? && matches.length > 0) || matches.length == @count
end

# Provides extra description that can be appended to the basic description.
#
# @return [String]
Expand Down

0 comments on commit 3e424a4

Please sign in to comment.