Sha256: cf61b6ea54beea4abf5be2d3795a4eb9199596ed79e4a6945901f28089ac6f2f

Contents?: true

Size: 1.29 KB

Versions: 2

Compression:

Stored size: 1.29 KB

Contents

require File.join(File.dirname(__FILE__), '/test_helper')
require 'rails/all'

module Test
  def self.rails_log_device
    @rails_log_device ||= TestLogDevice.new
  end
  
  class Application < Rails::Application
    config.logger = Logger.new(Test.rails_log_device)
  end
end

class TestController < ActionController::Base
  def hi
    logger.info "hi"
  end
end

Test::Application.initialize!

class TaggedLoggerRailsTest < Test::Unit::TestCase
  include RR::Adapters::TestUnit

  context "stub output device @@stub_out;" do
    setup do
      TaggedLogger.config(:replace_existing_logger => true)
      @@stub_out = TestLogDevice.new
    end
    
    teardown do
      TaggedLogger.reset
    end

    should "be able possible to initialize in the way to override Rails existing logger" do
      assert TestController.new.respond_to? :logger
      TaggedLogger.rules do 
        info /.*/ do |level, tag, message|
          @@stub_out.write(tag.to_s)
        end
      end
      @@stub_out.write("TestController")
      TestController.new.hi
    end
    
    should "be possible to restore old logger methods" do
      TaggedLogger.rules do 
        info(/.*/) {|level, tag, message|}
      end
      TaggedLogger.reset
      mock(Test.rails_log_device).write("hi\n")
      TestController.new.hi
    end
    
  end    
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tagged_logger-0.5.6 test/test_rails.rb
tagged_logger-0.5.5 test/test_rails.rb