summaryrefslogtreecommitdiff
path: root/test/ruby/test_object.rb
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2020-12-17 20:06:18 +0900
committerGitHub <noreply@github.com>2020-12-17 20:06:18 +0900
commit9908177857a28633d6279c43a1ad4dfedcb98596 (patch)
tree400f3c07584b9d87129ec24c42ccb436095f2803 /test/ruby/test_object.rb
parentd597d7a8b6e753cfe40b8470c770f744adde5d4f (diff)
test/ruby: Check warning messages at a finer granularity
Instead of suppressing all warnings wholly in each test scripts by setting `$VERBOSE` to `nil` in `setup` methods.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3925 Merged-By: nobu <nobu@ruby-lang.org>
Diffstat (limited to 'test/ruby/test_object.rb')
-rw-r--r--test/ruby/test_object.rb7
1 files changed, 5 insertions, 2 deletions
diff --git a/test/ruby/test_object.rb b/test/ruby/test_object.rb
index 782ae6ac72..774b707742 100644
--- a/test/ruby/test_object.rb
+++ b/test/ruby/test_object.rb
@@ -5,7 +5,6 @@ require 'test/unit'
class TestObject < Test::Unit::TestCase
def setup
@verbose = $VERBOSE
- $VERBOSE = nil
end
def teardown
@@ -360,6 +359,7 @@ class TestObject < Test::Unit::TestCase
o = Object.new
def o.to_s; 1; end
assert_raise(TypeError) { String(o) }
+ o.singleton_class.remove_method(:to_s)
def o.to_s; "o"; end
assert_equal("o", String(o))
def o.to_str; "O"; end
@@ -372,6 +372,7 @@ class TestObject < Test::Unit::TestCase
o = Object.new
def o.to_a; 1; end
assert_raise(TypeError) { Array(o) }
+ o.singleton_class.remove_method(:to_a)
def o.to_a; [1]; end
assert_equal([1], Array(o))
def o.to_ary; [2]; end
@@ -389,6 +390,7 @@ class TestObject < Test::Unit::TestCase
o = Object.new
def o.to_hash; {a: 1, b: 2}; end
assert_equal({a: 1, b: 2}, Hash(o))
+ o.singleton_class.remove_method(:to_hash)
def o.to_hash; 9; end
assert_raise(TypeError) { Hash(o) }
end
@@ -397,6 +399,7 @@ class TestObject < Test::Unit::TestCase
o = Object.new
def o.to_i; nil; end
assert_raise(TypeError) { Integer(o) }
+ o.singleton_class.remove_method(:to_i)
def o.to_i; 42; end
assert_equal(42, Integer(o))
def o.respond_to?(*) false; end
@@ -631,7 +634,7 @@ class TestObject < Test::Unit::TestCase
called = []
p.singleton_class.class_eval do
- define_method(:respond_to?) do |a|
+ define_method(:respond_to?) do |a, priv = false|
called << [:respond_to?, a]
false
end