diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/spec_helper.rb | 4 | ||||
-rw-r--r-- | spec/support/capture_output_helper.rb | 22 |
2 files changed, 26 insertions, 0 deletions
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3e57e6d..9c3c7bf 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -5,5 +5,9 @@ $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir) require 'rubygems' require 'spec' +# Console redirection helper +require File.expand_path(File.join(File.dirname(__FILE__), 'support/capture_output_helper')) + Spec::Runner.configure do |config| + include CaptureOutputHelper end 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 |