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

Commit

Permalink
Include a more complex spec exercising the actual restoration
Browse files Browse the repository at this point in the history
This is what the matcher is trying to actually do, so ensuring that it
works makes a stronger test.
  • Loading branch information
nevinera committed May 20, 2024
1 parent 0a12282 commit da06053
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion spec/rspec/support/spec/stderr_splitter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,25 @@
end
end

# Otherwise, Splitter#reopen _also_ reopens the clone, unlike with actual STDERR
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' 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 da06053

Please sign in to comment.