forked from rails/rails
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tagging every message in tests makes the logs really wide. It's great for grepping, but annoying to open in an editor or a narrow terminal. Try out a different approach: spit out a heading before each test.
- Loading branch information
Showing
2 changed files
with
11 additions
and
13 deletions.
There are no files selected for viewing
21 changes: 10 additions & 11 deletions
21
activesupport/lib/active_support/testing/tagged_logging.rb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,25 @@ | ||
module ActiveSupport | ||
module Testing | ||
module TaggedLogging | ||
# Logs a "PostsControllerTest: test name" heading before each test to | ||
# make test.log easier to search and follow along with. | ||
module TaggedLogging #:nodoc: | ||
attr_writer :tagged_logger | ||
|
||
def before_setup | ||
tagged_logger.push_tags(self.class.name, __name__) if tagged_logging? | ||
super | ||
end | ||
|
||
def after_teardown | ||
if tagged_logger | ||
heading = "#{self.class}: #{__name__}" | ||
divider = '-' * heading.size | ||
tagged_logger.info divider | ||
tagged_logger.info heading | ||
tagged_logger.info divider | ||
end | ||
super | ||
tagged_logger.pop_tags(2) if tagged_logging? | ||
end | ||
|
||
private | ||
def tagged_logger | ||
@tagged_logger ||= (defined?(Rails.logger) && Rails.logger) | ||
end | ||
|
||
def tagged_logging? | ||
tagged_logger && tagged_logger.respond_to?(:push_tags) | ||
end | ||
end | ||
end | ||
end |
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