1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/test/rake/capture_stdout.rb

25 lines
374 B
Ruby
Raw Normal View History

require 'stringio'
# Mix-in for capturing standard output.
module CaptureStdout
def capture_stdout
s = StringIO.new
oldstdout = $stdout
$stdout = s
yield
s.string
ensure
$stdout = oldstdout
end
def capture_stderr
s = StringIO.new
oldstderr = $stderr
$stderr = s
yield
s.string
ensure
$stderr = oldstderr
end
end