diff options
Diffstat (limited to 'spec/support/capture_output_helper.rb')
-rw-r--r-- | spec/support/capture_output_helper.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/spec/support/capture_output_helper.rb b/spec/support/capture_output_helper.rb new file mode 100644 index 0000000..363a57c --- /dev/null +++ b/spec/support/capture_output_helper.rb @@ -0,0 +1,22 @@ +module CaptureOutputHelper + def capture_output(&block) + old_stdout = $stdout + old_stderr = $stderr + + stream_out = StringIO.new + stream_err = StringIO.new + + begin + $stdout = stream_out + $stderr = stream_err + yield + ensure + $stdout = old_stdout + $stderr = old_stderr + end + stream_out.rewind + stream_err.rewind + + [stream_out.read, stream_err.read] + end +end |