Module: OStreamCatcher
- Extended by:
- OStreamCatcher
- Included in:
- OStreamCatcher
- Defined in:
- lib/o_stream_catcher.rb,
lib/o_stream_catcher/version.rb,
lib/o_stream_catcher/o_stream_catcher.rb
Constant Summary collapse
- VERSION =
"0.0.1"
Instance Method Summary collapse
Instance Method Details
#catch(&block) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/o_stream_catcher/o_stream_catcher.rb', line 3 def catch(&block) stdout_orig, stdout_mock = mock_stdout stderr_orig, stderr_mock = mock_stderr stderr_orig = $stderr stderr_mock = StringIO.new $stderr = stderr_mock begin result = block.call ensure $stdout = stdout_orig $stderr = stderr_orig end [result, stdout_mock.string, stderr_mock.string] end |