2012-01-20 14:45:29 -05:00
|
|
|
require 'abstract_unit'
|
|
|
|
|
|
|
|
module ActiveSupport
|
|
|
|
class BroadcastLoggerTest < TestCase
|
2016-01-05 11:37:04 -05:00
|
|
|
attr_reader :logger, :log1, :log2
|
2012-01-20 14:52:21 -05:00
|
|
|
def setup
|
2016-01-05 11:37:04 -05:00
|
|
|
@log1 = FakeLogger.new
|
|
|
|
@log2 = FakeLogger.new
|
|
|
|
@log1.extend Logger.broadcast @log2
|
|
|
|
@logger = @log1
|
2012-01-20 14:52:21 -05:00
|
|
|
end
|
2012-01-20 14:45:29 -05:00
|
|
|
|
2012-01-20 14:52:21 -05:00
|
|
|
def test_debug
|
2012-01-20 14:45:29 -05:00
|
|
|
logger.debug "foo"
|
2016-01-05 11:37:04 -05:00
|
|
|
assert_equal 'foo', log1.adds.first[2]
|
|
|
|
assert_equal 'foo', log2.adds.first[2]
|
2012-01-20 14:45:29 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_close
|
|
|
|
logger.close
|
2016-01-05 11:37:04 -05:00
|
|
|
assert log1.closed, 'should be closed'
|
|
|
|
assert log2.closed, 'should be closed'
|
2012-01-20 14:45:29 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_chevrons
|
|
|
|
logger << "foo"
|
2016-01-05 11:37:04 -05:00
|
|
|
assert_equal %w{ foo }, log1.chevrons
|
|
|
|
assert_equal %w{ foo }, log2.chevrons
|
2012-01-20 14:45:29 -05:00
|
|
|
end
|
|
|
|
|
2012-01-20 14:52:21 -05:00
|
|
|
def test_level
|
|
|
|
assert_nil logger.level
|
|
|
|
logger.level = 10
|
2016-01-05 11:37:04 -05:00
|
|
|
assert_equal 10, log1.level
|
|
|
|
assert_equal 10, log2.level
|
2012-01-20 14:52:21 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_progname
|
|
|
|
assert_nil logger.progname
|
|
|
|
logger.progname = 10
|
2016-01-05 11:37:04 -05:00
|
|
|
assert_equal 10, log1.progname
|
|
|
|
assert_equal 10, log2.progname
|
2012-01-20 14:52:21 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_formatter
|
|
|
|
assert_nil logger.formatter
|
|
|
|
logger.formatter = 10
|
2016-01-05 11:37:04 -05:00
|
|
|
assert_equal 10, log1.formatter
|
|
|
|
assert_equal 10, log2.formatter
|
2012-01-20 14:52:21 -05:00
|
|
|
end
|
|
|
|
|
2012-01-20 14:45:29 -05:00
|
|
|
class FakeLogger
|
|
|
|
attr_reader :adds, :closed, :chevrons
|
2016-01-05 11:37:04 -05:00
|
|
|
attr_accessor :level, :progname, :formatter
|
2012-01-20 14:45:29 -05:00
|
|
|
|
|
|
|
def initialize
|
2012-01-20 14:52:21 -05:00
|
|
|
@adds = []
|
|
|
|
@closed = false
|
|
|
|
@chevrons = []
|
|
|
|
@level = nil
|
|
|
|
@progname = nil
|
|
|
|
@formatter = nil
|
2012-01-20 14:45:29 -05:00
|
|
|
end
|
|
|
|
|
2012-01-20 17:18:29 -05:00
|
|
|
def debug msg, &block
|
|
|
|
add(:omg, nil, msg, &block)
|
|
|
|
end
|
|
|
|
|
2012-01-20 14:45:29 -05:00
|
|
|
def << x
|
|
|
|
@chevrons << x
|
|
|
|
end
|
|
|
|
|
|
|
|
def add(*args)
|
|
|
|
@adds << args
|
|
|
|
end
|
|
|
|
|
|
|
|
def close
|
|
|
|
@closed = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|