aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext/array
diff options
context:
space:
mode:
authorXavier Shay <xavier@rhnh.net>2014-07-30 20:00:31 -0700
committerXavier Shay <xavier@rhnh.net>2014-07-30 20:39:53 -0700
commitacac631cc9a8a0b72e8daf6ab8ad4b1f6f0667bf (patch)
tree2d08e6a4c44443201d3fe1c5f8b41aa6756b313d /activesupport/test/core_ext/array
parent29a6a17a11cd98f18ad46e882cc8f7fd669de59f (diff)
downloadrails-acac631cc9a8a0b72e8daf6ab8ad4b1f6f0667bf.tar.gz
rails-acac631cc9a8a0b72e8daf6ab8ad4b1f6f0667bf.tar.bz2
rails-acac631cc9a8a0b72e8daf6ab8ad4b1f6f0667bf.zip
Raise a descriptive error if non-positive integer passed to in_groups_of.
This is more consistent than the current behaviour of raising a `ZeroDivisionError: divided by 0` error when 0 is given, which can be non-obvious especially if `in_groups_of` is part of a longer chain of methods. The negative case was ok - "ArgumentError: invalid slice size" - but this error is clearer still.
Diffstat (limited to 'activesupport/test/core_ext/array')
-rw-r--r--activesupport/test/core_ext/array/grouping_test.rb6
1 files changed, 6 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/array/grouping_test.rb b/activesupport/test/core_ext/array/grouping_test.rb
index b8cfe9728c..2eb0f05141 100644
--- a/activesupport/test/core_ext/array/grouping_test.rb
+++ b/activesupport/test/core_ext/array/grouping_test.rb
@@ -90,6 +90,12 @@ class GroupingTest < ActiveSupport::TestCase
assert_equal [[1, 2, 3], [4, 5], [6, 7]],
(1..7).to_a.in_groups(3, false)
end
+
+ def test_in_groups_invalid_argument
+ assert_raises(ArgumentError) { [].in_groups_of(0) }
+ assert_raises(ArgumentError) { [].in_groups_of(-1) }
+ assert_raises(ArgumentError) { [].in_groups_of(nil) }
+ end
end
class SplitTest < ActiveSupport::TestCase