test-prof 1.0.9 → 1.0.10

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: 9680aa33c1d917182a0be6e8cfd0656149d510b634db637b8023feda29f10886
4
- data.tar.gz: 721767f61684ed87eff0f2e4c62080b9bb2a9e24bf6f47db194fc687bedbbe9b
3
+ metadata.gz: 9d847a0016b2749e8ba8a637d2db3d0044f7b77cfc5962596ff490aea0f5fc7d
4
+ data.tar.gz: 1f32af0e6e09b555bf258c5a52586a9d4a768578b0c816298343dfd5deb826da
5
5
  SHA512:
6
- metadata.gz: 5a1d037cdac034f7c58f7bd090de128a81d41c3927787c953cacd33e8ecec1dd11cbda282f64fd542c2679b5176aa7bce4fe2ecb49806abac895d2cf9f478c00
7
- data.tar.gz: baf837db1165a0d5631f07c9f4a978234afcce65fd9be886ef80bcf0a020fd43926e57eb5f295f0daddb22027c821ee72960fb01cd2cd4c7db6d18100d404343
6
+ metadata.gz: 55db394aef01457404c8f5cd914cfa0eb359f3bea08874c6d4a6b75b1151af5b4153087815c90ed73ea5948c403941918b75af0b79558afe795db77c4d2b2568
7
+ data.tar.gz: d95cfbd7c513d086cd47b2ce0a804ec52fdf174854c0a07c239289c65d97d18833529321e0ffb4853aabc802f05a8a8eac4e3fcdc7011f0ffd1bf0c60d150b41
data/CHANGELOG.md CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  ## master (unreleased)
4
4
 
5
+ ## 1.0.10 (2022-08-12)
6
+
7
+ - Allow overriding global logger. ([@palkan][])
8
+
9
+ ```ruby
10
+ require "test_prof/recipes/logging"
11
+
12
+ TestProf::Rails::LoggingHelpers.logger = CustomLogger.new
13
+ ```
14
+
5
15
  ## 1.0.9 (2022-05-05)
6
16
 
7
17
  - Add `AnyFixture.before_fixtures_reset` and `AnyFixture.after_fixtures_reset` callbacks. ([@ruslanshakirov][])
@@ -74,8 +74,8 @@ module Minitest
74
74
  @example_groups.each do |group, examples|
75
75
  msgs << "#{group[:description]} (#{group[:location]})\n"
76
76
  examples.each do |ex|
77
- msgs << " #{ex[:description]} (#{ex[:location]}) "\
78
- "– #{pluralize_records(ex[:factories])} created, "\
77
+ msgs << " #{ex[:description]} (#{ex[:location]}) " \
78
+ "– #{pluralize_records(ex[:factories])} created, " \
79
79
  "#{ex[:time].duration}\n"
80
80
  end
81
81
  msgs << "\n"
@@ -67,7 +67,7 @@ module TestProf
67
67
 
68
68
  examples.each do |ex|
69
69
  msgs << " #{ex.description} (#{ex.metadata[:location]}) " \
70
- "– #{pluralize_records(ex.metadata[:factories])} created, "\
70
+ "– #{pluralize_records(ex.metadata[:factories])} created, " \
71
71
  "#{ex.metadata[:time].duration}\n"
72
72
  end
73
73
  msgs << "\n"
@@ -11,7 +11,7 @@ module TestProf
11
11
 
12
12
  class Formatter
13
13
  def call(severity, _time, progname, msg)
14
- colorize(severity.to_sym, "[#{progname} #{severity}] #{msg}\n")
14
+ colorize(severity.to_sym, "[#{progname} #{severity}] #{msg}") + "\n"
15
15
  end
16
16
 
17
17
  private
@@ -7,12 +7,38 @@ module TestProf
7
7
  # Add `with_logging` and `with_ar_logging helpers`
8
8
  module LoggingHelpers
9
9
  class << self
10
- attr_writer :logger
10
+ def logger=(logger)
11
+ @logger = logger
12
+
13
+ # swap global loggers
14
+ global_loggables.each do |loggable|
15
+ loggable.logger = logger
16
+ end
17
+ end
11
18
 
12
19
  def logger
13
20
  return @logger if instance_variable_defined?(:@logger)
14
21
 
15
- @logger = Logger.new($stdout)
22
+ @logger = if defined?(ActiveSupport::TaggedLogging)
23
+ ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new($stdout))
24
+ elsif defined?(ActiveSupport::Logger)
25
+ ActiveSupport::Logger.new($stdout)
26
+ else
27
+ Logger.new($stdout)
28
+ end
29
+ end
30
+
31
+ def global_loggables
32
+ return @global_loggables if instance_variable_defined?(:@global_loggables)
33
+
34
+ @global_loggables = []
35
+ end
36
+
37
+ def swap_logger!(loggables)
38
+ loggables.each do |loggable|
39
+ loggable.logger = logger
40
+ global_loggables << loggable
41
+ end
16
42
  end
17
43
 
18
44
  def ar_loggables
@@ -77,7 +103,9 @@ end
77
103
  if TestProf.rspec?
78
104
  RSpec.shared_context "logging:verbose" do
79
105
  around(:each) do |ex|
80
- with_logging(&ex)
106
+ next with_logging(&ex) if ex.metadata[:log] == true || ex.metadata[:log] == :all
107
+
108
+ ex.call
81
109
  end
82
110
  end
83
111
 
@@ -96,13 +124,10 @@ end
96
124
 
97
125
  TestProf.activate("LOG", "all") do
98
126
  TestProf.log :info, "Rails verbose logging enabled"
99
- ActiveSupport::LogSubscriber.logger =
100
- Rails.logger =
101
- ActiveRecord::Base.logger = TestProf::Rails::LoggingHelpers.logger
127
+ TestProf::Rails::LoggingHelpers.swap_logger!(TestProf::Rails::LoggingHelpers.all_loggables)
102
128
  end
103
129
 
104
130
  TestProf.activate("LOG", "ar") do
105
131
  TestProf.log :info, "Active Record verbose logging enabled"
106
- ActiveSupport::LogSubscriber.logger =
107
- ActiveRecord::Base.logger = TestProf::Rails::LoggingHelpers.logger
132
+ TestProf::Rails::LoggingHelpers.swap_logger!(TestProf::Rails::LoggingHelpers.ar_loggables)
108
133
  end
@@ -153,8 +153,8 @@ module TestProf
153
153
  end
154
154
  end
155
155
 
156
- replacement = "\\1#{parsed.fname}#{need_parens ? "(" : " "}"\
157
- "#{[desc, tags_str, htags_str].compact.join(", ")}"\
156
+ replacement = "\\1#{parsed.fname}#{need_parens ? "(" : " "}" \
157
+ "#{[desc, tags_str, htags_str].compact.join(", ")}" \
158
158
  "#{need_parens ? ") " : " "}\\3"
159
159
 
160
160
  if config.dry_run?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TestProf
4
- VERSION = "1.0.9"
4
+ VERSION = "1.0.10"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: test-prof
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.9
4
+ version: 1.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Dementyev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-06 00:00:00.000000000 Z
11
+ date: 2022-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -237,7 +237,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
237
237
  - !ruby/object:Gem::Version
238
238
  version: '0'
239
239
  requirements: []
240
- rubygems_version: 3.3.7
240
+ rubygems_version: 3.3.11
241
241
  signing_key:
242
242
  specification_version: 4
243
243
  summary: Ruby applications tests profiling tools