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

Commit 4d06fb4

Browse files
committed
Merge pull request #1545 from rspec/fix-1541-for-3.0
Don’t re-close a closed output stream.
2 parents c5b5fcf + ed01468 commit 4d06fb4

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

Changelog.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
### 3.0.0 Development
2+
[Full Changelog](http://github.com/rspec/rspec-core/compare/v3.0.0.rc1...master)
3+
4+
Bug Fixes:
5+
6+
* Fix `BaseTextFormatter` so that it does not re-close a closed output
7+
stream. (Myron Marston)
8+
19
### 3.0.0.rc1 / 2014-05-18
210
[Full Changelog](http://github.com/rspec/rspec-core/compare/v3.0.0.beta2...v3.0.0.rc1)
311

lib/rspec/core/formatters/base_text_formatter.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ def seed(notification)
6666
#
6767
# @param notification [NullNotification]
6868
def close(notification)
69-
output.close if IO === output && output != $stdout
69+
return unless IO === output
70+
return if output.closed? || output == $stdout
71+
72+
output.close
7073
end
7174

7275
end

spec/rspec/core/formatters/base_text_formatter_spec.rb

+10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44
RSpec.describe RSpec::Core::Formatters::BaseTextFormatter do
55
include FormatterSupport
66

7+
context "when closing the formatter", :isolated_directory => true do
8+
it 'does not close an already closed output stream' do
9+
output = File.new("./output_to_close", "w")
10+
formatter = described_class.new(output)
11+
output.close
12+
13+
expect { formatter.close(RSpec::Core::Notifications::NullNotification) }.not_to raise_error
14+
end
15+
end
16+
717
describe "#dump_summary" do
818
it "with 0s outputs pluralized (excluding pending)" do
919
send_notification :dump_summary, summary_notification(0, [], [], [], 0)

0 commit comments

Comments
 (0)