semantic_logger 2.15.0 → 2.16.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,89 +2,89 @@ require_relative 'test_helper'
2
2
 
3
3
  # Unit Test for SemanticLogger::Logger
4
4
  class DebugAsTraceLoggerTest < Minitest::Test
5
- context SemanticLogger::Logger do
5
+ describe SemanticLogger::Logger do
6
6
  # Test each filter
7
- [ nil, /\ADebugAsTraceLoggerTest/, Proc.new{|l| (/\AExclude/ =~ l.message).nil? } ].each do |filter|
8
- context "filter: #{filter.class.name}" do
9
- setup do
7
+ [nil, /\ADebugAsTraceLoggerTest/, Proc.new { |l| (/\AExclude/ =~ l.message).nil? }].each do |filter|
8
+ describe "filter: #{filter.class.name}" do
9
+ before do
10
10
  # Use a mock logger that just keeps the last logged entry in an instance
11
11
  # variable
12
12
  SemanticLogger.default_level = :trace
13
- @mock_logger = MockLogger.new
14
- appender = SemanticLogger.add_appender(@mock_logger)
15
- appender.filter = filter
13
+ @mock_logger = MockLogger.new
14
+ appender = SemanticLogger.add_appender(@mock_logger)
15
+ appender.filter = filter
16
16
 
17
17
  # Use this test's class name as the application name in the log output
18
- @logger = SemanticLogger::DebugAsTraceLogger.new(self.class)
19
- @hash = { :session_id => 'HSSKLEU@JDK767', :tracking_number => 12345 }
20
- @hash_str = @hash.inspect.sub("{", "\\{").sub("}", "\\}")
18
+ @logger = SemanticLogger::DebugAsTraceLogger.new(DebugAsTraceLoggerTest)
19
+ @hash = {session_id: 'HSSKLEU@JDK767', tracking_number: 12345}
20
+ @hash_str = @hash.inspect.sub("{", "\\{").sub("}", "\\}")
21
21
  assert_equal [], @logger.tags
22
22
  end
23
23
 
24
- teardown do
24
+ after do
25
25
  # Remove all appenders
26
- SemanticLogger.appenders.each{|appender| SemanticLogger.remove_appender(appender)}
26
+ SemanticLogger.appenders.each { |appender| SemanticLogger.remove_appender(appender) }
27
27
  end
28
28
 
29
- context '.level?' do
30
- should 'return true for debug? with :trace level' do
29
+ describe '.level?' do
30
+ it 'return true for debug? with :trace level' do
31
31
  SemanticLogger.default_level = :trace
32
32
  assert_equal :trace, @logger.level
33
- assert_equal true, @logger.debug?
34
- assert_equal true, @logger.trace?
33
+ assert_equal true, @logger.debug?
34
+ assert_equal true, @logger.trace?
35
35
  end
36
36
 
37
- should 'return false for debug? with global :debug level' do
37
+ it 'return false for debug? with global :debug level' do
38
38
  SemanticLogger.default_level = :debug
39
- assert_equal :debug, @logger.level, @logger.inspect
40
- assert_equal false, @logger.debug?, @logger.inspect
41
- assert_equal false, @logger.trace?, @logger.inspect
39
+ assert_equal :debug, @logger.level, @logger.inspect
40
+ assert_equal false, @logger.debug?, @logger.inspect
41
+ assert_equal false, @logger.trace?, @logger.inspect
42
42
  end
43
43
 
44
- should 'return true for debug? with global :info level' do
44
+ it 'return true for debug? with global :info level' do
45
45
  SemanticLogger.default_level = :info
46
- assert_equal :info, @logger.level, @logger.inspect
47
- assert_equal false, @logger.debug?, @logger.inspect
48
- assert_equal false, @logger.trace?, @logger.inspect
46
+ assert_equal :info, @logger.level, @logger.inspect
47
+ assert_equal false, @logger.debug?, @logger.inspect
48
+ assert_equal false, @logger.trace?, @logger.inspect
49
49
  end
50
50
 
51
- should 'return false for debug? with instance :debug level' do
51
+ it 'return false for debug? with instance :debug level' do
52
52
  @logger.level = :debug
53
- assert_equal :debug, @logger.level, @logger.inspect
54
- assert_equal false, @logger.debug?, @logger.inspect
55
- assert_equal false, @logger.trace?, @logger.inspect
53
+ assert_equal :debug, @logger.level, @logger.inspect
54
+ assert_equal false, @logger.debug?, @logger.inspect
55
+ assert_equal false, @logger.trace?, @logger.inspect
56
56
  end
57
57
 
58
- should 'return true for debug? with instance :info level' do
58
+ it 'return true for debug? with instance :info level' do
59
59
  @logger.level = :info
60
- assert_equal :info, @logger.level, @logger.inspect
61
- assert_equal false, @logger.debug?, @logger.inspect
62
- assert_equal false, @logger.trace?, @logger.inspect
60
+ assert_equal :info, @logger.level, @logger.inspect
61
+ assert_equal false, @logger.debug?, @logger.inspect
62
+ assert_equal false, @logger.trace?, @logger.inspect
63
63
  end
64
64
  end
65
65
 
66
- should 'not log trace when level is debug' do
66
+ it 'not log trace when level is debug' do
67
67
  @logger.level = :debug
68
68
  @logger.trace('hello world', @hash) { "Calculations" }
69
69
  SemanticLogger.flush
70
70
  assert_nil @mock_logger.message
71
71
  end
72
72
 
73
- should 'not log debug when level is debug' do
73
+ it 'not log debug when level is debug' do
74
74
  @logger.level = :debug
75
75
  @logger.debug('hello world', @hash) { "Calculations" }
76
76
  SemanticLogger.flush
77
77
  assert_nil @mock_logger.message
78
78
  end
79
79
 
80
- should 'map trace to debug' do
80
+ it 'map trace to debug' do
81
81
  @logger.level = :trace
82
82
  @logger.debug('hello world', @hash) { "Calculations" }
83
83
  SemanticLogger.flush
84
84
  assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ T \[\d+:.+\] DebugAsTraceLoggerTest -- hello world -- Calculations -- #{@hash_str}/, @mock_logger.message
85
85
  end
86
86
 
87
- should 'log trace as trace' do
87
+ it 'log trace as trace' do
88
88
  @logger.level = :trace
89
89
  @logger.trace('hello world', @hash) { "Calculations" }
90
90
  SemanticLogger.flush
@@ -94,4 +94,4 @@ class DebugAsTraceLoggerTest < Minitest::Test
94
94
  end
95
95
 
96
96
  end
97
- end
97
+ end
@@ -8,31 +8,31 @@ end
8
8
  # Unit Test for SemanticLogger::Appender::File
9
9
  #
10
10
  class AppenderFileTest < Minitest::Test
11
- context SemanticLogger::Loggable do
12
- setup do
13
- @time = Time.new
14
- @io = StringIO.new
15
- @appender = SemanticLogger::Appender::File.new(@io)
11
+ describe SemanticLogger::Loggable do
12
+ before do
13
+ @time = Time.new
14
+ @io = StringIO.new
15
+ @appender = SemanticLogger::Appender::File.new(@io)
16
16
  SemanticLogger.default_level = :trace
17
17
  SemanticLogger.add_appender(@appender)
18
- @hash = { :session_id => 'HSSKLEU@JDK767', :tracking_number => 12345 }
19
- @hash_str = @hash.inspect.sub("{", "\\{").sub("}", "\\}")
18
+ @hash = {session_id: 'HSSKLEU@JDK767', tracking_number: 12345}
19
+ @hash_str = @hash.inspect.sub("{", "\\{").sub("}", "\\}")
20
20
  @thread_name = Thread.current.name
21
21
  end
22
22
 
23
- teardown do
23
+ after do
24
24
  SemanticLogger.remove_appender(@appender)
25
25
  end
26
26
 
27
- context "for each log level" do
27
+ describe "for each log level" do
28
28
  # Ensure that any log level can be logged
29
29
  SemanticLogger::LEVELS.each do |level|
30
- should "log #{level} information with class attribute" do
30
+ it "log #{level} information with class attribute" do
31
31
  TestAttribute.logger.send(level, "hello #{level}", @hash)
32
32
  SemanticLogger.flush
33
33
  assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ \w \[\d+:#{@thread_name}\] TestAttribute -- hello #{level} -- #{@hash_str}\n/, @io.string
34
34
  end
35
- should "log #{level} information with instance attribute" do
35
+ it "log #{level} information with instance attribute" do
36
36
  TestAttribute.new.logger.send(level, "hello #{level}", @hash)
37
37
  SemanticLogger.flush
38
38
  assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ \w \[\d+:#{@thread_name}\] TestAttribute -- hello #{level} -- #{@hash_str}\n/, @io.string
@@ -41,4 +41,4 @@ class AppenderFileTest < Minitest::Test
41
41
  end
42
42
 
43
43
  end
44
- end
44
+ end
data/test/logger_test.rb CHANGED
@@ -2,48 +2,48 @@ require_relative 'test_helper'
2
2
 
3
3
  # Unit Test for SemanticLogger::Logger
4
4
  class LoggerTest < Minitest::Test
5
- context SemanticLogger::Logger do
5
+ describe SemanticLogger::Logger do
6
6
  # Test each filter
7
- [ nil, /\ALogger/, Proc.new{|l| (/\AExclude/ =~ l.message).nil? } ].each do |filter|
8
- context "filter: #{filter.class.name}" do
9
- setup do
7
+ [nil, /\ALogger/, Proc.new { |l| (/\AExclude/ =~ l.message).nil? }].each do |filter|
8
+ describe "filter: #{filter.class.name}" do
9
+ before do
10
10
  # Use a mock logger that just keeps the last logged entry in an instance
11
11
  # variable
12
12
  SemanticLogger.default_level = :trace
13
- @mock_logger = MockLogger.new
14
- appender = SemanticLogger.add_appender(@mock_logger)
15
- appender.filter = filter
13
+ @mock_logger = MockLogger.new
14
+ appender = SemanticLogger.add_appender(@mock_logger)
15
+ appender.filter = filter
16
16
 
17
17
  # Add mock metric subscriber
18
- $last_metric = nil
18
+ $last_metric = nil
19
19
  SemanticLogger.on_metric do |log_struct|
20
20
  $last_metric = log_struct.dup
21
21
  end
22
22
 
23
23
  # Use this test's class name as the application name in the log output
24
- @logger = SemanticLogger[self.class]
25
- @hash = { :session_id => 'HSSKLEU@JDK767', :tracking_number => 12345 }
24
+ @logger = SemanticLogger[LoggerTest]
25
+ @hash = {session_id: 'HSSKLEU@JDK767', tracking_number: 12345}
26
26
  @hash_str = @hash.inspect.sub("{", "\\{").sub("}", "\\}")
27
27
  assert_equal [], @logger.tags
28
28
  end
29
29
 
30
- teardown do
30
+ after do
31
31
  # Remove all appenders
32
- SemanticLogger.appenders.each{|appender| SemanticLogger.remove_appender(appender)}
32
+ SemanticLogger.appenders.each { |appender| SemanticLogger.remove_appender(appender) }
33
33
  end
34
34
 
35
35
  # Ensure that any log level can be logged
36
36
  SemanticLogger::LEVELS.each do |level|
37
37
  level_char = level.to_s.upcase[0]
38
38
 
39
- context level do
40
- should "log" do
39
+ describe level do
40
+ it "log" do
41
41
  @logger.send(level, 'hello world', @hash) { "Calculations" }
42
42
  SemanticLogger.flush
43
43
  assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:.+\] LoggerTest -- hello world -- Calculations -- #{@hash_str}/, @mock_logger.message
44
44
  end
45
45
 
46
- should "exclude log messages using Proc filter" do
46
+ it "exclude log messages using Proc filter" do
47
47
  if filter.is_a?(Proc)
48
48
  @logger.send(level, 'Exclude this log message', @hash) { "Calculations" }
49
49
  SemanticLogger.flush
@@ -51,7 +51,7 @@ class LoggerTest < Minitest::Test
51
51
  end
52
52
  end
53
53
 
54
- should "exclude log messages using RegExp filter" do
54
+ it "exclude log messages using RegExp filter" do
55
55
  if filter.is_a?(Regexp)
56
56
  logger = SemanticLogger::Logger.new('NotLogger', :trace, filter)
57
57
  logger.send(level, 'Ignore all log messages from this class', @hash) { "Calculations" }
@@ -63,8 +63,8 @@ class LoggerTest < Minitest::Test
63
63
  end
64
64
  end
65
65
 
66
- context "tagged logging" do
67
- should "add tags to log entries" do
66
+ describe "tagged logging" do
67
+ it "add tags to log entries" do
68
68
  @logger.tagged('12345', 'DJHSFK') do
69
69
  @logger.info('Hello world')
70
70
  SemanticLogger.flush
@@ -72,7 +72,7 @@ class LoggerTest < Minitest::Test
72
72
  end
73
73
  end
74
74
 
75
- should "add embedded tags to log entries" do
75
+ it "add embedded tags to log entries" do
76
76
  @logger.tagged('First Level', 'tags') do
77
77
  @logger.tagged('Second Level') do
78
78
  @logger.info('Hello world')
@@ -85,11 +85,11 @@ class LoggerTest < Minitest::Test
85
85
  end
86
86
  end
87
87
 
88
- should "add payload to log entries" do
89
- hash = {:tracking_number=>"123456", :even=>2, :more=>"data"}
88
+ it "add payload to log entries" do
89
+ hash = {tracking_number: "123456", even: 2, more: "data"}
90
90
  hash_str = hash.inspect.sub("{", "\\{").sub("}", "\\}")
91
- @logger.with_payload(:tracking_number => '123456') do
92
- @logger.with_payload(:even => 2, :more => 'data') do
91
+ @logger.with_payload(tracking_number: '123456') do
92
+ @logger.with_payload(even: 2, more: 'data') do
93
93
  @logger.info('Hello world')
94
94
  SemanticLogger.flush
95
95
  assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ I \[\d+:.+\] LoggerTest -- Hello world -- #{hash_str}/, @mock_logger.message
@@ -98,10 +98,10 @@ class LoggerTest < Minitest::Test
98
98
  end
99
99
  end
100
100
 
101
- context "Ruby Logger" do
101
+ describe "Ruby Logger" do
102
102
  # Ensure that any log level can be logged
103
103
  Logger::Severity.constants.each do |level|
104
- should "log Ruby logger #{level} info" do
104
+ it "log Ruby logger #{level} info" do
105
105
  @logger.level = Logger::Severity.const_get(level)
106
106
  if level.to_s == 'UNKNOWN'
107
107
  assert_equal Logger::Severity.const_get('ERROR')+1, @logger.send(:level_index)
@@ -112,37 +112,37 @@ class LoggerTest < Minitest::Test
112
112
  end
113
113
  end
114
114
 
115
- context "benchmark" do
115
+ describe "benchmark" do
116
116
  # Ensure that any log level can be benchmarked and logged
117
117
  SemanticLogger::LEVELS.each do |level|
118
118
  level_char = level.to_s.upcase[0]
119
119
 
120
- context 'direct method' do
121
- should "log #{level} info" do
120
+ describe 'direct method' do
121
+ it "log #{level} info" do
122
122
  assert_equal "result", @logger.send("benchmark_#{level}".to_sym, 'hello world') { "result" } # Measure duration of the supplied block
123
123
  SemanticLogger.flush
124
124
  assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world/, @mock_logger.message
125
125
  end
126
126
 
127
- should "log #{level} info with payload" do
127
+ it "log #{level} info with payload" do
128
128
  assert_equal "result", @logger.send("benchmark_#{level}".to_sym, 'hello world', payload: @hash) { "result" } # Measure duration of the supplied block
129
129
  SemanticLogger.flush
130
130
  assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world -- #{@hash_str}/, @mock_logger.message
131
131
  end
132
132
 
133
- should "not log #{level} info when block is faster than :min_duration" do
134
- assert_equal "result", @logger.send("benchmark_#{level}".to_sym, 'hello world', :min_duration => 500) { "result" } # Measure duration of the supplied block
133
+ it "not log #{level} info when block is faster than :min_duration" do
134
+ assert_equal "result", @logger.send("benchmark_#{level}".to_sym, 'hello world', min_duration: 500) { "result" } # Measure duration of the supplied block
135
135
  SemanticLogger.flush
136
136
  assert_nil @mock_logger.message
137
137
  end
138
138
 
139
- should "log #{level} info when block duration exceeds :min_duration" do
140
- assert_equal "result", @logger.send("benchmark_#{level}".to_sym, 'hello world', :min_duration => 200, payload: @hash) { sleep 0.5; "result" } # Measure duration of the supplied block
139
+ it "log #{level} info when block duration exceeds :min_duration" do
140
+ assert_equal "result", @logger.send("benchmark_#{level}".to_sym, 'hello world', min_duration: 200, payload: @hash) { sleep 0.5; "result" } # Measure duration of the supplied block
141
141
  SemanticLogger.flush
142
142
  assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world -- #{@hash_str}/, @mock_logger.message
143
143
  end
144
144
 
145
- should "log #{level} info with an exception" do
145
+ it "log #{level} info with an exception" do
146
146
  assert_raises RuntimeError do
147
147
  @logger.send("benchmark_#{level}", 'hello world', payload: @hash) { raise RuntimeError.new("Test") } # Measure duration of the supplied block
148
148
  end
@@ -150,7 +150,7 @@ class LoggerTest < Minitest::Test
150
150
  assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world -- Exception: RuntimeError: Test -- #{@hash_str}/, @mock_logger.message
151
151
  end
152
152
 
153
- should "change log #{level} info with an exception" do
153
+ it "change log #{level} info with an exception" do
154
154
  assert_raises RuntimeError do
155
155
  @logger.send("benchmark_#{level}", 'hello world', payload: @hash, on_exception_level: :fatal) { raise RuntimeError.new("Test") } # Measure duration of the supplied block
156
156
  end
@@ -158,41 +158,41 @@ class LoggerTest < Minitest::Test
158
158
  assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ F \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world -- Exception: RuntimeError: Test -- #{@hash_str}/, @mock_logger.message
159
159
  end
160
160
 
161
- should "log #{level} info with metric" do
161
+ it "log #{level} info with metric" do
162
162
  metric_name = '/my/custom/metric'
163
- assert_equal "result", @logger.send("benchmark_#{level}".to_sym, 'hello world', :metric => metric_name) { "result" } # Measure duration of the supplied block
163
+ assert_equal "result", @logger.send("benchmark_#{level}".to_sym, 'hello world', metric: metric_name) { "result" } # Measure duration of the supplied block
164
164
  SemanticLogger.flush
165
165
  assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world/, @mock_logger.message
166
166
  assert metric_name, $last_metric.metric
167
167
  end
168
168
  end
169
169
 
170
- context 'generic method' do
171
- should "log #{level} info" do
170
+ describe 'generic method' do
171
+ it "log #{level} info" do
172
172
  assert_equal "result", @logger.benchmark(level, 'hello world') { "result" } # Measure duration of the supplied block
173
173
  SemanticLogger.flush
174
174
  assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world/, @mock_logger.message
175
175
  end
176
176
 
177
- should "log #{level} info with payload" do
177
+ it "log #{level} info with payload" do
178
178
  assert_equal "result", @logger.benchmark(level, 'hello world', payload: @hash) { "result" } # Measure duration of the supplied block
179
179
  SemanticLogger.flush
180
180
  assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world -- #{@hash_str}/, @mock_logger.message
181
181
  end
182
182
 
183
- should "not log #{level} info when block is faster than :min_duration" do
184
- assert_equal "result", @logger.benchmark(level, 'hello world', :min_duration => 500) { "result" } # Measure duration of the supplied block
183
+ it "not log #{level} info when block is faster than :min_duration" do
184
+ assert_equal "result", @logger.benchmark(level, 'hello world', min_duration: 500) { "result" } # Measure duration of the supplied block
185
185
  SemanticLogger.flush
186
186
  assert_nil @mock_logger.message
187
187
  end
188
188
 
189
- should "log #{level} info when block duration exceeds :min_duration" do
190
- assert_equal "result", @logger.benchmark(level, 'hello world', :min_duration => 200, payload: @hash) { sleep 0.5; "result" } # Measure duration of the supplied block
189
+ it "log #{level} info when block duration exceeds :min_duration" do
190
+ assert_equal "result", @logger.benchmark(level, 'hello world', min_duration: 200, payload: @hash) { sleep 0.5; "result" } # Measure duration of the supplied block
191
191
  SemanticLogger.flush
192
192
  assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world -- #{@hash_str}/, @mock_logger.message
193
193
  end
194
194
 
195
- should "log #{level} info with an exception" do
195
+ it "log #{level} info with an exception" do
196
196
  assert_raises RuntimeError do
197
197
  @logger.benchmark(level, 'hello world', payload: @hash) { raise RuntimeError.new("Test") } # Measure duration of the supplied block
198
198
  end
@@ -200,9 +200,9 @@ class LoggerTest < Minitest::Test
200
200
  assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world -- Exception: RuntimeError: Test -- #{@hash_str}/, @mock_logger.message
201
201
  end
202
202
 
203
- should "log #{level} info with metric" do
203
+ it "log #{level} info with metric" do
204
204
  metric_name = '/my/custom/metric'
205
- assert_equal "result", @logger.benchmark(level, 'hello world', :metric => metric_name) { "result" } # Measure duration of the supplied block
205
+ assert_equal "result", @logger.benchmark(level, 'hello world', metric: metric_name) { "result" } # Measure duration of the supplied block
206
206
  SemanticLogger.flush
207
207
  assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world/, @mock_logger.message
208
208
  assert metric_name, $last_metric.metric
@@ -210,13 +210,13 @@ class LoggerTest < Minitest::Test
210
210
  end
211
211
  end
212
212
 
213
- should "log when the block performs a return" do
213
+ it "log when the block performs a return" do
214
214
  assert_equal "Good", function_with_return(@logger)
215
215
  SemanticLogger.flush
216
216
  assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ I \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world -- #{@hash_str}/, @mock_logger.message
217
217
  end
218
218
 
219
- should 'not log at a level below the silence level' do
219
+ it 'not log at a level below the silence level' do
220
220
  SemanticLogger.default_level = :info
221
221
  @logger.benchmark_info('hello world', silence: :error) do
222
222
  @logger.warn "don't log me"
@@ -225,9 +225,9 @@ class LoggerTest < Minitest::Test
225
225
  assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ I \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world/, @mock_logger.message
226
226
  end
227
227
 
228
- should 'log at a silence level below the default level' do
228
+ it 'log at a silence level below the default level' do
229
229
  SemanticLogger.default_level = :info
230
- first_message = nil
230
+ first_message = nil
231
231
  @logger.benchmark_info('hello world', silence: :trace) do
232
232
  @logger.debug('hello world', @hash) { "Calculations" }
233
233
  SemanticLogger.flush
@@ -240,12 +240,12 @@ class LoggerTest < Minitest::Test
240
240
  end
241
241
  end
242
242
 
243
- context '.default_level' do
244
- setup do
243
+ describe '.default_level' do
244
+ before do
245
245
  SemanticLogger.default_level = :debug
246
246
  end
247
247
 
248
- should 'not log at a level below the global default' do
248
+ it 'not log at a level below the global default' do
249
249
  assert_equal :debug, SemanticLogger.default_level
250
250
  assert_equal :debug, @logger.level
251
251
  @logger.trace('hello world', @hash) { "Calculations" }
@@ -253,7 +253,7 @@ class LoggerTest < Minitest::Test
253
253
  assert_nil @mock_logger.message
254
254
  end
255
255
 
256
- should 'log at the instance level' do
256
+ it 'log at the instance level' do
257
257
  assert_equal :debug, SemanticLogger.default_level
258
258
  @logger.level = :trace
259
259
  assert_equal :trace, @logger.level
@@ -262,7 +262,7 @@ class LoggerTest < Minitest::Test
262
262
  assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ T \[\d+:.+\] LoggerTest -- hello world -- Calculations -- #{@hash_str}/, @mock_logger.message
263
263
  end
264
264
 
265
- should 'not log at a level below the instance level' do
265
+ it 'not log at a level below the instance level' do
266
266
  assert_equal :debug, SemanticLogger.default_level
267
267
  @logger.level = :warn
268
268
  assert_equal :warn, @logger.level
@@ -272,12 +272,12 @@ class LoggerTest < Minitest::Test
272
272
  end
273
273
  end
274
274
 
275
- context '.silence' do
276
- setup do
275
+ describe '.silence' do
276
+ before do
277
277
  SemanticLogger.default_level = :info
278
278
  end
279
279
 
280
- should 'not log at a level below the silence level' do
280
+ it 'not log at a level below the silence level' do
281
281
  assert_equal :info, SemanticLogger.default_level
282
282
  assert_equal :info, @logger.level
283
283
  @logger.silence do
@@ -290,7 +290,7 @@ class LoggerTest < Minitest::Test
290
290
  assert_nil @mock_logger.message
291
291
  end
292
292
 
293
- should 'log at the instance level even with the silencer at a higher level' do
293
+ it 'log at the instance level even with the silencer at a higher level' do
294
294
  @logger.level = :trace
295
295
  assert_equal :trace, @logger.level
296
296
  @logger.silence do
@@ -300,7 +300,7 @@ class LoggerTest < Minitest::Test
300
300
  assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ T \[\d+:.+\] LoggerTest -- hello world -- Calculations -- #{@hash_str}/, @mock_logger.message
301
301
  end
302
302
 
303
- should 'log at a silence level below the default level' do
303
+ it 'log at a silence level below the default level' do
304
304
  assert_equal :info, SemanticLogger.default_level
305
305
  assert_equal :info, @logger.level
306
306
  @logger.silence(:debug) do
@@ -311,55 +311,54 @@ class LoggerTest < Minitest::Test
311
311
  end
312
312
  end
313
313
 
314
- context '.level?' do
315
- should 'return true for debug? with :trace level' do
314
+ describe '.level?' do
315
+ it 'return true for debug? with :trace level' do
316
316
  SemanticLogger.default_level = :trace
317
317
  assert_equal :trace, @logger.level
318
- assert_equal true, @logger.debug?
319
- assert_equal true, @logger.trace?
318
+ assert_equal true, @logger.debug?
319
+ assert_equal true, @logger.trace?
320
320
  end
321
321
 
322
- should 'return false for debug? with global :debug level' do
322
+ it 'return false for debug? with global :debug level' do
323
323
  SemanticLogger.default_level = :debug
324
- assert_equal :debug, @logger.level, @logger.inspect
325
- assert_equal true, @logger.debug?, @logger.inspect
326
- assert_equal false, @logger.trace?, @logger.inspect
324
+ assert_equal :debug, @logger.level, @logger.inspect
325
+ assert_equal true, @logger.debug?, @logger.inspect
326
+ assert_equal false, @logger.trace?, @logger.inspect
327
327
  end
328
328
 
329
- should 'return true for debug? with global :info level' do
329
+ it 'return true for debug? with global :info level' do
330
330
  SemanticLogger.default_level = :info
331
- assert_equal :info, @logger.level, @logger.inspect
332
- assert_equal false, @logger.debug?, @logger.inspect
333
- assert_equal false, @logger.trace?, @logger.inspect
331
+ assert_equal :info, @logger.level, @logger.inspect
332
+ assert_equal false, @logger.debug?, @logger.inspect
333
+ assert_equal false, @logger.trace?, @logger.inspect
334
334
  end
335
335
 
336
- should 'return false for debug? with instance :debug level' do
336
+ it 'return false for debug? with instance :debug level' do
337
337
  @logger.level = :debug
338
- assert_equal :debug, @logger.level, @logger.inspect
339
- assert_equal true, @logger.debug?, @logger.inspect
340
- assert_equal false, @logger.trace?, @logger.inspect
338
+ assert_equal :debug, @logger.level, @logger.inspect
339
+ assert_equal true, @logger.debug?, @logger.inspect
340
+ assert_equal false, @logger.trace?, @logger.inspect
341
341
  end
342
342
 
343
- should 'return true for debug? with instance :info level' do
343
+ it 'return true for debug? with instance :info level' do
344
344
  @logger.level = :info
345
- assert_equal :info, @logger.level, @logger.inspect
346
- assert_equal false, @logger.debug?, @logger.inspect
347
- assert_equal false, @logger.trace?, @logger.inspect
345
+ assert_equal :info, @logger.level, @logger.inspect
346
+ assert_equal false, @logger.debug?, @logger.inspect
347
+ assert_equal false, @logger.trace?, @logger.inspect
348
348
  end
349
349
  end
350
350
 
351
351
  end
352
352
  end
353
353
 
354
- end
355
-
356
- # Make sure that benchmark still logs when a block uses return to return from
357
- # a function
358
- def function_with_return(logger)
359
- logger.benchmark_info('hello world', payload: @hash) do
360
- return "Good"
354
+ # Make sure that benchmark still logs when a block uses return to return from
355
+ # a function
356
+ def function_with_return(logger)
357
+ logger.benchmark_info('hello world', payload: @hash) do
358
+ return "Good"
359
+ end
360
+ "Bad"
361
361
  end
362
- "Bad"
363
- end
364
362
 
365
- end
363
+ end
364
+ end