diff options
author | Hrvoje Šimić <shime@twobucks.co> | 2018-03-16 11:07:02 +0100 |
---|---|---|
committer | Hrvoje Šimić <shime@twobucks.co> | 2018-03-16 12:44:50 +0100 |
commit | 29950b28af07b5b7b4215947519d5aaffe1d86f9 (patch) | |
tree | 76a8a483b9e2767f89ad7ec353b449dfcf12c131 | |
parent | 331ade5e654b4cb5cfcafff159593d2bb63d5b1b (diff) | |
download | bundler-29950b28af07b5b7b4215947519d5aaffe1d86f9.tar.gz |
fix to stop writing to stderr if closed
-rw-r--r-- | lib/bundler/ui/shell.rb | 2 | ||||
-rw-r--r-- | spec/bundler/ui/shell_spec.rb | 9 | ||||
-rw-r--r-- | spec/support/streams.rb | 12 |
3 files changed, 19 insertions, 4 deletions
diff --git a/lib/bundler/ui/shell.rb b/lib/bundler/ui/shell.rb index fdf073ffb8..16e3d15713 100644 --- a/lib/bundler/ui/shell.rb +++ b/lib/bundler/ui/shell.rb @@ -109,6 +109,8 @@ module Bundler end def tell_err(message, color = nil, newline = nil) + return if @shell.send(:stderr).closed? + newline ||= message.to_s !~ /( |\t)\Z/ message = word_wrap(message) if newline.is_a?(Hash) && newline[:wrap] diff --git a/spec/bundler/ui/shell_spec.rb b/spec/bundler/ui/shell_spec.rb index 9a47a3572f..951a446aff 100644 --- a/spec/bundler/ui/shell_spec.rb +++ b/spec/bundler/ui/shell_spec.rb @@ -59,6 +59,15 @@ RSpec.describe Bundler::UI::Shell do it "prints to stderr" do expect { subject.error("error!!!") }.to output("error!!!\n").to_stderr end + + context "when stderr is closed" do + it "doesn't report anything" do + output = capture(:stderr, :closed => true) do + subject.error("Something went wrong") + end + expect(output).to_not eq("Something went wrong\n") + end + end end end end diff --git a/spec/support/streams.rb b/spec/support/streams.rb index b9e1d292dc..a947eebf6f 100644 --- a/spec/support/streams.rb +++ b/spec/support/streams.rb @@ -2,14 +2,18 @@ require "stringio" -def capture(*streams) - streams.map!(&:to_s) +def capture(*args) + opts = args.pop if args.last.is_a?(Hash) + opts ||= {} + + args.map!(&:to_s) begin result = StringIO.new - streams.each {|stream| eval "$#{stream} = result" } + result.close if opts[:closed] + args.each {|stream| eval "$#{stream} = result" } yield ensure - streams.each {|stream| eval("$#{stream} = #{stream.upcase}") } + args.each {|stream| eval("$#{stream} = #{stream.upcase}") } end result.string end |