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

Override RSpec::Support::StdErrSplitter#clone #598

Merged
merged 3 commits into from
Aug 18, 2024
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
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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test fails on this line without the change - $stderr is actually still pointed at the Tempfile (despite that it's closed), and not the original process stream.

end
end
Loading