Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Tests tag the Rails log with the current test class and test case

  • Loading branch information...
commit 86ebe0bd36e03b7b7531d818f65cacdb03766abe 1 parent 107fd87
@jeremy jeremy authored
View
7 activesupport/CHANGELOG.md
@@ -1,5 +1,12 @@
## Rails 4.0.0 (unreleased) ##
+* Tests tag the Rails log with the current test class and test case:
+
+ [SessionsControllerTest] [test_0002_sign in] Processing by SessionsController#create as HTML
+ [SessionsControllerTest] [test_0002_sign in] ...
+
+ *Jeremy Kemper*
+
* Add logger.push_tags and .pop_tags to complement logger.tagged:
class Job
View
2  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 @@ def self.test_order # :nodoc:
:sorted
end
+ include ActiveSupport::Testing::TaggedLogging
include ActiveSupport::Testing::SetupAndTeardown
include ActiveSupport::Testing::Assertions
include ActiveSupport::Testing::Deprecation
View
30 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
@tenderlove Owner

Do we need this? (I mean the AS::Concern part)

@josevalim Owner

Are you concerned about AS::Concern?

I have removed it in b8b100a a few days ago after asking @jeremy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+
+ 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
View
15 activesupport/test/test_test.rb
@@ -171,3 +171,18 @@ def sentinel
assert_equal [:foo, :bar, :bar, :foo], @called_back
end
end
+
+
+class TestCaseTaggedLoggingTest < ActiveSupport::TestCase
+ def before_setup
+ require 'stringio'
+ @out = StringIO.new
+ self.tagged_logger = ActiveSupport::TaggedLogging.new(Logger.new(@out))
+ super
+ end
+
+ def test_logs_tagged_with_current_test_case
+ tagged_logger.info 'test'
+ assert_equal "[#{self.class.name}] [#{__name__}] test\n", @out.string
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.