From 332ccb35a19987d826ccf000238aa61c1db80de6 Mon Sep 17 00:00:00 2001 From: Timm Date: Sat, 20 Jul 2013 20:07:04 +0200 Subject: Added assert_size_match! with the assertions for assert_select. --- .../action_dispatch/testing/assertions/selector.rb | 32 ++++++++++++---------- 1 file 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) -- cgit v1.2.3