From 1ded4dbd110868891d1255bc11845c1130a0ca3e Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 5 Aug 2011 06:55:36 +0000 Subject: * test/ruby/test_object.rb: tests that respond_to? returns false. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32857 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_object.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test') diff --git a/test/ruby/test_object.rb b/test/ruby/test_object.rb index b23a8e6498..4ce422f7b5 100644 --- a/test/ruby/test_object.rb +++ b/test/ruby/test_object.rb @@ -181,18 +181,30 @@ class TestObject < Test::Unit::TestCase o = Object.new def o.to_s; 1; end assert_raise(TypeError) { String(o) } + def o.to_s; "o"; end + assert_equal("o", String(o)) + def o.respond_to?(*) false; end + assert_raise(TypeError) { String(o) } end def test_check_convert_type o = Object.new def o.to_a; 1; end assert_raise(TypeError) { Array(o) } + def o.to_a; [1]; end + assert_equal([1], Array(o)) + def o.respond_to?(*) false; end + assert_equal([o], Array(o)) end def test_to_integer o = Object.new def o.to_i; nil; end assert_raise(TypeError) { Integer(o) } + def o.to_i; 42; end + assert_equal(42, Integer(o)) + def o.respond_to?(*) false; end + assert_raise(TypeError) { Integer(o) } end class MyInteger -- cgit v1.2.3