Skip to content

Instantly share code, notes, and snippets.

@adamstegman
Created April 19, 2011 05:18
Show Gist options
  • Save adamstegman/926853 to your computer and use it in GitHub Desktop.
Save adamstegman/926853 to your computer and use it in GitHub Desktop.
silence Test::Unit tests
setup :silence_output
# Redirects stderr and stdout to /dev/null.
def silence_output
@orig_stderr = $stderr
@orig_stdout = $stdout
# redirect stderr and stdout to /dev/null
$stderr = File.new('/dev/null', 'w')
$stdout = File.new('/dev/null', 'w')
end
teardown :enable_output
# Replace stdout and stderr so anything else is output correctly.
def enable_output
$stderr = @orig_stderr
$stdout = @orig_stdout
@orig_stderr = nil
@orig_stdout = nil
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment