-
-
Save Mayurifag/ff7936bec89e2e10bd94dbdb6ff62f19 to your computer and use it in GitHub Desktop.
Better debugging for rails tests: logs and custom output to stdout
This file contains hidden or 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
# run it as DEBUG=true rails test | |
if ENV['DEBUG'] | |
Rails.logger = Logger.new(STDOUT) | |
Rails.logger.level = Logger::INFO | |
Rails.logger.datetime_format = "" | |
Rails.logger.formatter = proc do |severity, _time, _progname, msg| | |
"#{severity.green}: #{msg}\n" | |
end | |
# to see database queries | |
# run it as DEBUG=db rails test | |
ActiveRecord::Base.logger = ActiveSupport::Logger.new(STDOUT) if ENV['DEBUG'] == 'db' | |
end | |
# special output which works in debug | |
def echo(msg) | |
return unless ENV['DEBUG'] | |
puts msg.blue | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment