Method: MiniTest::Assertions#capture_io
- Defined in:
- lib/minitest/unit.rb
#capture_io ⇒ Object
Captures $stdout and $stderr into strings:
out, err = capture_io do
warn "You did a bad thing"
end
assert_match %r%bad%, err
323 324 325 326 327 328 329 330 331 332 333 334 335 336 |
# File 'lib/minitest/unit.rb', line 323 def capture_io require 'stringio' orig_stdout, orig_stderr = $stdout, $stderr captured_stdout, captured_stderr = StringIO.new, StringIO.new $stdout, $stderr = captured_stdout, captured_stderr yield return captured_stdout.string, captured_stderr.string ensure $stdout = orig_stdout $stderr = orig_stderr end |