diff options
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/buffered_logger_test.rb | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/activesupport/test/buffered_logger_test.rb b/activesupport/test/buffered_logger_test.rb new file mode 100644 index 0000000000..7d55715084 --- /dev/null +++ b/activesupport/test/buffered_logger_test.rb @@ -0,0 +1,41 @@ +require File.dirname(__FILE__) + '/abstract_unit' +require 'stringio' + +class BufferedLoggerTest < Test::Unit::TestCase + def setup + @message = "A debug message" + @output = StringIO.new + @logger = ActiveSupport::BufferedLogger.new(@output) + end + + def test_should_log_debugging_message_when_debugging + @logger.level = Logger::DEBUG + @logger.add(Logger::DEBUG, @message) + assert @output.string.include?(@message) + end + + def test_should_not_log_debug_messages_when_log_level_is_info + @logger.level = Logger::INFO + @logger.add(Logger::DEBUG, @message) + assert ! @output.string.include?(@message) + end + + def test_should_add_message_passed_as_block_when_using_add + @logger.level = Logger::INFO + @logger.add(Logger::INFO) {@message} + assert @output.string.include?(@message) + end + + def test_should_add_message_passed_as_block_when_using_shortcut + @logger.level = Logger::INFO + @logger.info {@message} + assert @output.string.include?(@message) + end + + def test_should_not_evaluate_block_if_message_wont_be_logged + @logger.level = Logger::INFO + evaluated = false + @logger.add(Logger::DEBUG) {evaluated = true} + assert evaluated == false + end +end |