ci_logger 0.5.1 → 0.7.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: d378e44c124952aecefaada042e51ca49bde9f126970a7ed5b8e04a9f4523a4f
4
- data.tar.gz: cb5d471262303a7b6075979c5c4d411424fa1783742e1a2c67aea4630ed5166e
3
+ metadata.gz: 51c9f02d787a2ea528d373395735b2a3f442c410b371b3a678cff837245056e2
4
+ data.tar.gz: b64fc8ea5f7f8590cf102b6ceb24bf47b113014061b526753ed12a22c8eec166
5
5
  SHA512:
6
- metadata.gz: 40f1589c2767df171705caa124a03afe67b793e043f9ec94a2d4dc0552029bdca4c5cbca2dafe1b9182b6b6d00afec6821a9dea1b4024c6585c04ee1a560b9da
7
- data.tar.gz: fbe15cfa23c67256a4b8a71fb2871b7da2dc0b236d913537d2ae49a70a4b4e2738ec0eff000013c2b921d24894e28f240018986ef02ba20b007c8dab1bfd07f3
6
+ metadata.gz: acfa40bed44dc82d44e311cf5a8124c32545176d8361e57e3fa82ae0b6a3bcc20bb3a201a4a6b84338eb6e4fc27d447e8ca8efaad14fe23343cbe24b5e08cbe8
7
+ data.tar.gz: 0eb2d0c042f3e926ee34368e9681200f676f30f54860bad8ff636b44c952e3cd94ec86084bbf77966d3ec529e815cb3995eebb71070b6dd10fb7836866f3a6bf
data/README.md CHANGED
@@ -6,11 +6,9 @@ CiLogger specifically generates logs for failed tests, which proves invaluable d
6
6
 
7
7
  ## prerequisite
8
8
 
9
- - rspec
9
+ - rspec or minitest
10
10
  - rails(>= 6.0)
11
11
 
12
- If you want minitest integration, send Pull Request!
13
-
14
12
  ## Installation
15
13
 
16
14
  Add this line to your application's Gemfile:
@@ -37,6 +35,15 @@ config.ci_logger.enabled = ENV['CI']
37
35
 
38
36
  You can replace `ENV['CI']` with what you like.
39
37
 
38
+ ## Replace loggers besides rails logger
39
+
40
+ CiLogger replaces Rails.logger by default, but other loggers can be replaced.
41
+
42
+ ```ruby
43
+ your_logger = CiLogger.new(your_logger)
44
+ your_logger.debug('debug!') # This is only output when the test fails
45
+ ```
46
+
40
47
  ## Contributing
41
48
  Contribution directions go here.
42
49
 
@@ -1,3 +1,5 @@
1
+ require "ci_logger/registry"
2
+
1
3
  module CiLogger
2
4
  class Logger < ::Logger
3
5
  def initialize(original)
@@ -5,6 +7,7 @@ module CiLogger
5
7
  @original_level = @original.level
6
8
  @original.level = :debug
7
9
  self.level = :debug
10
+ Registry.register(self)
8
11
  end
9
12
 
10
13
  def sync
@@ -0,0 +1,19 @@
1
+ module CiLogger
2
+ module Minitest
3
+ module Integration
4
+ def before_teardown
5
+ super
6
+ if CiLogger.disabled?
7
+ Registry.sync
8
+ elsif passed? || skipped?
9
+ Registry.clear
10
+ else
11
+ Registry.sync
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ class ActiveSupport::TestCase
18
+ include CiLogger::Minitest::Integration
19
+ end
@@ -4,30 +4,20 @@ module CiLogger
4
4
  config.ci_logger.enabled = false
5
5
 
6
6
  config.before_initialize do
7
- if Rails.application.config.ci_logger.enabled
7
+ if CiLogger.enabled?
8
8
  Rails.logger = CiLogger::Logger.new(Rails.logger)
9
- require "rspec/core"
10
- require "ci_logger/example_group_methods"
11
-
12
- RSpec.configure do |config|
13
- config.include CiLogger::ExampleGroupMethods
14
-
15
- config.prepend_before do |example|
16
- next unless Rails.application.config.ci_logger.enabled
17
-
18
- Rails.logger.debug("start example at #{example.location}")
19
- end
9
+ begin
10
+ require "rspec/core"
11
+ require "ci_logger/rspec/integration"
12
+ rescue LoadError
13
+ # do nothing
14
+ end
20
15
 
21
- config.append_after do |example|
22
- if !Rails.application.config.ci_logger.enabled
23
- Rails.logger.sync
24
- elsif passed?
25
- Rails.logger.clear
26
- else
27
- Rails.logger.debug("finish example at #{example.location}")
28
- Rails.logger.sync
29
- end
30
- end
16
+ begin
17
+ require "active_support/test_case"
18
+ require "ci_logger/minitest/integration"
19
+ rescue LoadError
20
+ # do nothing
31
21
  end
32
22
  end
33
23
  end
@@ -0,0 +1,22 @@
1
+ module CiLogger
2
+ module Registry
3
+ class << self
4
+ def register(logger)
5
+ @loggers ||= []
6
+ @loggers << logger
7
+ end
8
+
9
+ def sync
10
+ @loggers.each(&:sync)
11
+ end
12
+
13
+ def clear
14
+ @loggers.each(&:clear)
15
+ end
16
+
17
+ def debug(...)
18
+ @loggers.each { _1.debug(...) }
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,16 @@
1
+ module CiLogger
2
+ module Rspec
3
+ module ExampleGroupMethods
4
+ # original from https://github.com/rspec/rspec-rails/blob/229f5f7ca9c0de0c7bca452450416d988f7cf612/lib/rspec/rails/example/system_example_group.rb#L28-L37
5
+ def passed?
6
+ return false if RSpec.current_example.exception
7
+ return true unless defined?(::RSpec::Expectations::FailureAggregator)
8
+
9
+ failure_notifier = ::RSpec::Support.failure_notifier
10
+ return true unless failure_notifier.is_a?(::RSpec::Expectations::FailureAggregator)
11
+
12
+ failure_notifier.failures.empty? && failure_notifier.other_errors.empty?
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,22 @@
1
+ require "ci_logger/rspec/example_group_methods"
2
+
3
+ RSpec.configure do |config|
4
+ config.include CiLogger::Rspec::ExampleGroupMethods
5
+
6
+ config.prepend_before do |example|
7
+ next if CiLogger.disabled?
8
+
9
+ CiLogger::Registry.debug("start example at #{example.location}")
10
+ end
11
+
12
+ config.append_after do |example|
13
+ if CiLogger.disabled?
14
+ CiLogger::Registry.sync
15
+ elsif passed?
16
+ CiLogger::Registry.clear
17
+ else
18
+ CiLogger::Registry.debug("finish example at #{example.location}")
19
+ CiLogger::Registry.sync
20
+ end
21
+ end
22
+ end
@@ -1,3 +1,3 @@
1
1
  module CiLogger
2
- VERSION = '0.5.1'
2
+ VERSION = '0.7.0'
3
3
  end
data/lib/ci_logger.rb CHANGED
@@ -3,4 +3,17 @@ require "ci_logger/railtie"
3
3
  require "ci_logger/logger"
4
4
 
5
5
  module CiLogger
6
+ class << self
7
+ def new(original)
8
+ Logger.new(original)
9
+ end
10
+
11
+ def enabled?
12
+ Rails.application.config.ci_logger.enabled
13
+ end
14
+
15
+ def disabled?
16
+ !enabled?
17
+ end
18
+ end
6
19
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ci_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - willnet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-09 00:00:00.000000000 Z
11
+ date: 2023-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 6.0.0
27
- - !ruby/object:Gem::Dependency
28
- name: rspec-core
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rspec-rails
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -63,9 +49,12 @@ files:
63
49
  - README.md
64
50
  - Rakefile
65
51
  - lib/ci_logger.rb
66
- - lib/ci_logger/example_group_methods.rb
67
52
  - lib/ci_logger/logger.rb
53
+ - lib/ci_logger/minitest/integration.rb
68
54
  - lib/ci_logger/railtie.rb
55
+ - lib/ci_logger/registry.rb
56
+ - lib/ci_logger/rspec/example_group_methods.rb
57
+ - lib/ci_logger/rspec/integration.rb
69
58
  - lib/ci_logger/version.rb
70
59
  - lib/tasks/ci_logger_tasks.rake
71
60
  homepage: https://github.com/willnet/ci_logger
@@ -90,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
79
  - !ruby/object:Gem::Version
91
80
  version: '0'
92
81
  requirements: []
93
- rubygems_version: 3.3.3
82
+ rubygems_version: 3.4.17
94
83
  signing_key:
95
84
  specification_version: 4
96
85
  summary: Faster logger for CI
@@ -1,14 +0,0 @@
1
- module CiLogger
2
- module ExampleGroupMethods
3
- # original from https://github.com/rspec/rspec-rails/blob/229f5f7ca9c0de0c7bca452450416d988f7cf612/lib/rspec/rails/example/system_example_group.rb#L28-L37
4
- def passed?
5
- return false if RSpec.current_example.exception
6
- return true unless defined?(::RSpec::Expectations::FailureAggregator)
7
-
8
- failure_notifier = ::RSpec::Support.failure_notifier
9
- return true unless failure_notifier.is_a?(::RSpec::Expectations::FailureAggregator)
10
-
11
- failure_notifier.failures.empty? && failure_notifier.other_errors.empty?
12
- end
13
- end
14
- end