Sha256: 82b76f6bf8e5ca69abeaddaff7ac22a45c1d2a153c26c27609395597f449385e
Contents?: true
Size: 1.23 KB
Versions: 2
Compression:
Stored size: 1.23 KB
Contents
module Micron module Util module IO # Captures $stdout and $stderr into strings: # # out, err = capture_io do # puts "Some info" # warn "You did a bad thing" # end # # assert_match %r%info%, out # assert_match %r%bad%, err # # NOTE: For efficiency, this method uses StringIO and does not # capture IO for subprocesses. Use #capture_subprocess_io for # that. def capture_io require 'stringio' captured_stdout, captured_stderr = StringIO.new, StringIO.new # synchronize do orig_stdout, orig_stderr = $stdout, $stderr $stdout, $stderr = captured_stdout, captured_stderr begin yield ensure $stdout = orig_stdout $stderr = orig_stderr end # end return captured_stdout.string, captured_stderr.string end # Dispose of STDOUT/STDERR # # @param [Array<IO>] out # @param [Array<IO>] err def dispose_io(out, err) STDOUT.reopen out.last out.last.close STDERR.reopen err.last err.last.close STDOUT.sync = STDERR.sync = true end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
micron-0.5.1 | lib/micron/util/io.rb |
micron-0.5.0 | lib/micron/util/io.rb |