aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/testing
diff options
context:
space:
mode:
authorTimm <kaspth@gmail.com>2013-07-20 20:07:04 +0200
committerTimm <kaspth@gmail.com>2014-06-15 23:40:59 +0200
commit332ccb35a19987d826ccf000238aa61c1db80de6 (patch)
tree053ee1f09afbb61ba07a94298bd3aee960686189 /actionpack/lib/action_dispatch/testing
parent95afa79439c4f241e2eb68c6f838c355b9f6535e (diff)
downloadrails-332ccb35a19987d826ccf000238aa61c1db80de6.tar.gz
rails-332ccb35a19987d826ccf000238aa61c1db80de6.tar.bz2
rails-332ccb35a19987d826ccf000238aa61c1db80de6.zip
Added assert_size_match! with the assertions for assert_select.
Diffstat (limited to 'actionpack/lib/action_dispatch/testing')
-rw-r--r--actionpack/lib/action_dispatch/testing/assertions/selector.rb32
1 files changed, 18 insertions, 14 deletions
diff --git a/actionpack/lib/action_dispatch/testing/assertions/selector.rb b/actionpack/lib/action_dispatch/testing/assertions/selector.rb
index 3f2037eaea..2488e761f1 100644
--- a/actionpack/lib/action_dispatch/testing/assertions/selector.rb
+++ b/actionpack/lib/action_dispatch/testing/assertions/selector.rb
@@ -175,21 +175,10 @@ module ActionDispatch
# found one but expecting two.
message = filter.message
message ||= content_mismatch if matches.empty?
- # Test minimum/maximum occurrence.
- min, max, count = equals[:minimum], equals[:maximum], equals[:count]
-
- # FIXME: minitest provides messaging when we use assert_operator,
- # so is this custom message really needed?
- message = message || %(Expected #{count_description(min, max, count)} matching "#{selector.to_s}", found #{matches.size})
- if count
- assert_equal count, matches.size, message
- else
- assert_operator matches.size, :>=, min, message if min
- assert_operator matches.size, :<=, max, message if max
- end
+ assert_size_match!(matches.size, equals, selector, message)
- # If a block is given call that block. Set @selected to allow
- # nested assert_select, which can be nested several levels deep.
+ # Set @selected to allow nested assert_select.
+ # Can be nested several levels deep.
if block_given? && !matches.empty?
begin
in_scope, @selected = @selected, matches
@@ -325,6 +314,21 @@ module ActionDispatch
end
end
+ # +equals+ must contain :minimum, :maximum and :count keys
+ def assert_size_match!(size, equals, selector, message = nil)
+ min, max, count = equals[:minimum], equals[:maximum], equals[:count]
+
+ # FIXME: minitest provides messaging when we use assert_operator,
+ # so is this custom message really needed?
+ message ||= %(Expected #{count_description(min, max, count)} matching "#{selector.to_s}", found #{size}.)
+ if count
+ assert_equal size, count, message
+ else
+ assert_operator size, :>=, min, message if min
+ assert_operator size, :<=, max, message if max
+ end
+ end
+
def response_from_page
@html_document ||= if @response.content_type =~ /xml$/
Loofah.xml_document(@response.body)