slack_log_device 2.1.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f7c2fbccccb4df5730e6f9ea792d23df250aeaae
4
- data.tar.gz: 03700bccd9ef1366dfe3035d8ba31db4aa87002b
3
+ metadata.gz: e489a5ee3f73f7e9e12d6ec7b7c0fd0c4013b768
4
+ data.tar.gz: e209bf2e8df911376b3b0624dfeb75986b25970e
5
5
  SHA512:
6
- metadata.gz: 951dc372a3de3848fa203ad903e4bb5c2efde689a28f52249730cadd8555b0137365b845f1fd089f6860857e9faeb957702f110d8e7ca6bdcc105e73423b9993
7
- data.tar.gz: 9735f2db5fd0ea7332023c9c8211d7974d07fc6365fc15e01bf87d66782dfc232c041792850ceb991b093ff9d08ae223c1c68ad444e3687fbc63307be777a99a
6
+ metadata.gz: f3ca47f4d8f1d983e0750e4314d7e9cfcf4930fce71d93edaa6c0f5bd5535ad2eacc0eed2476cb3536a1dc00dc902ee720bfa63801e44b8e7783e913634379db
7
+ data.tar.gz: d24fce09e62726004440dca80ff5dd6ce9be076a0118864f1e813c5f89f337ce8628ffeb6cea0d6fec45e14d0999169987814ce3a621ed97ca06a88881c69906
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.1.0
1
+ 2.1.1
@@ -40,6 +40,7 @@ class SlackLogDevice
40
40
  end
41
41
 
42
42
  def flush
43
+ kill_flush_thread
43
44
  return if @buffer.empty?
44
45
  message = ''
45
46
  @mutex.synchronize do
@@ -96,7 +97,7 @@ class SlackLogDevice
96
97
  @mutex.synchronize do
97
98
  @buffer << message
98
99
  end
99
- @flush_thread.kill if @flush_thread
100
+ kill_flush_thread
100
101
  @flush_thread = Thread.new do
101
102
  sleep(flush_delay) unless auto_flush?
102
103
  flush
@@ -104,4 +105,13 @@ class SlackLogDevice
104
105
  nil
105
106
  end
106
107
 
108
+ private
109
+
110
+ def kill_flush_thread
111
+ if @flush_thread
112
+ @flush_thread.kill
113
+ @flush_thread = nil
114
+ end
115
+ end
116
+
107
117
  end
@@ -3,13 +3,16 @@ require 'spec_helper'
3
3
  describe SlackLogDevice do
4
4
 
5
5
  let(:device) { SlackLogDevice.new(options) }
6
- let(:logger) { Logger.new(device).tap { |logger| logger.level = Logger::INFO } }
7
6
  let(:options) { { username: 'MyApp', webhook_url: 'https://hooks.slack.com/services/test' } }
8
7
 
9
8
  before :each do
10
9
  allow(HTTParty).to receive(:post)
11
10
  end
12
11
 
12
+ it 'is not a LogDevice instance' do
13
+ expect(device).not_to be_a(Logger::LogDevice)
14
+ end
15
+
13
16
  describe '#auto_flush?' do
14
17
 
15
18
  it 'is false by default' do
@@ -134,6 +137,16 @@ describe SlackLogDevice do
134
137
  expect(device.flush).to be_nil
135
138
  end
136
139
 
140
+ it 'clears buffer' do
141
+ device.write('BAM!')
142
+ device.write('BIM!')
143
+ expect {
144
+ device.flush
145
+ }.to change { device.instance_variable_get(:@buffer) }.to([])
146
+ expect(HTTParty).not_to receive(:post)
147
+ device.flush
148
+ end
149
+
137
150
  end
138
151
 
139
152
  describe '#flush?' do
@@ -419,12 +432,6 @@ describe SlackLogDevice do
419
432
  expect(device.write('BAM!')).to be_nil
420
433
  end
421
434
 
422
- it 'does nothing if log level is lower than specified one' do
423
- expect(HTTParty).not_to receive(:post)
424
- logger.debug('BIM!')
425
- device.flush
426
- end
427
-
428
435
  it 'strips message' do
429
436
  device.write(" BAM !\n")
430
437
  expect(device.instance_variable_get(:@buffer)).to eq(['BAM !'])
@@ -448,6 +455,23 @@ describe SlackLogDevice do
448
455
  expect(device.instance_variable_get(:@buffer)).to eq([])
449
456
  end
450
457
 
458
+ it 'does not post HTTP message if auto flush is false' do
459
+ expect(HTTParty).not_to receive(:post)
460
+ device.write('BAM!')
461
+ end
462
+
463
+ end
464
+
465
+ describe Logger, 'with slack log device' do
466
+
467
+ let(:logger) { Logger.new(device).tap { |logger| logger.level = Logger::INFO } }
468
+
469
+ it 'does nothing if log level is lower than specified one' do
470
+ expect(HTTParty).not_to receive(:post)
471
+ logger.debug('BIM!')
472
+ device.flush
473
+ end
474
+
451
475
  it 'send HTTP request if log level is equal to specified one' do
452
476
  expect(HTTParty).to receive(:post)
453
477
  logger.info('BIM!')
@@ -460,9 +484,42 @@ describe SlackLogDevice do
460
484
  device.flush
461
485
  end
462
486
 
463
- it 'does not post HTTP message if auto flush is false' do
464
- expect(HTTParty).not_to receive(:post)
465
- device.write('BAM!')
487
+ describe '#close' do
488
+
489
+ it 'does not raise any error' do
490
+ expect {
491
+ logger.close
492
+ }.not_to raise_error
493
+ end
494
+
495
+ end
496
+
497
+ describe '#reopen' do
498
+
499
+ it 'does not raise any error' do
500
+ expect {
501
+ logger.reopen
502
+ }.not_to raise_error
503
+ end
504
+
505
+ end
506
+
507
+ describe '@logdev' do
508
+
509
+ let(:logdev) { logger.instance_variable_get(:@logdev) }
510
+
511
+ it 'is a LogDevice instance' do
512
+ expect(logdev).to be_a(Logger::LogDevice)
513
+ end
514
+
515
+ describe '#filename' do
516
+
517
+ it 'is nil' do
518
+ expect(logdev.filename).to be_nil
519
+ end
520
+
521
+ end
522
+
466
523
  end
467
524
 
468
525
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slack_log_device
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexis Toulotte
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-18 00:00:00.000000000 Z
11
+ date: 2017-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport