From ed014683e8f567ff6d4d576ea86f476a8c829f0a Mon Sep 17 00:00:00 2001 From: Myron Marston Date: Thu, 22 May 2014 09:51:26 -0700 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20re-close=20a=20closed=20output?= =?UTF-8?q?=20stream.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #1541 for 3.0. --- Changelog.md | 8 ++++++++ lib/rspec/core/formatters/base_text_formatter.rb | 5 ++++- spec/rspec/core/formatters/base_text_formatter_spec.rb | 10 ++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index e8a5e2425b..bf2f77c54c 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,11 @@ +### 3.0.0 Development +[Full Changelog](http://github.com/rspec/rspec-core/compare/v3.0.0.rc1...master) + +Bug Fixes: + +* Fix `BaseTextFormatter` so that it does not re-close a closed output + stream. (Myron Marston) + ### 3.0.0.rc1 / 2014-05-18 [Full Changelog](http://github.com/rspec/rspec-core/compare/v3.0.0.beta2...v3.0.0.rc1) diff --git a/lib/rspec/core/formatters/base_text_formatter.rb b/lib/rspec/core/formatters/base_text_formatter.rb index dbceb2b386..cb3bcde6c9 100644 --- a/lib/rspec/core/formatters/base_text_formatter.rb +++ b/lib/rspec/core/formatters/base_text_formatter.rb @@ -66,7 +66,10 @@ def seed(notification) # # @param notification [NullNotification] def close(notification) - output.close if IO === output && output != $stdout + return unless IO === output + return if output.closed? || output == $stdout + + output.close end end diff --git a/spec/rspec/core/formatters/base_text_formatter_spec.rb b/spec/rspec/core/formatters/base_text_formatter_spec.rb index 14e24a72e9..f6d8132379 100644 --- a/spec/rspec/core/formatters/base_text_formatter_spec.rb +++ b/spec/rspec/core/formatters/base_text_formatter_spec.rb @@ -4,6 +4,16 @@ RSpec.describe RSpec::Core::Formatters::BaseTextFormatter do include FormatterSupport + context "when closing the formatter", :isolated_directory => true do + it 'does not close an already closed output stream' do + output = File.new("./output_to_close", "w") + formatter = described_class.new(output) + output.close + + expect { formatter.close(RSpec::Core::Notifications::NullNotification) }.not_to raise_error + end + end + describe "#dump_summary" do it "with 0s outputs pluralized (excluding pending)" do send_notification :dump_summary, summary_notification(0, [], [], [], 0)