Skip to content
Browse files

Abstract check for length of matches into method

  • Loading branch information...
1 parent 3ad46c6 commit 3e424a45db480502c97d3f13ffd92523ee9b1c26 Chris Apolzon committed Mar 23, 2012
Showing with 10 additions and 1 deletion.
  1. +10 −1 lib/rspec/tag_matchers/has_tag.rb
View
11 lib/rspec/tag_matchers/has_tag.rb
@@ -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+
@@ -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]

0 comments on commit 3e424a4

Please sign in to comment.
Something went wrong with that request. Please try again.