diff options
Diffstat (limited to 'activesupport/test/core_ext/enumerable_test.rb')
-rw-r--r-- | activesupport/test/core_ext/enumerable_test.rb | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/enumerable_test.rb b/activesupport/test/core_ext/enumerable_test.rb index 885393815b..66507d4652 100644 --- a/activesupport/test/core_ext/enumerable_test.rb +++ b/activesupport/test/core_ext/enumerable_test.rb @@ -1,5 +1,6 @@ require 'abstract_unit' require 'active_support/core_ext/array' +require 'active_support/core_ext/symbol' require 'active_support/core_ext/enumerable' Payment = Struct.new(:price) @@ -60,6 +61,14 @@ class EnumerableTests < Test::Unit::TestCase assert_equal Payment.new(0), [].sum(Payment.new(0)) end + def test_enumerable_sums + assert_equal 20, (1..4).sum { |i| i * 2 } + assert_equal 10, (1..4).sum + assert_equal 6, (1...4).sum + assert_equal 'abc', ('a'..'c').sum + assert_raises(NoMethodError) { 1..2.5.sum } + end + def test_each_with_object result = %w(foo bar).each_with_object({}) { |str, hsh| hsh[str] = str.upcase } assert_equal({'foo' => 'FOO', 'bar' => 'BAR'}, result) |