aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2012-09-26 11:16:43 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2012-09-26 11:17:02 -0700
commit86ebe0bd36e03b7b7531d818f65cacdb03766abe (patch)
tree8090c947015c9d842ad7c55d5d947ee28dc569f6 /activesupport/lib/active_support
parent107fd8788f92da53232e87a220d6f4329c8f2b13 (diff)
downloadrails-86ebe0bd36e03b7b7531d818f65cacdb03766abe.tar.gz
rails-86ebe0bd36e03b7b7531d818f65cacdb03766abe.tar.bz2
rails-86ebe0bd36e03b7b7531d818f65cacdb03766abe.zip
Tests tag the Rails log with the current test class and test case
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r--activesupport/lib/active_support/test_case.rb2
-rw-r--r--activesupport/lib/active_support/testing/tagged_logging.rb30
2 files changed, 32 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/test_case.rb b/activesupport/lib/active_support/test_case.rb
index 60bd4ace9b..1f874b56db 100644
--- a/activesupport/lib/active_support/test_case.rb
+++ b/activesupport/lib/active_support/test_case.rb
@@ -1,5 +1,6 @@
gem 'minitest' # make sure we get the gem, not stdlib
require 'minitest/spec'
+require 'active_support/testing/tagged_logging'
require 'active_support/testing/setup_and_teardown'
require 'active_support/testing/assertions'
require 'active_support/testing/deprecation'
@@ -33,6 +34,7 @@ module ActiveSupport
:sorted
end
+ include ActiveSupport::Testing::TaggedLogging
include ActiveSupport::Testing::SetupAndTeardown
include ActiveSupport::Testing::Assertions
include ActiveSupport::Testing::Deprecation
diff --git a/activesupport/lib/active_support/testing/tagged_logging.rb b/activesupport/lib/active_support/testing/tagged_logging.rb
new file mode 100644
index 0000000000..899467c45f
--- /dev/null
+++ b/activesupport/lib/active_support/testing/tagged_logging.rb
@@ -0,0 +1,30 @@
+require 'active_support/concern'
+
+module ActiveSupport
+ module Testing
+ module TaggedLogging
+ extend ActiveSupport::Concern
+
+ attr_writer :tagged_logger
+
+ def before_setup
+ tagged_logger.push_tags(self.class.name, __name__) if tagged_logging?
+ super
+ end
+
+ def after_teardown
+ 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