ougai 2.0.0 → 2.1.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.
data/spec/logging_spec.rb DELETED
@@ -1,107 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Ougai::Logging do
4
- subject do
5
- m = described_class
6
-
7
- Class.new do
8
- include m
9
-
10
- def level
11
- -1
12
- end
13
- end.new
14
- end
15
-
16
- describe '#weak_merge!' do
17
- it 'merges with unique elements in array' do
18
- result = nil
19
- subject.instance_eval do
20
- result = weak_merge!({ foo: [1, 2], bar: 'base', baz: ['A'] },
21
- { foo: [2, 3], bar: 'inferior', baz: ['B'] })
22
- end
23
- expect(result[:foo]).to eq([2, 3, 1])
24
- expect(result[:bar]).to eq('base')
25
- expect(result[:baz]).to eq(['B', 'A'])
26
- end
27
-
28
- it 'merges hashes recursively' do
29
- result = nil
30
- subject.instance_eval do
31
- result = weak_merge!({ foo: { bar: { baz: 15 } } },
32
- { foo: { bar: { extra: 10 }, nested: 'string' } })
33
- end
34
- expect(result).to eq({ foo: { bar: { baz: 15, extra: 10 }, nested: 'string' } })
35
- end
36
- end
37
-
38
- describe '#chain' do
39
- it 'is not implemented' do
40
- expect{ subject.chain(:arg1, :arg2, :arg3, :arg4) }.to raise_error(NotImplementedError)
41
- end
42
- end
43
-
44
- describe '#append' do
45
- it 'is not implemented' do
46
- expect{ subject.send(:append, :arg1, :arg2) }.to raise_error(NotImplementedError)
47
- end
48
- end
49
-
50
- describe '#add' do
51
- context 'severity is specified level' do
52
- it 'calls append with specified level' do
53
- data = double('data')
54
- expect(subject).to receive(:append).with(::Logger::Severity::DEBUG, ['debug message', data, nil])
55
- subject.add(::Logger::Severity::DEBUG, 'debug message', data)
56
- end
57
- end
58
-
59
- context 'severity is nil' do
60
- it 'calls append with UNKNOWN level' do
61
- expect(subject).to receive(:append).with(::Logger::Severity::UNKNOWN, ['message', nil, nil])
62
- subject.add(nil, 'message')
63
- end
64
- end
65
-
66
- context 'with block that yields message' do
67
- it 'calls append with yielded message' do
68
- expect(subject).to receive(:append).with(::Logger::Severity::WARN, 'block message')
69
- subject.add(::Logger::Severity::WARN) { 'block message' }
70
- end
71
- end
72
-
73
- context 'with block that yields array' do
74
- it 'calls append with yielded array' do
75
- data = double('data')
76
- expect(subject).to receive(:append).with(::Logger::Severity::WARN, ['block message', data])
77
- subject.add(::Logger::Severity::WARN) { ['block message', data] }
78
- end
79
- end
80
- end
81
-
82
- describe '#log' do
83
- context 'severity is specified' do
84
- it 'calls append with specified level' do
85
- ex = Exception.new
86
- expect(subject).to receive(:append).with(::Logger::Severity::FATAL, ['fatal message', ex, nil])
87
- subject.log(::Logger::Severity::FATAL, 'fatal message', ex)
88
- end
89
- end
90
-
91
- context 'severity is nil' do
92
- it 'calls append with UNKNOWN level' do
93
- expect(subject).to receive(:append).with(::Logger::Severity::UNKNOWN, ['message', nil, nil])
94
- subject.log(nil, 'message')
95
- end
96
- end
97
-
98
- context 'with block' do
99
- it 'calls append with yielded arguments' do
100
- ex = Exception.new
101
- data = double('data')
102
- expect(subject).to receive(:append).with(::Logger::Severity::INFO, ['block message', ex, data])
103
- subject.log(::Logger::Severity::INFO) { ['block message', ex, data] }
104
- end
105
- end
106
- end
107
- end
data/spec/ougai_spec.rb DELETED
@@ -1,7 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Ougai do
4
- it 'has a version number' do
5
- expect(Ougai::VERSION).not_to be nil
6
- end
7
- end
data/spec/spec_helper.rb DELETED
@@ -1,78 +0,0 @@
1
- require 'timecop'
2
- require 'simplecov'
3
- SimpleCov.start do
4
- add_filter "/spec/"
5
- end
6
-
7
- $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
8
- require 'ougai'
9
-
10
- RSpec.shared_examples 'formatter#initialize' do |params|
11
- describe '#initialize' do
12
- let(:app_name) { 'dummy app name' }
13
- let(:hostname) { 'dummyhost' }
14
- let(:options) { params[:options] }
15
-
16
- subject { described_class.new(*arguments) }
17
-
18
- context 'with app_name' do
19
- let!(:arguments) { [app_name] }
20
-
21
- it 'creates an instance with valid app_name and hostname' do
22
- expect(subject.app_name).to eq(app_name)
23
- expect(subject.hostname).to eq(Socket.gethostname.force_encoding('UTF-8'))
24
- params[:default_opts].each do |key, val|
25
- expect(subject.send(key)).to eq(val)
26
- end
27
- end
28
- end
29
-
30
- context 'with options' do
31
- let!(:arguments) { [options] }
32
-
33
- it 'creates an instance with valid values for attributes' do
34
- expect(subject.app_name).to eq('rspec')
35
- expect(subject.hostname).to eq(Socket.gethostname.force_encoding('UTF-8'))
36
- options.each do |key, val|
37
- expect(subject.send(key)).to eq(val)
38
- end
39
- end
40
- end
41
-
42
- context 'with app_name and hostname' do
43
- let!(:arguments) { [app_name, hostname] }
44
-
45
- it 'creates an instance with valid app_name and hostname' do
46
- expect(subject.app_name).to eq(app_name)
47
- expect(subject.hostname).to eq(hostname)
48
- params[:default_opts].each do |key, val|
49
- expect(subject.send(key)).to eq(val)
50
- end
51
- end
52
- end
53
-
54
- context 'with app_name and options' do
55
- let!(:arguments) { [app_name, options] }
56
-
57
- it 'creates an instance with valid values for attributes' do
58
- expect(subject.app_name).to eq(app_name)
59
- expect(subject.hostname).to eq(Socket.gethostname.force_encoding('UTF-8'))
60
- options.each do |key, val|
61
- expect(subject.send(key)).to eq(val)
62
- end
63
- end
64
- end
65
-
66
- context 'with app_name, hostname and options' do
67
- let!(:arguments) { [app_name, hostname, options] }
68
-
69
- it 'creates an instance with valid values for attributes' do
70
- expect(subject.app_name).to eq(app_name)
71
- expect(subject.hostname).to eq(hostname)
72
- options.each do |key, val|
73
- expect(subject.send(key)).to eq(val)
74
- end
75
- end
76
- end
77
- end
78
- end