Sha256: 8b3244fa7eb5e939a06d9e7e70ce603e5a0e7a570cf274427a0a7e9940784c24

Contents?: true

Size: 714 Bytes

Versions: 8

Compression:

Stored size: 714 Bytes

Contents

module StdStreamsHelper
  # Capture STDOUT in a variable
  #
  # Usage
  #
  #     out_stream = StringIO.new
  #     capture_stdout(out_stream) { do_something }
  def capture_stdout(stdout)
    original_stdout = $stdout
    $stdout = stdout

    yield

    $stdout = original_stdout
  end

  # Capture STDOUT and STDERR in variables
  #
  # Usage
  #
  #     out_stream = StringIO.new
  #     err_stream = StringIO.new
  #     capture_std_streams(out_stream, err_stream) { do_something }
  def capture_std_streams(stdout, stderr)
    original_stdout = $stdout
    $stdout = stdout
    original_stderr = $stderr
    $stderr = stderr

    yield

    $stdout = original_stdout
    $stderr = original_stderr
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
appsignal-2.0.3 spec/support/helpers/std_streams_helper.rb
appsignal-2.0.2 spec/support/helpers/std_streams_helper.rb
appsignal-2.0.1 spec/support/helpers/std_streams_helper.rb
appsignal-2.0.0 spec/support/helpers/std_streams_helper.rb
appsignal-2.0.0.beta.1 spec/support/helpers/std_streams_helper.rb
appsignal-1.4.0.beta.1 spec/support/helpers/std_streams_helper.rb
appsignal-1.3.6 spec/support/helpers/std_streams_helper.rb
appsignal-1.3.6.beta.1 spec/support/helpers/std_streams_helper.rb