提交 6f9d97cd 编写于 作者: C Carlos Antonio da Silva

Merge pull request #12684 from mariovisic/fix_kernel_silence_stream_descriptor_leak

Fix issue with Kernel#silence_stream leaking file descriptors
* Fix file descriptor being leaked on each call to `Kernel.silence_stream`
*Mario Visic*
* Ensure `config.i18n.enforce_available_locales` is set before any other
configuration option.
......
......@@ -48,6 +48,7 @@ def silence_stream(stream)
yield
ensure
stream.reopen(old_stream)
old_stream.close
end
# Blocks and ignores any exception passed as argument if raised within the block.
......
......@@ -38,6 +38,22 @@ def test_silence_stderr
# Skip if we can't STDERR.tell
end
def test_silence_stream
old_stream_position = STDOUT.tell
silence_stream(STDOUT) { STDOUT.puts 'hello world' }
assert_equal old_stream_position, STDOUT.tell
rescue Errno::ESPIPE
# Skip if we can't stream.tell
end
def test_silence_stream_closes_file_descriptors
stream = StringIO.new
dup_stream = StringIO.new
stream.stubs(:dup).returns(dup_stream)
dup_stream.expects(:close)
silence_stream(stream) { stream.puts 'hello world' }
end
def test_quietly
old_stdout_position, old_stderr_position = STDOUT.tell, STDERR.tell
quietly do
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册