betterlog 0.20.2 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,96 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Betterlog::Logger do
4
- let :logger do
5
- described_class.new(Redis.new)
6
- end
7
-
8
- describe '.for_redis_url' do
9
- it 'can handle not being able to connect to redis' do
10
- redis = double
11
- allow(redis).to receive(:ping).and_raise Redis::CannotConnectError
12
- allow(Redis).to receive(:new).with(url: 'the_url').and_return redis
13
- expect(Betterlog::Logger.for_redis_url('the_url')).to be_nil
14
- end
15
-
16
- it 'can connect to redis for the url' do
17
- redis = double(ping: 'PONG')
18
- allow(Redis).to receive(:new).with(url: 'the_url').and_return redis
19
- expect(Betterlog::Logger.for_redis_url('the_url')).to be_a Betterlog::Logger
20
- end
21
- end
22
-
23
- describe '#<<' do
24
- it 'writes to redis' do
25
- expect(logger.instance_variable_get(:@redis)).to receive(:append).
26
- with('Betterlog::Logger', 'foo')
27
- logger << 'foo'
28
- end
29
-
30
- it 'falls back if redis errors' do
31
- allow(logger.instance_variable_get(:@redis)).to receive(:append).
32
- and_raise(Redis::BaseConnectionError)
33
- expect(logger.instance_variable_get(:@fallback)).to\
34
- receive(:<<).with('foo')
35
- logger << 'foo'
36
- end
37
- end
38
-
39
- describe '#add' do
40
- it 'writes to redis' do
41
- expect(logger.instance_variable_get(:@redis)).to receive(:append).
42
- with('Betterlog::Logger', /INFO -- : foo/)
43
- logger.info 'foo'
44
- end
45
-
46
- it 'falls back if redis errors' do
47
- allow(logger.instance_variable_get(:@redis)).to receive(:append).
48
- and_raise(Redis::BaseConnectionError)
49
- expect(logger.instance_variable_get(:@fallback)).to\
50
- receive(:add).with(::Logger::INFO, 'foo', nil)
51
- logger.info 'foo'
52
- end
53
- end
54
-
55
- describe '#each_chunk' do
56
- it 'iterates over chunks of data' do
57
- logger.clear
58
- logger << "foo" * 23
59
- expect(logger.each_chunk(chunk_size: 10).to_a).to eq %w[
60
- foofoofoof
61
- oofoofoofo
62
- ofoofoofoo
63
- foofoofoof
64
- oofoofoofo
65
- ofoofoofoo
66
- foofoofoo
67
- ]
68
- end
69
-
70
- it 'works if no data is there' do
71
- logger.clear
72
- expect(logger.each_chunk(chunk_size: 1).to_a).to eq []
73
- end
74
-
75
- it 'iterates if chunk_size is 1 and 23' do
76
- logger.clear
77
- logger << ?. * 23
78
- expect(logger.each_chunk(chunk_size: 1).to_a).to eq [ ?. ] * 23
79
- end
80
-
81
- it 'iterates if chunk_size is 1 and 22' do
82
- logger.clear
83
- logger << ?. * 22
84
- expect(logger.each_chunk(chunk_size: 1).to_a).to eq [ ?. ] * 22
85
- end
86
- end
87
-
88
- describe '#each' do
89
- it 'iterates over log lines' do
90
- logger.clear
91
- logger << "foo\n"
92
- logger << "bar\n"
93
- expect(logger.to_a).to eq [ "foo\n", "bar\n" ]
94
- end
95
- end
96
- end