summaryrefslogtreecommitdiff
path: root/spec/spec_helper.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/spec_helper.rb')
-rw-r--r--spec/spec_helper.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 4899c49..e566d0e 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -40,6 +40,38 @@ parent = path.parent
$:.unshift parent.join('lib')
+module CaptureSubprocessIO
+ def _synchronize
+ yield
+ end
+
+ def capture_subprocess_io
+ _synchronize do
+ begin
+ require 'tempfile'
+
+ captured_stdout, captured_stderr = Tempfile.new('out'), Tempfile.new('err')
+
+ orig_stdout, orig_stderr = $stdout.dup, $stderr.dup
+ $stdout.reopen captured_stdout
+ $stderr.reopen captured_stderr
+
+ yield
+
+ $stdout.rewind
+ $stderr.rewind
+
+ return captured_stdout.read, captured_stderr.read
+ ensure
+ captured_stdout.unlink
+ captured_stderr.unlink
+ $stdout.reopen orig_stdout
+ $stderr.reopen orig_stderr
+ end
+ end
+ end
+end
+
require 'diff-lcs'
module Diff::LCS::SpecHelper