diff options
| author | Rizwan Reza <rizwanreza@gmail.com> | 2010-05-17 02:40:15 +0430 |
|---|---|---|
| committer | Rizwan Reza <rizwanreza@gmail.com> | 2010-05-17 02:40:15 +0430 |
| commit | d148a6f6ba5f8ee65905f12cd2601fcc377d4852 (patch) | |
| tree | 4bcb5e7ad47cfb9a9bb14ffe7c9e003d4646d64c /actionpack/lib/action_dispatch/testing/assertions | |
| parent | e1c773006969abea3c0619fbdc7e32c121b6085f (diff) | |
| parent | 6b4e0cc526f55b5532cf99292c94f0a4db53b16f (diff) | |
| download | rails-d148a6f6ba5f8ee65905f12cd2601fcc377d4852.tar.gz rails-d148a6f6ba5f8ee65905f12cd2601fcc377d4852.tar.bz2 rails-d148a6f6ba5f8ee65905f12cd2601fcc377d4852.zip | |
Merge branch 'master' of git://github.com/rails/rails
Diffstat (limited to 'actionpack/lib/action_dispatch/testing/assertions')
| -rw-r--r-- | actionpack/lib/action_dispatch/testing/assertions/selector.rb | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/actionpack/lib/action_dispatch/testing/assertions/selector.rb b/actionpack/lib/action_dispatch/testing/assertions/selector.rb index a6b1126e2b..9deabf5b3c 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/selector.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/selector.rb @@ -298,10 +298,14 @@ module ActionDispatch # found one but expecting two. message ||= content_mismatch if matches.empty? # Test minimum/maximum occurrence. - min, max = equals[:minimum], equals[:maximum] - message = message || %(Expected #{count_description(min, max)} matching "#{selector.to_s}", found #{matches.size}.) - assert matches.size >= min, message if min - assert matches.size <= max, message if max + min, max, count = equals[:minimum], equals[:maximum], equals[:count] + message = message || %(Expected #{count_description(min, max, count)} matching "#{selector.to_s}", found #{matches.size}.) + if count + assert matches.size == count, message + else + assert matches.size >= min, message if min + assert matches.size <= max, message if max + end # If a block is given call that block. Set @selected to allow # nested assert_select, which can be nested several levels deep. @@ -318,11 +322,13 @@ module ActionDispatch matches end - def count_description(min, max) #:nodoc: + def count_description(min, max, count) #:nodoc: pluralize = lambda {|word, quantity| word << (quantity == 1 ? '' : 's')} if min && max && (max != min) "between #{min} and #{max} elements" + elsif min && max && max == min && count + "exactly #{count} #{pluralize['element', min]}" elsif min && !(min == 1 && max == 1) "at least #{min} #{pluralize['element', min]}" elsif max |
