test-prof 1.4.2 → 1.4.4

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: db12b48471cc8814d90d2388415798a742a5b5d69f61862bc88c12ac118e80c2
4
- data.tar.gz: 9c930443a46e765d13b4528725d795aef8e4a2ab9b9c2c7a3939e2cb458ebd03
3
+ metadata.gz: 3cfa0f1751f398092de8ffa46d5bff81bb9eadd7b90caaf9293c62c93c6b3e20
4
+ data.tar.gz: 3afcb831782f0e58881839f33af07a41b3b42d63ac8eb87c35b6fd0eb01537ea
5
5
  SHA512:
6
- metadata.gz: 6fe1ff6102261d0b8c3c9e88e982255996b01ec6a34a9bc0d812a5021e8dd193aba57feca87d467c99f93973e98ed4cc4e94c94e8e1ab2e7b61dce806eeebedc
7
- data.tar.gz: db01e089936817767666c9d8d8fc11c0e2765bbb254be6e1baa5fac3ab26de7ad6d2b937dca7c6f0bef72fb60045caef2e909bf196978ebe94aef0c7f54da1c4
6
+ metadata.gz: 2de8fb8232f5ed623167846c37cce6224b297761324acdf6a17a47338e2a3904aa480b48fc9793a51f5595d3d839c3ff3bc9fbb262c7900ad3d7c819113947a0
7
+ data.tar.gz: dcec92d722f9e7cce9f1d371a2c6d363aa9a78a6cf1149a73d8b836a269ebf6bd14e50d86a8470cccc56a861b94646ad23494f43de6d9beb0cc6a5b478f77e93
data/CHANGELOG.md CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  ## master (unreleased)
4
4
 
5
+ ## 1.4.4 (2025-01-03)
6
+
7
+ - Fix _stamping_ specs with single quotes with Rpsec Stamp. ([@elasticspoon][])
8
+
9
+ ## 1.4.3 (2024-12-18)
10
+
11
+ - Fix handling new (lazy) connection pools in `before_all`. ([@palkan][])
12
+
13
+ - Updates Rubocop::Cop code to comply with most modern API. ([@aseroff][])
14
+
5
15
  ## 1.4.2 (2024-09-03) 🗓️
6
16
 
7
17
  - Ignore default scopes in `ActiveRecord::Base#refind`. ([@palkan][])
@@ -443,3 +453,4 @@ See [changelog](https://github.com/test-prof/test-prof/blob/v0.8.0/CHANGELOG.md)
443
453
  [@lHydra]: https://github.com/lHydra
444
454
  [@john-h-k]: https://github.com/john-h-k
445
455
  [@devinburnette]: https://github.com/devinburnette
456
+ [@elasticspoon]: https://github.com/elasticspoon
@@ -69,7 +69,7 @@ module TestProf
69
69
  end
70
70
 
71
71
  def commit
72
- return unless defined?(:@file)
72
+ return unless instance_variable_defined?(:@file)
73
73
 
74
74
  file.close
75
75
 
@@ -10,6 +10,7 @@ module TestProf
10
10
  class << self
11
11
  if ::ActiveRecord::Base.connection.pool.respond_to?(:pin_connection!)
12
12
  def begin_transaction
13
+ subscribe!
13
14
  ::ActiveRecord::Base.connection_handler.connection_pool_list(:writing).each do |pool|
14
15
  pool.pin_connection!(true)
15
16
  end
@@ -19,6 +20,26 @@ module TestProf
19
20
  ::ActiveRecord::Base.connection_handler.connection_pool_list(:writing).each do |pool|
20
21
  pool.unpin_connection!
21
22
  end
23
+ unsubscribe!
24
+ end
25
+
26
+ def subscribe!
27
+ Thread.current[:before_all_connection_subscriber] = ActiveSupport::Notifications.subscribe("!connection.active_record") do |_, _, _, _, payload|
28
+ connection_name = payload[:connection_name] if payload.key?(:connection_name)
29
+ shard = payload[:shard] if payload.key?(:shard)
30
+ next unless connection_name
31
+
32
+ pool = ::ActiveRecord::Base.connection_handler.retrieve_connection_pool(connection_name, shard: shard)
33
+ next unless pool && pool.role == :writing
34
+
35
+ pool.pin_connection!(true)
36
+ end
37
+ end
38
+
39
+ def unsubscribe!
40
+ return unless Thread.current[:before_all_connection_subscriber]
41
+ ActiveSupport::Notifications.unsubscribe(Thread.current[:before_all_connection_subscriber])
42
+ Thread.current[:before_all_connection_subscriber] = nil
22
43
  end
23
44
  else
24
45
  def all_connections
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module RSpec
6
- class AggregateExamples < ::RuboCop::Cop::Cop
6
+ class AggregateExamples < ::RuboCop::Cop::Base
7
7
  # @example `its`
8
8
  #
9
9
  # # Supports regular `its` call with an attribute/method name,
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module RSpec
6
- class AggregateExamples < ::RuboCop::Cop::Cop
6
+ class AggregateExamples < ::RuboCop::Cop::Base
7
7
  # @internal Support methods for keeping newlines around examples.
8
8
  module LineRangeHelpers
9
9
  include RangeHelp
@@ -5,7 +5,7 @@ require "test_prof/cops/rspec/language"
5
5
  module RuboCop
6
6
  module Cop
7
7
  module RSpec
8
- class AggregateExamples < ::RuboCop::Cop::Cop
8
+ class AggregateExamples < ::RuboCop::Cop::Base
9
9
  # When aggregated, the expectations will fail when not supposed to or
10
10
  # have a risk of not failing when expected to. One example is
11
11
  # `validate_presence_of :comment` as it leaves an empty comment after
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module RSpec
6
- class AggregateExamples < ::RuboCop::Cop::Cop
6
+ class AggregateExamples < ::RuboCop::Cop::Base
7
7
  # @internal
8
8
  # Support methods for example metadata.
9
9
  # Examples with similar metadata are grouped.
@@ -5,7 +5,7 @@ require "test_prof/cops/rspec/language"
5
5
  module RuboCop
6
6
  module Cop
7
7
  module RSpec
8
- class AggregateExamples < ::RuboCop::Cop::Cop
8
+ class AggregateExamples < ::RuboCop::Cop::Base
9
9
  # @internal
10
10
  # Node matchers and searchers.
11
11
  module NodeMatchers
@@ -108,7 +108,8 @@ module RuboCop
108
108
  # expect(number).to be_odd
109
109
  # end
110
110
  #
111
- class AggregateExamples < ::RuboCop::Cop::Cop
111
+ class AggregateExamples < ::RuboCop::Cop::Base
112
+ extend AutoCorrector
112
113
  include LineRangeHelpers
113
114
  include MetadataHelpers
114
115
  include NodeMatchers
@@ -123,29 +124,22 @@ module RuboCop
123
124
  def on_block(node)
124
125
  example_group_with_several_examples(node) do |all_examples|
125
126
  example_clusters(all_examples).each do |_, examples|
126
- examples[1..].each do |example|
127
+ examples.drop(1).each do |example|
127
128
  add_offense(example,
128
- location: :expression,
129
- message: message_for(example, examples[0]))
129
+ message: message_for(example, examples[0])) do |corrector|
130
+ clusters = example_clusters_for_autocorrect(example)
131
+ clusters.each do |metadata, examples|
132
+ range = range_for_replace(examples)
133
+ replacement = aggregated_example(examples, metadata)
134
+ corrector.replace(range, replacement)
135
+ examples.drop(1).map { |example| drop_example(corrector, example) }
136
+ end
137
+ end
130
138
  end
131
139
  end
132
140
  end
133
141
  end
134
142
 
135
- def autocorrect(example_node)
136
- clusters = example_clusters_for_autocorrect(example_node)
137
- return if clusters.empty?
138
-
139
- lambda do |corrector|
140
- clusters.each do |metadata, examples|
141
- range = range_for_replace(examples)
142
- replacement = aggregated_example(examples, metadata)
143
- corrector.replace(range, replacement)
144
- examples[1..].map { |example| drop_example(corrector, example) }
145
- end
146
- end
147
- end
148
-
149
143
  private
150
144
 
151
145
  # Clusters of examples in the same example group, on the same nesting
@@ -105,10 +105,9 @@ module TestProf
105
105
  # Do not analyze code within the block
106
106
  def ignore
107
107
  @ignored = true
108
- res = yield
108
+ yield
109
109
  ensure
110
110
  @ignored = false
111
- res
112
111
  end
113
112
 
114
113
  def ignore!
@@ -104,7 +104,7 @@ module TestProf
104
104
  if base.respond_to?(:parallelize_teardown)
105
105
  base.parallelize_teardown do
106
106
  last_klass = ::Minitest.previous_klass
107
- if last_klass&.respond_to?(:parallelized) && last_klass&.parallelized
107
+ if last_klass&.respond_to?(:parallelized) && last_klass.parallelized
108
108
  last_klass.before_all_executor&.deactivate!
109
109
  end
110
110
  end
@@ -153,14 +153,16 @@ 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(", ")}" \
158
- "#{need_parens ? ") " : " "}\\3"
156
+ replacement = proc do
157
+ $1 + "#{parsed.fname}#{need_parens ? "(" : " "}" \
158
+ "#{[desc, tags_str, htags_str].compact.join(", ")}" \
159
+ "#{need_parens ? ") " : " "}" + $3
160
+ end
159
161
 
160
162
  if config.dry_run?
161
- log :info, "Patched: #{example.sub(EXAMPLE_RXP, replacement)}"
163
+ log :info, "Patched: #{example.sub(EXAMPLE_RXP, &replacement)}"
162
164
  else
163
- example.sub!(EXAMPLE_RXP, replacement)
165
+ example.sub!(EXAMPLE_RXP, &replacement)
164
166
  end
165
167
  true
166
168
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TestProf
4
- VERSION = "1.4.2"
4
+ VERSION = "1.4.4"
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.4.2
4
+ version: 1.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Dementyev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-09-03 00:00:00.000000000 Z
11
+ date: 2025-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler