Class: RSpec::Risky::Probe::OutputProbe::FdCapture

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/risky/probe/fd_capture.rb

Constant Summary collapse

READ_SIZE =
4096

Instance Method Summary collapse

Constructor Details

#initialize(stream_name, io, report, passthrough:) ⇒ FdCapture

Returns a new instance of FdCapture.



10
11
12
13
14
15
16
17
18
# File 'lib/rspec/risky/probe/fd_capture.rb', line 10

def initialize(stream_name, io, report, passthrough:)
  @stream_name = stream_name
  @io = io
  @report = report
  @passthrough = passthrough
  @reader = nil
  @original = nil
  @thread = nil
end

Instance Method Details

#finishObject



32
33
34
35
36
37
38
# File 'lib/rspec/risky/probe/fd_capture.rb', line 32

def finish
  @io.reopen(@original) if @original
  @thread&.join(1)
  @original&.close
ensure
  @reader&.close unless @reader&.closed?
end

#startObject



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rspec/risky/probe/fd_capture.rb', line 20

def start
  @original = @io.dup
  @reader, writer = IO.pipe
  @reader.binmode
  writer.binmode
  @io.reopen(writer)
  @io.sync = true if @io.respond_to?(:sync=)
  writer.close
  start_reader
  self
end