ci_logger 0.1.3 → 0.2.0

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
  SHA256:
3
- metadata.gz: 2ed98779d07fdac9af3859e89ca4a2785b6a1df26270efad3ead2bfd473086db
4
- data.tar.gz: c27d8ba865ba4f56a6f6e13f541a86397b025ebaecca3c4207a376ca1a356db6
3
+ metadata.gz: 11629fb2dce2cdff3c3e940151e40efd927ac0b780981a644a03b493cee90131
4
+ data.tar.gz: 277aab9b4b91ac63c8be5d2fc18cf7cc0ef6cd906f2d89e30dc8a6d721f504a2
5
5
  SHA512:
6
- metadata.gz: 5175af5e43ed981ae562b29c9419b8540a5c1fed6ed0135427e837cd9edb2f5d2a1564cde2beb94f76f58b4881f951aace952ccff50b285ab7b85491eec212c1
7
- data.tar.gz: 709748c62dfa5ff7bd848b908a188346c476432befe487a3b4087e1d50fee4b070744a8cd6c5ea608fb79da24ee8575d3647b0123a65acecd5badba65be41b57
6
+ metadata.gz: 03b4a46f290717e27a7c9a69141a5b31c96702983a19262a16e88224e7672167b900858f423f65fbce9f07ac00bce8791eca73f2299f0a234b24cc6542c86fec
7
+ data.tar.gz: 5a0a4624f2541e88ba8ba2b65f105f9288d700c0eb03c3b089437df64269c8975d5cf469a77ffc0af0915f7d8df7c8cbb76dd351b837d9ebd2c9565a47af1c29
@@ -0,0 +1,37 @@
1
+ require "rspec/core"
2
+
3
+ module CiLogger
4
+ class Formatter
5
+ RSpec::Core::Formatters.register self, :example_passed, :example_pending, :example_failed
6
+
7
+ def initialize(_out)
8
+ @out = _out
9
+ end
10
+
11
+ def example_failed(notification)
12
+ if Rails.application.config.ci_logger.enabled
13
+ example = notification.example
14
+ Rails.logger.debug("finish example at #{example.location}")
15
+ Rails.logger.sync
16
+ else
17
+ Rails.logger.sync_with_original_level
18
+ end
19
+ end
20
+
21
+ def example_passed(_notification)
22
+ if Rails.application.config.ci_logger.enabled
23
+ Rails.logger.clear
24
+ else
25
+ Rails.logger.sync_with_original_level
26
+ end
27
+ end
28
+
29
+ def example_pending(_notification)
30
+ if Rails.application.config.ci_logger.enabled
31
+ Rails.logger.clear
32
+ else
33
+ Rails.logger.sync_with_original_level
34
+ end
35
+ end
36
+ end
37
+ end
@@ -2,14 +2,33 @@ module CiLogger
2
2
  class Logger < ::Logger
3
3
  def initialize(original)
4
4
  @original = original
5
+ @original_level = @original.level
5
6
  @original.level = :debug
6
7
  self.level = :debug
7
8
  end
8
9
 
10
+ def sync
11
+ temporary_log.each do |l|
12
+ if @level <= l[:severity]
13
+ @original.add(l[:severity], l[:message], l[:progname])
14
+ end
15
+ end
16
+ temporary_log.clear
17
+ end
18
+
19
+ def sync_with_original_level
20
+ @original.level = @original_level
21
+ sync
22
+ ensure
23
+ @original.level = :debug
24
+ end
25
+
9
26
  def clear
10
27
  temporary_log.clear
11
28
  end
12
29
 
30
+ private
31
+
13
32
  def temporary_log
14
33
  @temporary_log ||= []
15
34
  end
@@ -18,15 +37,6 @@ module CiLogger
18
37
  temporary_log << { severity: severity, message: message, progname: progname }
19
38
  end
20
39
 
21
- def sync
22
- temporary_log.each do |l|
23
- if @level <= l[:severity]
24
- @original.add(l[:severity], l[:message], l[:progname])
25
- end
26
- end
27
- temporary_log.clear
28
- end
29
-
30
40
  def method_missing(symbol, *args, &block)
31
41
  @original.send(symbol, *args, &block)
32
42
  end
@@ -1,3 +1,3 @@
1
1
  module CiLogger
2
- VERSION = '0.1.3'
2
+ VERSION = '0.2.0'
3
3
  end
data/lib/ci_logger.rb CHANGED
@@ -1,33 +1,7 @@
1
1
  require "ci_logger/version"
2
2
  require "ci_logger/railtie"
3
3
  require "ci_logger/logger"
4
+ require "ci_logger/formatter"
4
5
 
5
6
  module CiLogger
6
- require "rspec/core"
7
-
8
- class Formatter
9
- RSpec::Core::Formatters.register self, :example_passed, :example_pending, :example_failed
10
-
11
- def initialize(_out)
12
- @out = _out
13
- end
14
-
15
- def example_failed(notification)
16
- if Rails.application.config.ci_logger.enabled
17
- example = notification.example
18
- Rails.logger.debug("finish example at #{example.location}")
19
- Rails.logger.sync
20
- else
21
- Rails.logger.clear
22
- end
23
- end
24
-
25
- def example_passed(_notification)
26
- Rails.logger.clear
27
- end
28
-
29
- def example_pending(_notification)
30
- Rails.logger.clear
31
- end
32
- end
33
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ci_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - willnet
@@ -63,6 +63,7 @@ files:
63
63
  - README.md
64
64
  - Rakefile
65
65
  - lib/ci_logger.rb
66
+ - lib/ci_logger/formatter.rb
66
67
  - lib/ci_logger/logger.rb
67
68
  - lib/ci_logger/railtie.rb
68
69
  - lib/ci_logger/version.rb