spec/spec_helper.rb in rubabel-0.1.0 vs spec/spec_helper.rb in rubabel-0.1.1
- old
+ new
@@ -1,6 +1,7 @@
require 'rspec'
+require 'stringio'
# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
#Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
@@ -8,5 +9,28 @@
config.formatter = :documentation
config.color = true
end
TESTFILES = File.dirname(__FILE__) + "/testfiles"
+
+module Kernel
+ # from: http://thinkingdigitally.com/archive/capturing-output-from-puts-in-ruby/
+ def capture_stdout
+ out = StringIO.new
+ $stdout = out
+ yield
+ return out.string
+ ensure
+ $stdout = STDOUT
+ end
+
+ def capture_stderr
+ out = StringIO.new
+ $stderr = out
+ yield
+ return out.string
+ ensure
+ $stderr = STDERR
+ end
+
+
+end