Skip to content

Instantly share code, notes, and snippets.

@andrewle
Created October 17, 2016 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewle/d98481684026fc21512fc70060d577e6 to your computer and use it in GitHub Desktop.
Save andrewle/d98481684026fc21512fc70060d577e6 to your computer and use it in GitHub Desktop.
Print deprecation notices to stderr after all tests have run
# I've always disliked the way deprecation notices would appear while the test
# suite is running: they break up the neat little rows of dots (or F's, as it
# may be) which causes noise and makes the notices hard to read and understand.
#
# Adding this snippet to `config/environments/test.rb` will buffer all your
# deprecation notices until the end of the test run and keep your test output
# nice and tidy.
#
Rails.application.config do
# ...
# Collect deprecation notices in a StringIO buffer while tests are running
deprecation_buffer = StringIO.new
config.active_support.deprecation = ->(message, callstack) {
deprecation_buffer.puts message
deprecation_buffer.puts callstack.join("\n ") if ActiveSupport::Deprecation.debug
}
# Print deprecation notices to stderr after all tests have run
at_exit {
$stderr.puts deprecation_buffer.string
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment