summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorLuis Lavena <luislavena@gmail.com>2009-04-09 20:33:56 -0300
committerLuis Lavena <luislavena@gmail.com>2009-04-09 20:33:56 -0300
commit491d6a9237b1647eb1d47ba3a1b2c122431908c5 (patch)
tree78714c07a933db33df119ba93c3ff1bb71eee6be /spec
parentc9bd9939ee607e68ae79b2af70009a7c61f0f8aa (diff)
downloadrake-compiler-491d6a9237b1647eb1d47ba3a1b2c122431908c5.tar.gz
Added Console redirection helper
The idea is be able to capture output from OUT and ERR in the specs.
Diffstat (limited to 'spec')
-rw-r--r--spec/spec_helper.rb4
-rw-r--r--spec/support/capture_output_helper.rb22
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