diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-09-27 01:13:10 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-09-27 01:13:10 +0900 |
commit | 81191afe8a9b40e6dd6cc8e0d1a9899938840073 (patch) | |
tree | ca16f18d09ebdd141f016c3f4bf761c9b38d84c2 /test/ruby/test_io.rb | |
parent | 617fa3049a151d773bb26151ae774a8f6a60bc2a (diff) | |
download | ruby-81191afe8a9b40e6dd6cc8e0d1a9899938840073.tar.gz |
Kernel#open may be redefined
Diffstat (limited to 'test/ruby/test_io.rb')
-rw-r--r-- | test/ruby/test_io.rb | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index 280d11f786..6a27b5dc93 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -2283,13 +2283,24 @@ class TestIO < Test::Unit::TestCase o = Object.new def o.to_open(**kw); kw; end assert_equal({:a=>1}, open(o, a: 1)) - assert_warn(/The last argument is used as the keyword parameter.*for `to_open'/m) do + + w = /The last argument is used as the keyword parameter.*for `(to_)?open'/m + redefined = nil + w.singleton_class.define_method(:===) do |s| + match = super(s) + redefined = !$1 + match + end + + assert_warn(w) do assert_equal({:a=>1}, open(o, {a: 1})) end def o.to_open(kw); kw; end assert_equal({:a=>1}, open(o, a: 1)) - assert_equal({:a=>1}, open(o, {a: 1})) + unless redefined + assert_equal({:a=>1}, open(o, {a: 1})) + end end def test_open_pipe |