module RSpec::Helpers

Constants

VERSION

Public Instance Methods

capture_io(&block) click to toggle source

Wrap around ‘silence_io` making it easy to capture IO.


# File lib/rspec/helpers.rb, line 41
def capture_io(&block)
  silence_io(:capture => true, &block)
end
silence_io(capture: false) { || ... } click to toggle source

Silence the output of any method or command being ran.


# File lib/rspec/helpers.rb, line 17
def silence_io(capture: false)
  _stdout = $stdout # OG
  _stderr = $stderr # OG
  $stdout = StringIO.new
  $stderr = StringIO.new

  if !capture
    yield
  else
    yield
    return {
      :stderr => $stderr.string,
      :stdout => $stdout.string
    }
  end
ensure
  $stdout = _stdout
  $stderr = _stderr
end