From 4e60f99803e0b9ab49fb368f3660438934bf1a4e Mon Sep 17 00:00:00 2001 From: shyouhei Date: Tue, 27 Sep 2016 09:19:14 +0000 Subject: * error.c: This makes all warnings raised call Warning.warn, which by default does the same thing it does currently (rb_write_error_str). You can override Warning.warn to change the behavior. [ruby-core:75016] [Feature #12299] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56269 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_exception.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb index 208c5ecfc0..3735e492d8 100644 --- a/test/ruby/test_exception.rb +++ b/test/ruby/test_exception.rb @@ -913,4 +913,31 @@ $stderr = $stdout; raise "\x82\xa0"') do |outs, errs, status| end end end + + def test_warning_warn + verbose = $VERBOSE + warning = nil + + ::Warning.class_eval do + alias_method :warn2, :warn + remove_method :warn + + define_method(:warn) do |str| + warning = str + end + end + + $VERBOSE = true + a = @a + + assert_match(/instance variable @a not initialized/, warning) + ensure + $VERBOSE = verbose + + ::Warning.class_eval do + remove_method :warn + alias_method :warn, :warn2 + remove_method :warn2 + end + end end -- cgit v1.2.3