tighten up Hub and add comments
[god.git] / test / test_logger.rb
blob8f9e4e534b4a8bf127fde454248c18f0198062b6
1 require File.dirname(__FILE__) + '/helper'
3 class TestLogger < Test::Unit::TestCase
4   def setup
5     @log = God::Logger.new
6   end
7   
8   # log
9   
10   def test_log
11     @log.expects(:info).with("qux")
12     
13     no_stdout do
14       @log.log(stub(:name => 'foo'), :info, "qux")
15     end
16     
17     assert_equal 1, @log.logs.size
18     assert_instance_of Time, @log.logs['foo'][0][0]
19     assert_match(/qux/, @log.logs['foo'][0][1])
20   end
21   
22   def test_log_should_send_to_syslog
23     Syslog.expects(:crit).with('foo')
24     
25     no_stdout do
26       @log.log(stub(:name => 'foo'), :fatal, "foo")
27     end
28   end
29   
30   # watch_log_since
31   
32   def test_watch_log_since
33     t1 = Time.now
34     
35     no_stdout do
36       @log.log(stub(:name => 'foo'), :info, "one")
37       @log.log(stub(:name => 'foo'), :info, "two")
38     end
39     
40     assert_match(/one.*two/m, @log.watch_log_since('foo', t1))
41     
42     t2 = Time.now
43     
44     no_stdout do
45       @log.log(stub(:name => 'foo'), :info, "three")
46     end
47     
48     out = @log.watch_log_since('foo', t2)
49     
50     assert_no_match(/one/, out)
51     assert_no_match(/two/, out)
52     assert_match(/three/, out)
53   end
54   
55   # regular methods
56   
57   def test_fatal
58     no_stdout do
59       @log.fatal('foo')
60     end
61     assert_equal 0, @log.logs.size
62   end
63 end