steno 1.3.4 → 1.3.5

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.
Files changed (43) hide show
  1. checksums.yaml +5 -5
  2. data/NOTICE +14 -0
  3. data/Rakefile +6 -7
  4. data/bin/steno-prettify +24 -25
  5. data/lib/steno/codec/base.rb +1 -1
  6. data/lib/steno/codec/json.rb +16 -19
  7. data/lib/steno/codec.rb +2 -2
  8. data/lib/steno/config.rb +22 -33
  9. data/lib/steno/context.rb +3 -3
  10. data/lib/steno/json_prettifier.rb +30 -29
  11. data/lib/steno/log_level.rb +1 -2
  12. data/lib/steno/logger.rb +22 -26
  13. data/lib/steno/record.rb +5 -15
  14. data/lib/steno/sink/base.rb +2 -3
  15. data/lib/steno/sink/counter.rb +4 -8
  16. data/lib/steno/sink/eventlog.rb +16 -17
  17. data/lib/steno/sink/fluentd.rb +4 -5
  18. data/lib/steno/sink/io.rb +8 -12
  19. data/lib/steno/sink/syslog.rb +15 -13
  20. data/lib/steno/sink.rb +6 -6
  21. data/lib/steno/tagged_logger.rb +2 -3
  22. data/lib/steno/version.rb +1 -1
  23. data/lib/steno.rb +16 -21
  24. data/spec/spec_helper.rb +4 -4
  25. data/spec/support/barrier.rb +2 -2
  26. data/spec/support/shared_context_specs.rb +4 -4
  27. data/spec/unit/config_spec.rb +87 -94
  28. data/spec/unit/context_spec.rb +17 -17
  29. data/spec/unit/core_ext_spec.rb +11 -11
  30. data/spec/unit/json_codec_spec.rb +26 -26
  31. data/spec/unit/json_prettifier_spec.rb +22 -22
  32. data/spec/unit/log_level_spec.rb +5 -6
  33. data/spec/unit/logger_spec.rb +39 -39
  34. data/spec/unit/record_spec.rb +10 -10
  35. data/spec/unit/sink/counter_spec.rb +7 -7
  36. data/spec/unit/sink/eventlog_spec.rb +14 -15
  37. data/spec/unit/sink/fluentd_spec.rb +26 -26
  38. data/spec/unit/sink/io_spec.rb +49 -49
  39. data/spec/unit/sink/syslog_spec.rb +43 -19
  40. data/spec/unit/steno_spec.rb +24 -24
  41. data/spec/unit/tagged_logger_spec.rb +12 -12
  42. data/steno.gemspec +28 -27
  43. metadata +61 -38
@@ -1,29 +1,28 @@
1
- require "fileutils"
2
- require "yaml"
1
+ require 'fileutils'
2
+ require 'yaml'
3
3
 
4
- require "spec_helper"
4
+ require 'spec_helper'
5
5
 
6
6
  describe Steno::Config do
7
-
8
7
  if Steno::Sink::WINDOWS
9
- describe ".from_hash" do
10
- before :each do
11
- @log_path = "some_file"
8
+ describe '.from_hash' do
9
+ before do
10
+ @log_path = 'some_file'
12
11
 
13
- @mock_sink_file = double("sink")
12
+ @mock_sink_file = double('sink')
14
13
  expect(@mock_sink_file).to receive(:codec=)
15
14
  expect(Steno::Sink::IO).to receive(:for_file).with(@log_path,
16
- :max_retries => 5)
17
- .and_return(@mock_sink_file)
15
+ max_retries: 5)
16
+ .and_return(@mock_sink_file)
18
17
 
19
- @mock_sink_eventlog = double("sink")
18
+ @mock_sink_eventlog = double('sink')
20
19
  expect(@mock_sink_eventlog).to receive(:codec=)
21
- expect(@mock_sink_eventlog).to receive(:open).with("test")
22
- expect(Steno::Sink::Eventlog).to receive(:instance).twice()
23
- .and_return(@mock_sink_eventlog)
20
+ expect(@mock_sink_eventlog).to receive(:open).with('test')
21
+ expect(Steno::Sink::Eventlog).to receive(:instance).twice
22
+ .and_return(@mock_sink_eventlog)
24
23
  end
25
24
 
26
- after :each do
25
+ after do
27
26
  @config = Steno::Config.from_hash(@hash)
28
27
 
29
28
  expect(@config.default_log_level).to eq(:debug2)
@@ -31,49 +30,48 @@ describe Steno::Config do
31
30
  expect(@config.codec.class).to eq(Steno::Codec::Json)
32
31
 
33
32
  expect(@config.sinks.size).to eq(2)
34
- expect(@config.sinks).to match_array([@mock_sink_file, @mock_sink_eventlog])
33
+ expect(@config.sinks).to contain_exactly(@mock_sink_file, @mock_sink_eventlog)
35
34
  end
36
35
 
37
- it "should work for symbolized keys" do
36
+ it 'works for symbolized keys' do
38
37
  @hash = {
39
- :file => @log_path,
40
- :level => "debug2",
41
- :default_log_level => "warn",
42
- :eventlog => "test",
43
- :max_retries => 5,
38
+ file: @log_path,
39
+ level: 'debug2',
40
+ default_log_level: 'warn',
41
+ eventlog: 'test',
42
+ max_retries: 5
44
43
  }
45
44
  end
46
45
 
47
- it "should work for non-symbolized keys" do
46
+ it 'works for non-symbolized keys' do
48
47
  @hash = {
49
- "file" => @log_path,
50
- "level" => "debug2",
51
- "default_log_level" => "warn",
52
- "eventlog" => "test",
53
- "max_retries" => 5,
48
+ 'file' => @log_path,
49
+ 'level' => 'debug2',
50
+ 'default_log_level' => 'warn',
51
+ 'eventlog' => 'test',
52
+ 'max_retries' => 5
54
53
  }
55
54
  end
56
-
57
55
  end
58
56
  else
59
- describe ".from_hash" do
60
- before :each do
61
- @log_path = "some_file"
57
+ describe '.from_hash' do
58
+ before do
59
+ @log_path = 'some_file'
62
60
 
63
- @mock_sink_file = double("sink")
61
+ @mock_sink_file = double('sink')
64
62
  allow(@mock_sink_file).to receive(:codec=)
65
63
  expect(Steno::Sink::IO).to receive(:for_file).with(@log_path,
66
- :max_retries => 5)
67
- .and_return(@mock_sink_file)
64
+ max_retries: 5)
65
+ .and_return(@mock_sink_file)
68
66
 
69
- @mock_sink_syslog = double("sink")
67
+ @mock_sink_syslog = double('sink')
70
68
  expect(@mock_sink_syslog).to receive(:codec=)
71
- expect(@mock_sink_syslog).to receive(:open).with("test")
72
- expect(Steno::Sink::Syslog).to receive(:instance).twice()
73
- .and_return(@mock_sink_syslog)
69
+ expect(@mock_sink_syslog).to receive(:open).with('test')
70
+ expect(Steno::Sink::Syslog).to receive(:instance).twice
71
+ .and_return(@mock_sink_syslog)
74
72
  end
75
73
 
76
- after :each do
74
+ after do
77
75
  @config = Steno::Config.from_hash(@hash)
78
76
 
79
77
  expect(@config.default_log_level).to eq(:debug2)
@@ -81,44 +79,43 @@ describe Steno::Config do
81
79
  expect(@config.codec.class).to eq(Steno::Codec::Json)
82
80
 
83
81
  expect(@config.sinks.size).to eq(2)
84
- expect(@config.sinks).to match_array([@mock_sink_file, @mock_sink_syslog])
82
+ expect(@config.sinks).to contain_exactly(@mock_sink_file, @mock_sink_syslog)
85
83
  end
86
84
 
87
- it "should work for symbolized keys" do
85
+ it 'works for symbolized keys' do
88
86
  @hash = {
89
- :file => @log_path,
90
- :level => "debug2",
91
- :default_log_level => "warn",
92
- :syslog => "test",
93
- :max_retries => 5,
87
+ file: @log_path,
88
+ level: 'debug2',
89
+ default_log_level: 'warn',
90
+ syslog: 'test',
91
+ max_retries: 5
94
92
  }
95
93
  end
96
94
 
97
- it "should work for non-symbolized keys" do
95
+ it 'works for non-symbolized keys' do
98
96
  @hash = {
99
- "file" => @log_path,
100
- "level" => "debug2",
101
- "default_log_level" => "warn",
102
- "syslog" => "test",
103
- "max_retries" => 5,
97
+ 'file' => @log_path,
98
+ 'level' => 'debug2',
99
+ 'default_log_level' => 'warn',
100
+ 'syslog' => 'test',
101
+ 'max_retries' => 5
104
102
  }
105
103
  end
106
-
107
104
  end
108
105
  end
109
106
 
110
- describe ".from_file" do
111
- before :each do
107
+ describe '.from_file' do
108
+ before do
112
109
  @tmpdir = Dir.mktmpdir
113
- @config_path = File.join(@tmpdir, "config.yml")
114
- @log_path = File.join(@tmpdir, "test.log")
110
+ @config_path = File.join(@tmpdir, 'config.yml')
111
+ @log_path = File.join(@tmpdir, 'test.log')
115
112
  end
116
113
 
117
- after :each do
114
+ after do
118
115
  FileUtils.rm_rf(@tmpdir)
119
116
  end
120
117
 
121
- it "should return Steno::Config instance with sane defaults" do
118
+ it 'returns Steno::Config instance with sane defaults' do
122
119
  write_config(@config_path, {})
123
120
 
124
121
  config = Steno::Config.from_file(@config_path)
@@ -134,60 +131,60 @@ describe Steno::Config do
134
131
  expect(config.codec.iso8601_timestamps?).to eq(false)
135
132
  end
136
133
 
137
- it "should configure json codec with readable dates if iso8601_timestamps is true" do
138
- write_config(@config_path, {"iso8601_timestamps" => "true"})
134
+ it 'configures json codec with readable dates if iso8601_timestamps is true' do
135
+ write_config(@config_path, { 'iso8601_timestamps' => 'true' })
139
136
  config = Steno::Config.from_file(@config_path)
140
137
  expect(config.codec.class).to eq(Steno::Codec::Json)
141
138
  expect(config.codec.iso8601_timestamps?).to eq(true)
142
139
  end
143
140
 
144
- it "should set the default_log_level if a key with the same name is supplied" do
145
- write_config(@config_path, {"level" => "debug2"})
141
+ it 'sets the default_log_level if a key with the same name is supplied' do
142
+ write_config(@config_path, { 'level' => 'debug2' })
146
143
  expect(Steno::Config.from_file(@config_path).default_log_level).to eq(:debug2)
147
144
 
148
- write_config(@config_path, {"default_log_level" => "debug2"})
145
+ write_config(@config_path, { 'default_log_level' => 'debug2' })
149
146
  expect(Steno::Config.from_file(@config_path).default_log_level).to eq(:debug2)
150
147
  end
151
148
 
152
- it "should read the 'level' key if both default_log_level and level are spscified" do
153
- write_config(@config_path, {"level" => "debug2",
154
- "default_log_level" => "warn"})
149
+ it "reads the 'level' key if both default_log_level and level are spscified" do
150
+ write_config(@config_path, { 'level' => 'debug2',
151
+ 'default_log_level' => 'warn' })
155
152
  expect(Steno::Config.from_file(@config_path).default_log_level).to eq(:debug2)
156
153
  end
157
154
 
158
- it "should add a file sink if the 'file' key is specified" do
159
- write_config(@config_path, {"file" => @log_path, "max_retries" => 2})
160
- mock_sink = double("sink")
155
+ it "adds a file sink if the 'file' key is specified" do
156
+ write_config(@config_path, { 'file' => @log_path, 'max_retries' => 2 })
157
+ mock_sink = double('sink')
161
158
  expect(mock_sink).to receive(:codec=)
162
159
 
163
- expect(Steno::Sink::IO).to receive(:for_file).
164
- with(@log_path, :max_retries => 2).and_return(mock_sink)
160
+ expect(Steno::Sink::IO).to receive(:for_file)
161
+ .with(@log_path, max_retries: 2).and_return(mock_sink)
165
162
  config = Steno::Config.from_file(@config_path)
166
163
  expect(config.sinks.size).to eq(1)
167
164
  expect(config.sinks[0]).to eq(mock_sink)
168
165
  end
169
166
 
170
167
  if Steno::Sink::WINDOWS
171
- it "should add a event sink if the 'eventlog' key is specified" do
172
- write_config(@config_path, {"eventlog" => "test"})
173
- mock_sink = double("sink")
174
- expect(mock_sink).to receive(:open).with("test")
168
+ it "adds a event sink if the 'eventlog' key is specified" do
169
+ write_config(@config_path, { 'eventlog' => 'test' })
170
+ mock_sink = double('sink')
171
+ expect(mock_sink).to receive(:open).with('test')
175
172
  expect(mock_sink).to receive(:codec=)
176
173
 
177
- expect(Steno::Sink::Eventlog).to receive(:instance).twice().and_return(mock_sink)
174
+ expect(Steno::Sink::Eventlog).to receive(:instance).twice.and_return(mock_sink)
178
175
 
179
176
  config = Steno::Config.from_file(@config_path)
180
177
  expect(config.sinks.size).to eq(1)
181
178
  expect(config.sinks[0]).to eq(mock_sink)
182
179
  end
183
180
  else
184
- it "should add a syslog sink if the 'syslog' key is specified" do
185
- write_config(@config_path, {"syslog" => "test"})
186
- mock_sink = double("sink")
187
- expect(mock_sink).to receive(:open).with("test")
181
+ it "adds a syslog sink if the 'syslog' key is specified" do
182
+ write_config(@config_path, { 'syslog' => 'test' })
183
+ mock_sink = double('sink')
184
+ expect(mock_sink).to receive(:open).with('test')
188
185
  expect(mock_sink).to receive(:codec=)
189
186
 
190
- expect(Steno::Sink::Syslog).to receive(:instance).twice().and_return(mock_sink)
187
+ expect(Steno::Sink::Syslog).to receive(:instance).twice.and_return(mock_sink)
191
188
 
192
189
  config = Steno::Config.from_file(@config_path)
193
190
  expect(config.sinks.size).to eq(1)
@@ -195,11 +192,9 @@ describe Steno::Config do
195
192
  end
196
193
  end
197
194
 
198
-
199
-
200
- it "should add an io sink to stdout if no sinks are explicitly specified in the config file" do
195
+ it 'adds an io sink to stdout if no sinks are explicitly specified in the config file' do
201
196
  write_config(@config_path, {})
202
- mock_sink = double("sink")
197
+ mock_sink = double('sink')
203
198
  expect(mock_sink).to receive(:codec=)
204
199
 
205
200
  expect(Steno::Sink::IO).to receive(:new).with(STDOUT).and_return(mock_sink)
@@ -209,21 +204,19 @@ describe Steno::Config do
209
204
  expect(config.sinks[0]).to eq(mock_sink)
210
205
  end
211
206
 
212
- it "should merge supplied overrides with the file based config" do
213
- write_config(@config_path, {"default_log_level" => "debug"})
207
+ it 'merges supplied overrides with the file based config' do
208
+ write_config(@config_path, { 'default_log_level' => 'debug' })
214
209
 
215
210
  context = Steno::Context::ThreadLocal.new
216
211
  config = Steno::Config.from_file(@config_path,
217
- :default_log_level => "warn",
218
- :context => context)
212
+ default_log_level: 'warn',
213
+ context: context)
219
214
  expect(config.context).to eq(context)
220
215
  expect(config.default_log_level).to eq(:warn)
221
216
  end
222
217
  end
223
218
 
224
219
  def write_config(path, config)
225
- File.open(path, "w+") do |f|
226
- f.write(YAML.dump({"logging" => config}))
227
- end
220
+ File.write(path, YAML.dump({ 'logging' => config }))
228
221
  end
229
222
  end
@@ -1,37 +1,37 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe Steno::Context::Null do
4
- include_context :steno_context
4
+ include_context 'steno context'
5
5
 
6
6
  let(:context) { Steno::Context::Null.new }
7
7
 
8
- it "should store no data" do
8
+ it 'stores no data' do
9
9
  expect(context.data).to eq({})
10
- context.data["foo"] = "bar"
10
+ context.data['foo'] = 'bar'
11
11
  expect(context.data).to eq({})
12
12
  end
13
13
  end
14
14
 
15
15
  describe Steno::Context::ThreadLocal do
16
- include_context :steno_context
16
+ include_context 'steno context'
17
17
 
18
- let (:context) { Steno::Context::ThreadLocal.new }
18
+ let(:context) { Steno::Context::ThreadLocal.new }
19
19
 
20
- it "should store data local to threads" do
20
+ it 'stores data local to threads' do
21
21
  b1 = Barrier.new
22
22
  b2 = Barrier.new
23
23
 
24
24
  t1 = Thread.new do
25
- context.data["thread"] = "t1"
25
+ context.data['thread'] = 't1'
26
26
  b1.release
27
27
  b2.wait
28
- expect(context.data["thread"]).to eq("t1")
28
+ expect(context.data['thread']).to eq('t1')
29
29
  end
30
30
 
31
31
  t2 = Thread.new do
32
32
  b1.wait
33
- expect(context.data["thread"]).to be_nil
34
- context.data["thread"] = "t2"
33
+ expect(context.data['thread']).to be_nil
34
+ context.data['thread'] = 't2'
35
35
  b2.release
36
36
  end
37
37
 
@@ -41,20 +41,20 @@ describe Steno::Context::ThreadLocal do
41
41
  end
42
42
 
43
43
  describe Steno::Context::FiberLocal do
44
- include_context :steno_context
44
+ include_context 'steno context'
45
45
 
46
46
  let(:context) { Steno::Context::FiberLocal.new }
47
47
 
48
- it "should store data local to fibers" do
48
+ it 'stores data local to fibers' do
49
49
  f2 = Fiber.new do
50
- expect(context.data["fiber"]).to be_nil
51
- context.data["fiber"] = "f2"
50
+ expect(context.data['fiber']).to be_nil
51
+ context.data['fiber'] = 'f2'
52
52
  end
53
53
 
54
54
  f1 = Fiber.new do
55
- context.data["fiber"] = "f1"
55
+ context.data['fiber'] = 'f1'
56
56
  f2.resume
57
- expect(context.data["fiber"]).to eq("f1")
57
+ expect(context.data['fiber']).to eq('f1')
58
58
  end
59
59
 
60
60
  f1.resume
@@ -1,6 +1,6 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
- require "steno/core_ext"
3
+ require 'steno/core_ext'
4
4
 
5
5
  module Foo
6
6
  class Bar
@@ -8,31 +8,31 @@ module Foo
8
8
  end
9
9
 
10
10
  describe Module do
11
- describe "#logger" do
12
- it "should request a logger named after itself" do
11
+ describe '#logger' do
12
+ it 'requests a logger named after itself' do
13
13
  x = Foo.logger
14
14
  expect(x).to be_a(Steno::Logger)
15
- expect(x.name).to include("Foo")
15
+ expect(x.name).to include('Foo')
16
16
  end
17
17
  end
18
18
  end
19
19
 
20
20
  describe Class do
21
- describe "#logger" do
22
- it "should request a logger named after itself" do
21
+ describe '#logger' do
22
+ it 'requests a logger named after itself' do
23
23
  x = Foo::Bar.logger
24
24
  expect(x).to be_a(Steno::Logger)
25
- expect(x.name).to include("Foo::Bar")
25
+ expect(x.name).to include('Foo::Bar')
26
26
  end
27
27
  end
28
28
  end
29
29
 
30
30
  describe Object do
31
- describe "#logger" do
32
- it "should request a logger named after its class" do
31
+ describe '#logger' do
32
+ it 'requests a logger named after its class' do
33
33
  x = Foo::Bar.new.logger
34
34
  expect(x).to be_a(Steno::Logger)
35
- expect(x.name).to include("Foo::Bar")
35
+ expect(x.name).to include('Foo::Bar')
36
36
  end
37
37
  end
38
38
  end
@@ -1,68 +1,68 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe Steno::Codec::Json do
4
4
  let(:codec) { Steno::Codec::Json.new }
5
- let(:record) { make_record(:data => { "user" => "data" }) }
5
+ let(:record) { make_record(data: { 'user' => 'data' }) }
6
6
 
7
- describe "#encode_record" do
8
- it "should encode records as json hashes" do
7
+ describe '#encode_record' do
8
+ it 'encodes records as json hashes' do
9
9
  parsed = Yajl::Parser.parse(codec.encode_record(record))
10
10
  expect(parsed.class).to eq(Hash)
11
11
  end
12
12
 
13
- it "should encode the timestamp as a float" do
13
+ it 'encodes the timestamp as a float' do
14
14
  parsed = Yajl::Parser.parse(codec.encode_record(record))
15
- expect(parsed["timestamp"].class).to eq(Float)
15
+ expect(parsed['timestamp'].class).to eq(Float)
16
16
  end
17
17
 
18
- it "should escape newlines" do
19
- rec = make_record(:message => "newline\ntest")
18
+ it 'escapes newlines' do
19
+ rec = make_record(message: "newline\ntest")
20
20
  expect(codec.encode_record(rec)).to match(/newline\\ntest/)
21
21
  end
22
22
 
23
- it "should escape carriage returns" do
24
- rec = make_record(:message => "newline\rtest")
23
+ it 'escapes carriage returns' do
24
+ rec = make_record(message: "newline\rtest")
25
25
  expect(codec.encode_record(rec)).to match(/newline\\rtest/)
26
26
  end
27
27
 
28
- it "should allow messages with valid encodings to pass through untouched" do
28
+ it 'allows messages with valid encodings to pass through untouched' do
29
29
  msg = "HI\u2600"
30
- rec = make_record(:message => msg)
30
+ rec = make_record(message: msg)
31
31
  expect(codec.encode_record(rec)).to match(/#{msg}/)
32
32
  end
33
33
 
34
- it "should treat messages with invalid encodings as binary data" do
35
- msg = "HI\u2026".force_encoding("US-ASCII")
36
- rec = make_record(:message => msg)
34
+ it 'treats messages with invalid encodings as binary data' do
35
+ msg = "HI\u2026".force_encoding('US-ASCII')
36
+ rec = make_record(message: msg)
37
37
  expect(codec.encode_record(rec)).to match(/HI\\\\xe2\\\\x80\\\\xa6/)
38
38
  end
39
39
 
40
- it "shouldn't use readable dates by default" do
40
+ it 'does not use readable dates by default' do
41
41
  expect(codec.iso8601_timestamps?).to eq(false)
42
42
  end
43
43
 
44
- context "when iso8601_timestamps is set" do
45
- let(:codec) { Steno::Codec::Json.new( :iso8601_timestamps => true ) }
44
+ context 'when iso8601_timestamps is set' do
45
+ let(:codec) { Steno::Codec::Json.new(iso8601_timestamps: true) }
46
46
 
47
- it "should encode timestamps as UTC-formatted strings" do
48
- allow(record).to receive(:timestamp).and_return 1396473763.811278 # 2014-04-02 22:22:43 +01:00
47
+ it 'encodes timestamps as UTC-formatted strings' do
48
+ allow(record).to receive(:timestamp).and_return 1_396_473_763.811278 # 2014-04-02 22:22:43 +01:00
49
49
  parsed = Yajl::Parser.parse(codec.encode_record(record))
50
50
 
51
- expect(parsed["timestamp"].class).to eq(String)
52
- expect(parsed["timestamp"]).to eq("2014-04-02T21:22:43.811278Z")
51
+ expect(parsed['timestamp'].class).to eq(String)
52
+ expect(parsed['timestamp']).to eq('2014-04-02T21:22:43.811278Z')
53
53
  end
54
54
 
55
- it "should surface the property in a getter" do
55
+ it 'surfaces the property in a getter' do
56
56
  expect(codec.iso8601_timestamps?).to eq(true)
57
57
  end
58
58
  end
59
59
  end
60
60
 
61
61
  def make_record(opts = {})
62
- Steno::Record.new(opts[:source] || "my_source",
62
+ Steno::Record.new(opts[:source] || 'my_source',
63
63
  opts[:level] || :debug,
64
- opts[:message] || "test message",
64
+ opts[:message] || 'test message',
65
65
  nil,
66
- opts[:data] || {})
66
+ opts[:data] || {})
67
67
  end
68
68
  end
@@ -1,15 +1,15 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
- require "steno/json_prettifier"
3
+ require 'steno/json_prettifier'
4
4
 
5
5
  describe Steno::JsonPrettifier do
6
6
  let(:prettifier) { Steno::JsonPrettifier.new }
7
7
  let(:codec) { Steno::Codec::Json.new }
8
8
 
9
- describe "#prettify_line" do
10
- it "should return a properly formatted string" do
11
- record = Steno::Record.new("test", :info, "message",
12
- ["filename", "line", "method"], "test" => "data")
9
+ describe '#prettify_line' do
10
+ it 'returns a properly formatted string' do
11
+ record = Steno::Record.new('test', :info, 'message',
12
+ %w[filename line method], 'test' => 'data')
13
13
  encoded = codec.encode_record(record)
14
14
  prettified = prettifier.prettify_line(encoded)
15
15
 
@@ -23,16 +23,16 @@ describe Steno::JsonPrettifier do
23
23
  'test=data', # User supplied data
24
24
  'INFO', # Level
25
25
  '--',
26
- 'message', # Log message
26
+ 'message' # Log message
27
27
  ].join("\s+") + "\n"
28
28
  expect(prettified).to match(exp_regex)
29
29
  end
30
30
 
31
- it "should always use the largest src len to determine src column width" do
31
+ it 'alwayses use the largest src len to determine src column width' do
32
32
  test_srcs = [
33
33
  'a' * (Steno::JsonPrettifier::MIN_COL_WIDTH - 3),
34
34
  'a' * (Steno::JsonPrettifier::MIN_COL_WIDTH - 1),
35
- 'a' * (Steno::JsonPrettifier::MIN_COL_WIDTH),
35
+ 'a' * Steno::JsonPrettifier::MIN_COL_WIDTH,
36
36
  'a' * (Steno::JsonPrettifier::MIN_COL_WIDTH + 1),
37
37
  'a' * (Steno::JsonPrettifier::MIN_COL_WIDTH - 3),
38
38
  'a' * (Steno::JsonPrettifier::MIN_COL_WIDTH + 3),
@@ -51,9 +51,9 @@ describe Steno::JsonPrettifier do
51
51
  test_srcs.each do |src|
52
52
  record = Steno::Record.new(src,
53
53
  :info,
54
- "message",
55
- ["filename", "line", "method"],
56
- "test" => "data")
54
+ 'message',
55
+ %w[filename line method],
56
+ 'test' => 'data')
57
57
 
58
58
  encoded = codec.encode_record(record)
59
59
  prettified = prettifier.prettify_line(encoded)
@@ -64,21 +64,21 @@ describe Steno::JsonPrettifier do
64
64
  end
65
65
  end
66
66
 
67
- it "should raise a parse error when the json-encoded string is not a hash" do
68
- expect {
69
- prettifier.prettify_line("[1,2,3]")
70
- }.to raise_error(Steno::JsonPrettifier::ParseError)
67
+ it 'raises a parse error when the json-encoded string is not a hash' do
68
+ expect do
69
+ prettifier.prettify_line('[1,2,3]')
70
+ end.to raise_error(Steno::JsonPrettifier::ParseError)
71
71
  end
72
72
 
73
- it "should raise a parse error when the json-encoded string is malformed" do
74
- expect {
75
- prettifier.prettify_line("blah")
76
- }.to raise_error(Steno::JsonPrettifier::ParseError)
73
+ it 'raises a parse error when the json-encoded string is malformed' do
74
+ expect do
75
+ prettifier.prettify_line('blah')
76
+ end.to raise_error(Steno::JsonPrettifier::ParseError)
77
77
  end
78
78
 
79
- it "should work with a nil data field" do
79
+ it 'works with a nil data field' do
80
80
  line = prettifier.prettify_line('{"data":null}')
81
- expect(line).to include(" - ")
81
+ expect(line).to include(' - ')
82
82
  end
83
83
  end
84
84
  end
@@ -1,19 +1,18 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe Steno::LogLevel do
4
4
  let(:info_level) { Steno::LogLevel.new(:info, 2) }
5
5
  let(:debug_level) { Steno::LogLevel.new(:debug, 1) }
6
6
 
7
- it "should be comparable" do
7
+ it 'is comparable' do
8
8
  expect(info_level > debug_level).to be_truthy
9
9
  expect(debug_level > info_level).to be_falsey
10
10
  expect(info_level == info_level).to be_truthy
11
11
  end
12
12
 
13
- describe "#to_s" do
14
- it "should return the name of the level" do
15
- expect(info_level.to_s).to eq("info")
13
+ describe '#to_s' do
14
+ it 'returns the name of the level' do
15
+ expect(info_level.to_s).to eq('info')
16
16
  end
17
17
  end
18
-
19
18
  end