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

Commit 6cd89ef

Browse files
committed
Merge pull request #68 from rspec/fix-with-isolated-stderr
Fix `with_isolated_stderr` so it does not leak.
2 parents 69e4717 + 3bb4fcc commit 6cd89ef

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/rspec/support/spec/with_isolated_stderr.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ def with_isolated_stderr
66
original = $stderr
77
$stderr = StringIO.new
88
yield
9+
ensure
910
$stderr = original
1011
end
1112

spec/rspec/support/spec/with_isolated_std_err_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,14 @@
88
$stderr.puts "Imma gonna warn you"
99
end
1010
end
11+
12+
it 'resets $stderr to its original value even if an error is raised' do
13+
orig_stderr = $stderr
14+
15+
expect {
16+
with_isolated_stderr { raise "boom" }
17+
}.to raise_error("boom")
18+
19+
expect($stderr).to be(orig_stderr)
20+
end
1121
end

0 commit comments

Comments
 (0)