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

Commit

Permalink
Merge pull request #598 from nevinera/nev--override-stderr-splitter-c…
Browse files Browse the repository at this point in the history
…lone

Override RSpec::Support::StdErrSplitter#clone
  • Loading branch information
pirj authored Aug 18, 2024
2 parents 9a85e6e + 102d1b5 commit 7378952
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/rspec/support/spec/stderr_splitter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ def method_missing(name, *args, &block)
@orig_stderr.__send__(name, *args, &block)
end

def clone
StdErrSplitter.new(@orig_stderr.clone)
end

def ==(other)
@orig_stderr == other
end
Expand Down
21 changes: 21 additions & 0 deletions spec/rspec/support/spec/stderr_splitter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,25 @@
end
end

it 'does not reuse the stream when cloned' do
expect(splitter.to_io).not_to eq(splitter.clone.to_io)
end

# This is essentially what the `to_stderr_from_any_process` matcher attempts
# to do in CaptureStreamToTempfile.
it 'is able to restore the stream from a cloned StdErrSplitter', :pending => RSpec::Support::Ruby.jruby? do
cloned = $stderr.clone
expect($stderr.to_io).not_to be_a(File)

tempfile = Tempfile.new("foo")
begin
$stderr.reopen(tempfile)
expect($stderr.to_io).to be_a(File)
ensure
$stderr.reopen(cloned)
tempfile.close
tempfile.unlink
end
expect($stderr.to_io).not_to be_a(File)
end
end

0 comments on commit 7378952

Please sign in to comment.