diff options
Diffstat (limited to 'spec/bundler/support/streams.rb')
-rw-r--r-- | spec/bundler/support/streams.rb | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/spec/bundler/support/streams.rb b/spec/bundler/support/streams.rb new file mode 100644 index 0000000000..a947eebf6f --- /dev/null +++ b/spec/bundler/support/streams.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +require "stringio" + +def capture(*args) + opts = args.pop if args.last.is_a?(Hash) + opts ||= {} + + args.map!(&:to_s) + begin + result = StringIO.new + result.close if opts[:closed] + args.each {|stream| eval "$#{stream} = result" } + yield + ensure + args.each {|stream| eval("$#{stream} = #{stream.upcase}") } + end + result.string +end |