yell 2.2.0 → 2.2.1

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,49 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Yell Adapter DSL spec" do
4
-
5
- class DSLAdapter < Yell::Adapters::Base
6
-
7
- setup do |options|
8
- @test_setup = true
9
- end
10
-
11
- write do |event|
12
- @test_write = true
13
- end
14
-
15
- close do
16
- @test_close = true
17
- end
18
-
19
- def test_setup?; !!@test_setup; end
20
- def test_write?; !!@test_write; end
21
- def test_close?; !!@test_close; end
22
- end
23
-
24
- it "should perform #setup" do
25
- adapter = DSLAdapter.new
26
- expect(adapter.test_setup?).to be_truthy
27
- end
28
-
29
- it "should perform #write" do
30
- event = 'event'
31
- allow(event).to receive(:level) { 0 }
32
-
33
- adapter = DSLAdapter.new
34
- expect(adapter.test_write?).to be_falsey
35
-
36
- adapter.write(event)
37
- expect(adapter.test_write?).to be_truthy
38
- end
39
-
40
- it "should perform #close" do
41
- adapter = DSLAdapter.new
42
- expect(adapter.test_close?).to be_falsey
43
-
44
- adapter.close
45
- expect(adapter.test_close?).to be_truthy
46
- end
47
-
48
- end
49
-
@@ -1,97 +0,0 @@
1
- require 'spec_helper'
2
-
3
- # Since Yell::Event.new is not called directly, but through
4
- # the logger methods, we need to divert here in order to get
5
- # the correct caller.
6
- class EventFactory
7
- def self.event(logger, level, message)
8
- self._event(logger, level, message)
9
- end
10
-
11
- private
12
-
13
- def self._event(logger, level, message)
14
- Yell::Event.new(logger, level, message)
15
- end
16
-
17
- end
18
-
19
- describe Yell::Event do
20
- let(:logger) { Yell::Logger.new(:trace => true) }
21
- let(:event) { Yell::Event.new(logger, 1, 'Hello World!') }
22
-
23
- context "#level" do
24
- subject { event.level }
25
- it { should eq(1) }
26
- end
27
-
28
- context "#messages" do
29
- subject { event.messages }
30
- it { should eq(['Hello World!']) }
31
- end
32
-
33
- context "#time" do
34
- let(:time) { Time.now }
35
- subject { event.time.to_s }
36
-
37
- before { Timecop.freeze(time) }
38
-
39
- it { should eq(time.to_s) }
40
- end
41
-
42
- context "#hostname" do
43
- subject { event.hostname }
44
- it { should eq(Socket.gethostname) }
45
- end
46
-
47
- context "#pid" do
48
- subject { event.pid }
49
- it { should eq(Process.pid) }
50
- end
51
-
52
- context "#id when forked", :pending => RUBY_PLATFORM == 'java' ? "No forking with jruby" : false do
53
- subject { @pid }
54
-
55
- before do
56
- read, write = IO.pipe
57
-
58
- @pid = Process.fork do
59
- event = Yell::Event.new(logger, 1, 'Hello World!')
60
- write.puts event.pid
61
- end
62
- Process.wait
63
- write.close
64
-
65
- @child_pid = read.read.to_i
66
- read.close
67
- end
68
-
69
- it { should_not eq(Process.pid) }
70
- it { should eq(@child_pid) }
71
- end
72
-
73
- context "#progname" do
74
- subject { event.progname }
75
- it { should eq($0) }
76
- end
77
-
78
- context ":caller" do
79
- subject { EventFactory.event(logger, 1, "Hello World") }
80
-
81
- context "with trace" do
82
- its(:file) { should eq(__FILE__) }
83
- its(:line) { should eq("8") }
84
- its(:method) { should eq("event") }
85
- end
86
-
87
- context "without trace" do
88
- before { logger.trace = false }
89
-
90
- its(:file) { should eq("") }
91
- its(:line) { should eq("") }
92
- its(:method) { should eq("") }
93
- end
94
- end
95
-
96
- end
97
-
@@ -1,199 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe Yell::Formatter do
6
- let(:logger) { Yell::Logger.new(:stdout, name: 'Yell') }
7
- let(:message) { "Hello World!" }
8
- let(:event) { Yell::Event.new(logger, 1, message) }
9
- let(:time) { Time.now }
10
-
11
- let(:pattern) { "%m" }
12
- let(:formatter) { Yell::Formatter.new(pattern) }
13
-
14
- let(:output) { formatter.call(event) }
15
-
16
- before do
17
- Timecop.freeze(time)
18
- end
19
-
20
- describe "patterns" do
21
- context "%m" do
22
- let(:pattern) { "%m" }
23
-
24
- it "returns correctly" do
25
- expect(output).to eq("#{event.messages.join(' ')}\n")
26
- end
27
- end
28
-
29
- context "%l" do
30
- let(:pattern) { "%l" }
31
-
32
- it "returns correctly" do
33
- expect(output).to eq("#{Yell::Severities[event.level][0,1]}\n")
34
- end
35
- end
36
-
37
- context "%L" do
38
- let(:pattern) { "%L" }
39
-
40
- it "returns correctly" do
41
- expect(output).to eq("#{Yell::Severities[event.level]}\n")
42
- end
43
- end
44
-
45
- context "%d" do
46
- let(:pattern) { "%d" }
47
-
48
- it "returns correctly" do
49
- expect(output).to eq("#{event.time.iso8601}\n")
50
- end
51
- end
52
-
53
- context "%p" do
54
- let(:pattern) { "%p" }
55
-
56
- it "returns correctly" do
57
- expect(output).to eq("#{event.pid}\n")
58
- end
59
- end
60
-
61
- context "%P" do
62
- let(:pattern) { "%P" }
63
-
64
- it "returns correctly" do
65
- expect(output).to eq("#{event.progname}\n")
66
- end
67
- end
68
-
69
- context "%t" do
70
- let(:pattern) { "%t" }
71
-
72
- it "returns correctly" do
73
- expect(output).to eq("#{event.thread_id}\n")
74
- end
75
- end
76
-
77
- context "%h" do
78
- let(:pattern) { "%h" }
79
-
80
- it "returns correctly" do
81
- expect(output).to eq("#{event.hostname}\n")
82
- end
83
- end
84
-
85
- context ":caller" do
86
- let(:_caller) { [nil, nil, "/path/to/file.rb:123:in `test_method'"] }
87
-
88
- before do
89
- allow(event).to receive(:file) { "/path/to/file.rb" }
90
- allow(event).to receive(:line) { "123" }
91
- allow(event).to receive(:method) { "test_method" }
92
- end
93
-
94
- context "%F" do
95
- let(:pattern) { "%F" }
96
-
97
- it "returns correctly" do
98
- expect(output).to eq("/path/to/file.rb\n")
99
- end
100
- end
101
-
102
- context "%f" do
103
- let(:pattern) { "%f" }
104
-
105
- it "returns correctly" do
106
- expect(output).to eq("file.rb\n")
107
- end
108
- end
109
-
110
- context "%M" do
111
- let(:pattern) { "%M" }
112
-
113
- it "returns correctly" do
114
- expect(output).to eq("test_method\n")
115
- end
116
- end
117
-
118
- context "%n" do
119
- let(:pattern) { "%n" }
120
-
121
- it "returns correctly" do
122
- expect(output).to eq("123\n")
123
- end
124
- end
125
- end
126
-
127
- context "%N" do
128
- let(:pattern) { "%N" }
129
-
130
- it "returns correctly" do
131
- expect(output).to eq("Yell\n")
132
- end
133
- end
134
- end
135
-
136
- describe "presets" do
137
- context "NoFormat" do
138
- let(:pattern) { Yell::NoFormat }
139
-
140
- it "Retrns correctly" do
141
- expect(output).to eq("Hello World!\n")
142
- end
143
- end
144
-
145
- context "DefaultFormat" do
146
- let(:pattern) { Yell::DefaultFormat }
147
-
148
- it "returns correctly" do
149
- expect(output).to eq("#{time.iso8601} [ INFO] #{$$} : Hello World!\n")
150
- end
151
- end
152
-
153
- context "BasicFormat" do
154
- let(:pattern) { Yell::BasicFormat }
155
-
156
- it "returns correctly" do
157
- expect(output).to eq("I, #{time.iso8601} : Hello World!\n")
158
- end
159
- end
160
-
161
- context "ExtendedFormat" do
162
- let(:pattern) { Yell::ExtendedFormat }
163
-
164
- it "Returns correctly" do
165
- expect(output).to eq("#{time.iso8601} [ INFO] #{$$} #{Socket.gethostname} : Hello World!\n")
166
- end
167
- end
168
- end
169
-
170
- describe "Exception" do
171
- let(:message) { StandardError.new("This is an Exception") }
172
-
173
- before do
174
- allow(message).to receive(:backtrace) { ["backtrace"] }
175
- end
176
-
177
- it "returns correctly" do
178
- expect(output).to eq("StandardError: This is an Exception\n\tbacktrace\n")
179
- end
180
- end
181
-
182
- describe "Hash" do
183
- let(:message) { {test: 'message'} }
184
-
185
- it "Returns correctly" do
186
- expect(output).to eq("test: message\n")
187
- end
188
- end
189
-
190
- describe "custom message modifiers" do
191
- let(:formatter) do
192
- Yell::Formatter.new(pattern) { |f| f.modify(String) { |m| "Modified! #{m}" } }
193
- end
194
-
195
- it "Returns correctly" do
196
- expect(output).to eq("Modified! #{message}\n")
197
- end
198
- end
199
- end
@@ -1,200 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Yell::Level do
4
-
5
- context "default" do
6
- let(:level) { Yell::Level.new }
7
-
8
- it "should should return correctly" do
9
- expect(level.at?(:debug)).to be_truthy
10
- expect(level.at?(:info)).to be_truthy
11
- expect(level.at?(:warn)).to be_truthy
12
- expect(level.at?(:error)).to be_truthy
13
- expect(level.at?(:fatal)).to be_truthy
14
- end
15
- end
16
-
17
- context "given a Symbol" do
18
- let(:level) { Yell::Level.new(severity) }
19
-
20
- context ":debug" do
21
- let(:severity) { :debug }
22
-
23
- it "should should return correctly" do
24
- expect(level.at?(:debug)).to be_truthy
25
- expect(level.at?(:info)).to be_truthy
26
- expect(level.at?(:warn)).to be_truthy
27
- expect(level.at?(:error)).to be_truthy
28
- expect(level.at?(:fatal)).to be_truthy
29
- end
30
- end
31
-
32
- context ":info" do
33
- let(:severity) { :info }
34
-
35
- it "should should return correctly" do
36
- expect(level.at?(:debug)).to be_falsey
37
- expect(level.at?(:info)).to be_truthy
38
- expect(level.at?(:warn)).to be_truthy
39
- expect(level.at?(:error)).to be_truthy
40
- expect(level.at?(:fatal)).to be_truthy
41
- end
42
- end
43
-
44
- context ":warn" do
45
- let(:severity) { :warn }
46
-
47
- it "should should return correctly" do
48
- expect(level.at?(:debug)).to be_falsey
49
- expect(level.at?(:info)).to be_falsey
50
- expect(level.at?(:warn)).to be_truthy
51
- expect(level.at?(:error)).to be_truthy
52
- expect(level.at?(:fatal)).to be_truthy
53
- end
54
- end
55
-
56
- context ":error" do
57
- let(:severity) { :error }
58
-
59
- it "should should return correctly" do
60
- expect(level.at?(:debug)).to be_falsey
61
- expect(level.at?(:info)).to be_falsey
62
- expect(level.at?(:warn)).to be_falsey
63
- expect(level.at?(:error)).to be_truthy
64
- expect(level.at?(:fatal)).to be_truthy
65
- end
66
- end
67
-
68
- context ":fatal" do
69
- let(:severity) { :fatal }
70
-
71
- it "should should return correctly" do
72
- expect(level.at?(:debug)).to be_falsey
73
- expect(level.at?(:info)).to be_falsey
74
- expect(level.at?(:warn)).to be_falsey
75
- expect(level.at?(:error)).to be_falsey
76
- expect(level.at?(:fatal)).to be_truthy
77
- end
78
- end
79
- end
80
-
81
- context "given a String" do
82
- let(:level) { Yell::Level.new(severity) }
83
-
84
- context "basic string" do
85
- let(:severity) { 'error' }
86
-
87
- it "should should return correctly" do
88
- expect(level.at?(:debug)).to be_falsey
89
- expect(level.at?(:info)).to be_falsey
90
- expect(level.at?(:warn)).to be_falsey
91
- expect(level.at?(:error)).to be_truthy
92
- expect(level.at?(:fatal)).to be_truthy
93
- end
94
- end
95
-
96
- context "complex string with outer boundaries" do
97
- let(:severity) { 'gte.info lte.error' }
98
-
99
- it "should should return correctly" do
100
- expect(level.at?(:debug)).to be_falsey
101
- expect(level.at?(:info)).to be_truthy
102
- expect(level.at?(:warn)).to be_truthy
103
- expect(level.at?(:error)).to be_truthy
104
- expect(level.at?(:fatal)).to be_falsey
105
- end
106
- end
107
-
108
- context "complex string with inner boundaries" do
109
- let(:severity) { 'gt.info lt.error' }
110
-
111
- it "should be valid" do
112
- expect(level.at?(:debug)).to be_falsey
113
- expect(level.at?(:info)).to be_falsey
114
- expect(level.at?(:warn)).to be_truthy
115
- expect(level.at?(:error)).to be_falsey
116
- expect(level.at?(:fatal)).to be_falsey
117
- end
118
- end
119
-
120
- context "complex string with precise boundaries" do
121
- let(:severity) { 'at.info at.error' }
122
-
123
- it "should be valid" do
124
- expect(level.at?(:debug)).to be_falsey
125
- expect(level.at?(:info)).to be_truthy
126
- expect(level.at?(:warn)).to be_falsey
127
- expect(level.at?(:error)).to be_truthy
128
- expect(level.at?(:fatal)).to be_falsey
129
- end
130
- end
131
-
132
- context "complex string with combined boundaries" do
133
- let(:severity) { 'gte.error at.debug' }
134
-
135
- it "should be valid" do
136
- expect(level.at?(:debug)).to be_truthy
137
- expect(level.at?(:info)).to be_falsey
138
- expect(level.at?(:warn)).to be_falsey
139
- expect(level.at?(:error)).to be_truthy
140
- expect(level.at?(:fatal)).to be_truthy
141
- end
142
- end
143
- end
144
-
145
- context "given an Array" do
146
- let(:level) { Yell::Level.new( %i[debug warn fatal] ) }
147
-
148
- it "should return correctly" do
149
- expect(level.at?(:debug)).to be_truthy
150
- expect(level.at?(:info)).to be_falsey
151
- expect(level.at?(:warn)).to be_truthy
152
- expect(level.at?(:error)).to be_falsey
153
- expect(level.at?(:fatal)).to be_truthy
154
- end
155
- end
156
-
157
- context "given a Range" do
158
- let(:level) { Yell::Level.new( (1..3) ) }
159
-
160
- it "should return correctly" do
161
- expect(level.at?(:debug)).to be_falsey
162
- expect(level.at?(:info)).to be_truthy
163
- expect(level.at?(:warn)).to be_truthy
164
- expect(level.at?(:error)).to be_truthy
165
- expect(level.at?(:fatal)).to be_falsey
166
- end
167
- end
168
-
169
- context "given a Yell::Level instance" do
170
- let(:level) { Yell::Level.new(:warn) }
171
-
172
- it "should return correctly" do
173
- expect(level.at?(:debug)).to be_falsey
174
- expect(level.at?(:info)).to be_falsey
175
- expect(level.at?(:warn)).to be_truthy
176
- expect(level.at?(:error)).to be_truthy
177
- expect(level.at?(:fatal)).to be_truthy
178
- end
179
- end
180
-
181
- context "backwards compatibility" do
182
- let(:level) { Yell::Level.new :warn }
183
-
184
- it "should return correctly to :to_i" do
185
- expect(level.to_i).to eq(2)
186
- end
187
-
188
- it "should typecast with Integer correctly" do
189
- expect(Integer(level)).to eq(2)
190
- end
191
-
192
- it "should be compatible when passing to array (https://github.com/rudionrails/yell/issues/1)" do
193
- severities = %w(FINE INFO WARNING SEVERE SEVERE INFO)
194
-
195
- expect(severities[level]).to eq("WARNING")
196
- end
197
- end
198
-
199
- end
200
-