Sha256: ca51aefc4a9379b27acf54e5b569ebe0e72ac8011542feebc90d86af7be21b94

Contents?: true

Size: 1.45 KB

Versions: 2

Compression:

Stored size: 1.45 KB

Contents

# Allow test to be run in-place without requiring a gem install
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'

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

    context "log to Ruby and Rails logger" do
      setup do
        # Use a mock logger that just keeps the last logged entry in an instance variable
        @mock_logger = MockLogger.new
        @appender = SemanticLogger::Appender::Logger.new(@mock_logger)
        SemanticLogger::Logger.appenders << @appender

        # Use this test's class name as the application name in the log output
        @logger = SemanticLogger::Logger.new('LoggerTest', :level => :trace)

        @hash = { :session_id => 'HSSKLEU@JDK767', :tracking_number => 12345 }
      end

      teardown do
        SemanticLogger::Logger.appenders.delete(@appender)
      end

      # Ensure that any log level can be logged
      SemanticLogger::Logger::LEVELS.each do |level|
        should "log #{level} info" do
          @logger.send(level, 'hello world', @hash) { "Calculations" }
          @logger.flush
          assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ \w \[\d+:.+\] LoggerTest -- hello world -- Calculations -- \{:session_id=>\"HSSKLEU@JDK767\", :tracking_number=>12345\}\n/, @mock_logger.message
        end
      end

    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
semantic_logger-0.2.0 test/logger_test.rb
semantic_logger-0.1.0 test/logger_test.rb