Created
April 19, 2011 05:28
-
-
Save adamstegman/926858 to your computer and use it in GitHub Desktop.
Silence RSpec specs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RSpec.configure do |config| | |
config.before(:all, &:silence_output) | |
config.after(:all, &:enable_output) | |
end | |
# 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 | |
# 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 |
Any way to still use a debugger?
this also works:
bin/rspec spec/models/user_spec.rb 2>/dev/null
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi guys, above mentioned methods doesn't help me in redirecting stdout for system call (` method). But thanks you all, these examples helped me in identifying the workaround. Here is the workaround I have used.