aboutsummaryrefslogtreecommitdiffstats
path: root/spec/bundler/support/streams.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/bundler/support/streams.rb')
-rw-r--r--spec/bundler/support/streams.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/spec/bundler/support/streams.rb b/spec/bundler/support/streams.rb
new file mode 100644
index 0000000000..561b29092b
--- /dev/null
+++ b/spec/bundler/support/streams.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+require "stringio"
+
+def capture(*streams)
+ streams.map!(&:to_s)
+ begin
+ result = StringIO.new
+ streams.each {|stream| eval "$#{stream} = result" }
+ yield
+ ensure
+ streams.each {|stream| eval("$#{stream} = #{stream.upcase}") }
+ end
+ result.string
+end