Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Don’t re-close a closed output stream. #1545

Merged
merged 1 commit into from
May 22, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
5 changes: 4 additions & 1 deletion lib/rspec/core/formatters/base_text_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions spec/rspec/core/formatters/base_text_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down