Skip to content

Instantly share code, notes, and snippets.

@pboling
Created Oct 18, 2015
Embed
What would you like to do?
Rspec support: Silnce the `puts`
# Some specs causes a lot of stuff to output to the console during the spec run which interrupts the flow of lovely green dots.
# We don't want to ignore stuff that we want to see, like rspec deprecation warnings, but for an otherwise clean spec,
# that is puts ing things, we can turn those off by tagging the spec as :noisy.
RSpec.configure do |config|
original_stderr = $stderr
original_stdout = $stdout
config.before(:each, :noisy) do
# Redirect stderr and stdout
$stderr = File.open(File::NULL, "w") # to /dev/null, since Ruby 1.9.3
$stdout = File.open(File::NULL, "w") # to /dev/null, since Ruby 1.9.3
end
config.after(:each, :noisy) do
$stderr = original_stderr
$stdout = original_stdout
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment