spec/spec_helper.rb
# Temporarily redirects STDOUT and STDERR to /dev/null
# but does print exceptions should there occur any.
# Call as:
#   suppress_output { puts 'never printed' }
#
Temporarily redirects STDOUT and STDERR to /dev/null
but does print exceptions should there occur any.
Call as:
suppress_output { puts 'never printed' }
Temporarily redirects STDOUT and STDERR to / dev / null but does print exceptions should there occur any . Call as : suppress_output { puts ' never printed ' }
def suppress_output
  original_stderr = $stderr.clone
  original_stdout = $stdout.clone
  $stderr.reopen(File.new("/dev/null", "w"))
  $stdout.reopen(File.new("/dev/null", "w"))
  retval = yield
rescue => e
  $stdout.reopen(original_stdout)
  $stderr.reopen(original_stderr)
  raise e
ensure
  $stdout.reopen(original_stdout)
  $stderr.reopen(original_stderr)
  retval
end
def suppress_output original_stderr = $stderr . clone original_stdout = $stdout . clone $stderr . reopen ( File . new ( "/dev/null" , "w" ) ) $stdout . reopen ( File . new ( "/dev/null" , "w" ) ) retval = yield rescue => e $stdout . reopen ( original_stdout ) $stderr . reopen ( original_stderr ) raise e ensure $stdout . reopen ( original_stdout ) $stderr . reopen ( original_stderr ) retval end
Temporarily redirects STDOUT and STDERR to /dev/null
but does print exceptions should there occur any.
Temporarily redirects STDOUT and STDERR to / dev / null but does print exceptions should there occur any .