test-prof 1.4.1 → 1.4.3

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: 573636b6655a08f1cfa650a2cf0d0136bbbbc85b7e2b84cf76969698fb92b597
4
- data.tar.gz: 55e1c58e1a1ed27fd56862c0be79737f3b2261d31bec306a1264b8c08e77c37a
3
+ metadata.gz: 97628c14c29719b463c2937602d31e201bafcf3f910b94fb11ee28bd8f23aaf5
4
+ data.tar.gz: 4f924233ae1dfeb81bcca92624c741980c8d7c07a5a02d88909a08685a1980d4
5
5
  SHA512:
6
- metadata.gz: f26c70dd8a5bc0379fc38f49834da4ae2b43bdd5d79f4290a5147a4b4c22255dc9eee1a8d0b4ecce2003625afd295656a6745b1111fce6c9e9dfd618b9c0fe91
7
- data.tar.gz: b44cd50ef268582467f18956475d6d767cbea0aef3f78f5ddbdf966d1ba6a07749a9481390fce75be1a667cd9cc8d0e7673868357c7fd241a5cf1e5dea18a02b
6
+ metadata.gz: 865839f6c518c531be8c41701beb5714fadbbd1824cb96af8509e7a6b601973551a1bbdd0019000df001c82916c12d1232ee9caefeeb1be2eef384056f57da8a
7
+ data.tar.gz: 775d73f88529efdf0c3ad9d93354b0ca18c58640a2fc958d9615773b16f53776d8006d93a1c3094fd02f57bd2d1a412edd35e955369ed477f3102e6a443a1556
data/CHANGELOG.md CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  ## master (unreleased)
4
4
 
5
+ ## 1.4.3 (2024-12-18)
6
+
7
+ - Fix handling new (lazy) connection pools in `before_all`. ([@palkan][])
8
+
9
+ - Updates Rubocop::Cop code to comply with most modern API. ([@aseroff][])
10
+
11
+ ## 1.4.2 (2024-09-03) 🗓️
12
+
13
+ - Ignore default scopes in `ActiveRecord::Base#refind`. ([@palkan][])
14
+
5
15
  ## 1.4.1 (2024-08-23)
6
16
 
7
17
  - Skips loading the ActiveRecord adapter for runs where RSpec --dry-run mode is enabled. ([@devinburnette][])
@@ -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
@@ -12,7 +12,7 @@ module TestProf
12
12
  #
13
13
  # We need it to make sure that the state is clean.
14
14
  def refind
15
- self.class.find(send(self.class.primary_key))
15
+ self.class.unscoped.find(send(self.class.primary_key))
16
16
  end
17
17
  end
18
18
  end
@@ -3,7 +3,7 @@
3
3
  module TestProf # :nodoc: all
4
4
  FACTORY_GIRL_NAMES = {"factory_bot" => "::FactoryBot", "factory_girl" => "::FactoryGirl"}.freeze
5
5
 
6
- TestProf.require("active_support/inflector")
6
+ TestProf.require("active_support")
7
7
 
8
8
  FACTORY_GIRL_NAMES.find do |name, cname|
9
9
  TestProf.require(name) do
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TestProf
4
- VERSION = "1.4.1"
4
+ VERSION = "1.4.3"
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.1
4
+ version: 1.4.3
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-08-23 00:00:00.000000000 Z
11
+ date: 2024-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler