diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2012-12-26 21:02:24 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2012-12-26 21:16:05 -0700 |
commit | b82109495b2e910f05922b05a2df69d42f3635a9 (patch) | |
tree | b9b013c0c9849edc23bbca6df9a70053a05f8038 /activesupport/lib/active_support | |
parent | 42d9b480121e15a15cddd2015a1e60a0f9e0f953 (diff) | |
download | rails-b82109495b2e910f05922b05a2df69d42f3635a9.tar.gz rails-b82109495b2e910f05922b05a2df69d42f3635a9.tar.bz2 rails-b82109495b2e910f05922b05a2df69d42f3635a9.zip |
Make test logs easier to read.
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.
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/testing/tagged_logging.rb | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/activesupport/lib/active_support/testing/tagged_logging.rb b/activesupport/lib/active_support/testing/tagged_logging.rb index 8ea2605733..9d43eb179f 100644 --- a/activesupport/lib/active_support/testing/tagged_logging.rb +++ b/activesupport/lib/active_support/testing/tagged_logging.rb @@ -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 |