aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-25 01:40:15 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-25 01:40:15 +0000
commit3a3d1676558fee264e28ab52de2e1654b73d1d9a (patch)
tree401a744bf49a200f1cd80a27e26ff5264107deaf /test
parent10d546c62d3c62cca5ea4ca34dfd55e6c9478dac (diff)
downloadruby-3a3d1676558fee264e28ab52de2e1654b73d1d9a.tar.gz
range.c: check if exclude_end? is defined
* range.c (rb_range_values): should raise TypeError if necessary method is not defined, not NoMethodError, when trying to tell if the object is a Range and extract info. [ruby-core:83541] [Bug #14048] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60411 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_enum.rb13
-rw-r--r--test/ruby/test_range.rb2
2 files changed, 14 insertions, 1 deletions
diff --git a/test/ruby/test_enum.rb b/test/ruby/test_enum.rb
index fcf601c183..ae119c73bf 100644
--- a/test/ruby/test_enum.rb
+++ b/test/ruby/test_enum.rb
@@ -966,6 +966,19 @@ class TestEnumerable < Test::Unit::TestCase
assert_int_equal(5, (2..0).sum(5))
assert_int_equal(2, (2..2).sum)
assert_int_equal(42, (2...2).sum(42))
+
+ not_a_range = Class.new do
+ include Enumerable # Defines the `#sum` method
+ def each
+ yield 2
+ yield 4
+ yield 6
+ end
+
+ def begin; end
+ def end; end
+ end
+ assert_equal(12, not_a_range.new.sum)
end
def test_uniq
diff --git a/test/ruby/test_range.rb b/test/ruby/test_range.rb
index 66c4682d8d..5823810f33 100644
--- a/test/ruby/test_range.rb
+++ b/test/ruby/test_range.rb
@@ -387,7 +387,7 @@ class TestRange < Test::Unit::TestCase
assert_raise(TypeError) { [][o] }
class << o; attr_accessor :end end
o.end = 0
- assert_raise(NoMethodError) { [][o] }
+ assert_raise(TypeError) { [][o] }
def o.exclude_end=(v) @exclude_end = v end
def o.exclude_end?() @exclude_end end
o.exclude_end = false