[ruby/tempfile] Make Tempfile#open return the underlying File
Add test for this behavior. https://github.com/ruby/tempfile/commit/0ca31a6b8d
This commit is contained in:
parent
eb2abc3f16
commit
ddd99a5290
@ -191,6 +191,7 @@ class Tempfile < DelegateClass(File)
|
||||
mode = @mode & ~(File::CREAT|File::EXCL)
|
||||
__setobj__(File.open(__getobj__.path, mode, **@opts))
|
||||
ObjectSpace.define_finalizer(self, Closer.new(__getobj__))
|
||||
__getobj__
|
||||
end
|
||||
|
||||
def _close # :nodoc:
|
||||
|
@ -378,6 +378,14 @@ puts Tempfile.new('foo').path
|
||||
assert_file.not_exist?(path)
|
||||
end
|
||||
|
||||
def test_open
|
||||
Tempfile.open {|f|
|
||||
file = f.open
|
||||
assert_kind_of File, file
|
||||
assert_equal f.to_i, file.to_i
|
||||
}
|
||||
end
|
||||
|
||||
def test_open_traversal_dir
|
||||
assert_mktmpdir_traversal do |traversal_path|
|
||||
t = Tempfile.open([traversal_path, 'foo'])
|
||||
|
Loading…
x
Reference in New Issue
Block a user