Created
October 17, 2016 16:25
-
-
Save andrewle/d98481684026fc21512fc70060d577e6 to your computer and use it in GitHub Desktop.
Print deprecation notices to stderr after all tests have run
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
# 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