mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Kernel#open may be redefined
This commit is contained in:
parent
617fa3049a
commit
81191afe8a
1 changed files with 13 additions and 2 deletions
|
@ -2283,13 +2283,24 @@ class TestIO < Test::Unit::TestCase
|
||||||
o = Object.new
|
o = Object.new
|
||||||
def o.to_open(**kw); kw; end
|
def o.to_open(**kw); kw; end
|
||||||
assert_equal({:a=>1}, open(o, a: 1))
|
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}))
|
assert_equal({:a=>1}, open(o, {a: 1}))
|
||||||
end
|
end
|
||||||
|
|
||||||
def o.to_open(kw); kw; end
|
def o.to_open(kw); kw; end
|
||||||
assert_equal({:a=>1}, open(o, a: 1))
|
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
|
end
|
||||||
|
|
||||||
def test_open_pipe
|
def test_open_pipe
|
||||||
|
|
Loading…
Add table
Reference in a new issue