Skip to content

Instantly share code, notes, and snippets.

@shtakai
Forked from adamstegman/spec_helper.rb
Created August 15, 2018 01:46
Show Gist options
  • Save shtakai/b697d2aaeaa058403490df4fcf2775da to your computer and use it in GitHub Desktop.
Save shtakai/b697d2aaeaa058403490df4fcf2775da to your computer and use it in GitHub Desktop.
Silence RSpec specs
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment