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

Commit 7378952

Browse files
authored
Merge pull request #598 from nevinera/nev--override-stderr-splitter-clone
Override RSpec::Support::StdErrSplitter#clone
2 parents 9a85e6e + 102d1b5 commit 7378952

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

lib/rspec/support/spec/stderr_splitter.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ def method_missing(name, *args, &block)
2121
@orig_stderr.__send__(name, *args, &block)
2222
end
2323

24+
def clone
25+
StdErrSplitter.new(@orig_stderr.clone)
26+
end
27+
2428
def ==(other)
2529
@orig_stderr == other
2630
end

spec/rspec/support/spec/stderr_splitter_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,25 @@
9595
end
9696
end
9797

98+
it 'does not reuse the stream when cloned' do
99+
expect(splitter.to_io).not_to eq(splitter.clone.to_io)
100+
end
101+
102+
# This is essentially what the `to_stderr_from_any_process` matcher attempts
103+
# to do in CaptureStreamToTempfile.
104+
it 'is able to restore the stream from a cloned StdErrSplitter', :pending => RSpec::Support::Ruby.jruby? do
105+
cloned = $stderr.clone
106+
expect($stderr.to_io).not_to be_a(File)
107+
108+
tempfile = Tempfile.new("foo")
109+
begin
110+
$stderr.reopen(tempfile)
111+
expect($stderr.to_io).to be_a(File)
112+
ensure
113+
$stderr.reopen(cloned)
114+
tempfile.close
115+
tempfile.unlink
116+
end
117+
expect($stderr.to_io).not_to be_a(File)
118+
end
98119
end

0 commit comments

Comments
 (0)