test/logger_test.rb in semantic_logger-0.6.2 vs test/logger_test.rb in semantic_logger-0.7.0

- old
+ new

@@ -4,11 +4,10 @@ require 'rubygems' require 'test/unit' require 'shoulda' require 'logger' require 'semantic_logger' -require 'test/mock_logger' # Unit Test for SemanticLogger::Logger class LoggerTest < Test::Unit::TestCase context SemanticLogger::Logger do @@ -69,27 +68,44 @@ end end end context "Ruby Logger" do - # Ensure that any log level can be logged Logger::Severity.constants.each do |level| should "log Ruby logger #{level} info" do @logger.level = Logger::Severity.const_get(level) - #assert_equal level.downcase.to_sym, @logger.level - if level == 'UNKNOWN' + if level.to_s == 'UNKNOWN' assert_equal Logger::Severity.const_get('ERROR')+1, @logger.send(:level_index) else assert_equal Logger::Severity.const_get(level)+1, @logger.send(:level_index) end - # @logger.send(level, 'hello world', @hash) { "Calculations" } - # SemanticLogger::Logger.flush - # assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ \w \[\d+:.+\] LoggerTest -- hello world -- Calculations -- #{@hash_str}/, @mock_logger.message end end end + context "benchmark" do + # Ensure that any log level can be benchmarked and logged + SemanticLogger::LEVELS.each do |level| + should "log #{level} info" do + assert_equal "result", @logger.send("benchmark_#{level}".to_sym, 'hello world') { "result" } + SemanticLogger::Logger.flush + assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ \w \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world/, @mock_logger.message + end + + should "log #{level} info with payload" do + assert_equal "result", @logger.send("benchmark_#{level}".to_sym, 'hello world', :payload => @hash) { "result" } + SemanticLogger::Logger.flush + assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ \w \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world -- #{@hash_str}/, @mock_logger.message + end + + should "not log #{level} info when block is faster than :min_duration" do + assert_equal "result", @logger.send("benchmark_#{level}".to_sym, 'hello world', :min_duration => 0.5) { "result" } + SemanticLogger::Logger.flush + assert_nil @mock_logger.message + end + end + end end end end \ No newline at end of file