Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a broadcasting logger so we can split logs
- Loading branch information
1 parent
30b0e58
commit d42b3d4
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,57 @@ | |||
require 'abstract_unit' | |||
|
|||
module ActiveSupport | |||
class BroadcastLoggerTest < TestCase | |||
def test_debug | |||
log1 = FakeLogger.new | |||
log2 = FakeLogger.new | |||
|
|||
logger = BroadcastLogger.new [log1, log2] | |||
logger.debug "foo" | |||
assert_equal 'foo', log1.adds.first[2] | |||
assert_equal 'foo', log2.adds.first[2] | |||
end | |||
|
|||
def test_close | |||
log1 = FakeLogger.new | |||
log2 = FakeLogger.new | |||
|
|||
logger = BroadcastLogger.new [log1, log2] | |||
logger.close | |||
assert log1.closed, 'should be closed' | |||
assert log2.closed, 'should be closed' | |||
end | |||
|
|||
def test_chevrons | |||
log1 = FakeLogger.new | |||
log2 = FakeLogger.new | |||
|
|||
logger = BroadcastLogger.new [log1, log2] | |||
logger << "foo" | |||
assert_equal %w{ foo }, log1.chevrons | |||
assert_equal %w{ foo }, log2.chevrons | |||
end | |||
|
|||
class FakeLogger | |||
attr_reader :adds, :closed, :chevrons | |||
|
|||
def initialize | |||
@adds = [] | |||
@closed = false | |||
@chevrons = [] | |||
end | |||
|
|||
def << x | |||
@chevrons << x | |||
end | |||
|
|||
def add(*args) | |||
@adds << args | |||
end | |||
|
|||
def close | |||
@closed = true | |||
end | |||
end | |||
end | |||
end |