test-prof 1.4.0.rc.4 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/lib/test_prof/any_fixture/dsl.rb +19 -1
- data/lib/test_prof/any_fixture.rb +16 -2
- data/lib/test_prof/before_all/isolator.rb +6 -15
- data/lib/test_prof/before_all.rb +30 -7
- data/lib/test_prof/cops/rspec/aggregate_examples/its.rb +1 -1
- data/lib/test_prof/cops/rspec/aggregate_examples.rb +2 -2
- data/lib/test_prof/core.rb +4 -0
- data/lib/test_prof/ext/string_truncate.rb +1 -1
- data/lib/test_prof/recipes/rspec/any_fixture.rb +8 -0
- data/lib/test_prof/rspec_stamp/parser.rb +1 -1
- data/lib/test_prof/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 573636b6655a08f1cfa650a2cf0d0136bbbbc85b7e2b84cf76969698fb92b597
|
4
|
+
data.tar.gz: 55e1c58e1a1ed27fd56862c0be79737f3b2261d31bec306a1264b8c08e77c37a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f26c70dd8a5bc0379fc38f49834da4ae2b43bdd5d79f4290a5147a4b4c22255dc9eee1a8d0b4ecce2003625afd295656a6745b1111fce6c9e9dfd618b9c0fe91
|
7
|
+
data.tar.gz: b44cd50ef268582467f18956475d6d767cbea0aef3f78f5ddbdf966d1ba6a07749a9481390fce75be1a667cd9cc8d0e7673868357c7fd241a5cf1e5dea18a02b
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,14 @@
|
|
2
2
|
|
3
3
|
## master (unreleased)
|
4
4
|
|
5
|
+
## 1.4.1 (2024-08-23)
|
6
|
+
|
7
|
+
- Skips loading the ActiveRecord adapter for runs where RSpec --dry-run mode is enabled. ([@devinburnette][])
|
8
|
+
|
9
|
+
## 1.4.0 (2024-08-12)
|
10
|
+
|
11
|
+
- AnyFixture: Disable fixtures cache within _clean fixture_ context. Automatically _refind_ records when using `#fixture`. ([@palkan][])
|
12
|
+
|
5
13
|
- Add new TPS (tests per second) profiler. ([@palkan][])
|
6
14
|
|
7
15
|
- FactoryDefault: add Fabrication support. ([@palkan][])
|
@@ -430,3 +438,4 @@ See [changelog](https://github.com/test-prof/test-prof/blob/v0.8.0/CHANGELOG.md)
|
|
430
438
|
[@lioneldebauge]: https://github.com/lioneldebauge
|
431
439
|
[@lHydra]: https://github.com/lHydra
|
432
440
|
[@john-h-k]: https://github.com/john-h-k
|
441
|
+
[@devinburnette]: https://github.com/devinburnette
|
@@ -1,5 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
if defined?(::ActiveRecord::Base)
|
4
|
+
require "test_prof/ext/active_record_refind"
|
5
|
+
using TestProf::Ext::ActiveRecordRefind
|
6
|
+
end
|
7
|
+
|
3
8
|
module TestProf
|
4
9
|
module AnyFixture
|
5
10
|
# Adds "global" `fixture`, `before_fixtures_reset` and `after_fixtures_reset` methods (through refinement)
|
@@ -9,7 +14,20 @@ module TestProf
|
|
9
14
|
# - Rails added `Kernel.prepend` in 6.1: https://github.com/rails/rails/commit/3124007bd674dcdc9c3b5c6b2964dfb7a1a0733c
|
10
15
|
refine ::Object do
|
11
16
|
def fixture(id, &block)
|
12
|
-
|
17
|
+
id = :"#{id}"
|
18
|
+
record = ::TestProf::AnyFixture.cached(id)
|
19
|
+
|
20
|
+
return ::TestProf::AnyFixture.register(id, &block) unless record
|
21
|
+
|
22
|
+
return record.refind if record.is_a?(::ActiveRecord::Base)
|
23
|
+
|
24
|
+
if record.respond_to?(:to_ary)
|
25
|
+
return record.map do |rec|
|
26
|
+
rec.is_a?(::ActiveRecord::Base) ? rec.refind : rec
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
record
|
13
31
|
end
|
14
32
|
|
15
33
|
def before_fixtures_reset(&block)
|
@@ -108,14 +108,18 @@ module TestProf
|
|
108
108
|
cached(id) do
|
109
109
|
raise "No fixture named #{id} has been registered" unless block_given?
|
110
110
|
|
111
|
+
next yield if @disabled
|
112
|
+
|
111
113
|
ActiveSupport::Notifications.subscribed(method(:subscriber), "sql.active_record") do
|
112
114
|
yield
|
113
115
|
end
|
114
116
|
end
|
115
117
|
end
|
116
118
|
|
117
|
-
def cached(id)
|
118
|
-
|
119
|
+
def cached(id, &block)
|
120
|
+
return (block_given? ? yield : nil) if @disabled
|
121
|
+
|
122
|
+
cache.fetch(id, &block)
|
119
123
|
end
|
120
124
|
|
121
125
|
# Create and register new SQL dump.
|
@@ -174,6 +178,14 @@ module TestProf
|
|
174
178
|
callbacks.clear
|
175
179
|
end
|
176
180
|
|
181
|
+
def disable!
|
182
|
+
@disabled = true
|
183
|
+
end
|
184
|
+
|
185
|
+
def enable!
|
186
|
+
@disabled = false
|
187
|
+
end
|
188
|
+
|
177
189
|
def before_fixtures_reset(&block)
|
178
190
|
callbacks[:before_fixtures_reset] << block
|
179
191
|
end
|
@@ -266,5 +278,7 @@ module TestProf
|
|
266
278
|
connection.disable_referential_integrity { yield }
|
267
279
|
end
|
268
280
|
end
|
281
|
+
|
282
|
+
enable!
|
269
283
|
end
|
270
284
|
end
|
@@ -1,20 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
def begin_transaction(*)
|
8
|
-
::Isolator.transactions_threshold += 1
|
9
|
-
super
|
10
|
-
end
|
3
|
+
TestProf::BeforeAll.configure do |config|
|
4
|
+
config.before(:begin) do
|
5
|
+
::Isolator.incr_thresholds!
|
6
|
+
end
|
11
7
|
|
12
|
-
|
13
|
-
|
14
|
-
::Isolator.transactions_threshold -= 1
|
15
|
-
end
|
16
|
-
end
|
8
|
+
config.after(:rollback) do
|
9
|
+
::Isolator.decr_thresholds!
|
17
10
|
end
|
18
11
|
end
|
19
|
-
|
20
|
-
TestProf::BeforeAll.singleton_class.prepend(TestProf::BeforeAll::Isolator)
|
data/lib/test_prof/before_all.rb
CHANGED
@@ -14,8 +14,26 @@ module TestProf
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
# Used in dry-run mode
|
18
|
+
class NoopAdapter
|
19
|
+
class << self
|
20
|
+
def begin_transaction(...)
|
21
|
+
end
|
22
|
+
|
23
|
+
def rollback_transaction(...)
|
24
|
+
end
|
25
|
+
|
26
|
+
def setup_fixtures(...)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
17
31
|
class << self
|
18
|
-
|
32
|
+
attr_writer :adapter
|
33
|
+
|
34
|
+
def adapter
|
35
|
+
@adapter ||= default_adapter
|
36
|
+
end
|
19
37
|
|
20
38
|
def begin_transaction(scope = nil, metadata = [])
|
21
39
|
raise AdapterMissing if adapter.nil?
|
@@ -47,6 +65,17 @@ module TestProf
|
|
47
65
|
def configure
|
48
66
|
yield config
|
49
67
|
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def default_adapter
|
72
|
+
return NoopAdapter if TestProf.dry_run?
|
73
|
+
|
74
|
+
if defined?(::ActiveRecord::Base)
|
75
|
+
require "test_prof/before_all/adapters/active_record"
|
76
|
+
Adapters::ActiveRecord
|
77
|
+
end
|
78
|
+
end
|
50
79
|
end
|
51
80
|
|
52
81
|
class HookEntry # :nodoc:
|
@@ -138,12 +167,6 @@ module TestProf
|
|
138
167
|
end
|
139
168
|
end
|
140
169
|
|
141
|
-
if defined?(::ActiveRecord::Base)
|
142
|
-
require "test_prof/before_all/adapters/active_record"
|
143
|
-
|
144
|
-
TestProf::BeforeAll.adapter = TestProf::BeforeAll::Adapters::ActiveRecord
|
145
|
-
end
|
146
|
-
|
147
170
|
if defined?(::Isolator)
|
148
171
|
require "test_prof/before_all/isolator"
|
149
172
|
end
|
@@ -123,7 +123,7 @@ module RuboCop
|
|
123
123
|
def on_block(node)
|
124
124
|
example_group_with_several_examples(node) do |all_examples|
|
125
125
|
example_clusters(all_examples).each do |_, examples|
|
126
|
-
examples[1
|
126
|
+
examples[1..].each do |example|
|
127
127
|
add_offense(example,
|
128
128
|
location: :expression,
|
129
129
|
message: message_for(example, examples[0]))
|
@@ -141,7 +141,7 @@ module RuboCop
|
|
141
141
|
range = range_for_replace(examples)
|
142
142
|
replacement = aggregated_example(examples, metadata)
|
143
143
|
corrector.replace(range, replacement)
|
144
|
-
examples[1
|
144
|
+
examples[1..].map { |example| drop_example(corrector, example) }
|
145
145
|
end
|
146
146
|
end
|
147
147
|
end
|
data/lib/test_prof/core.rb
CHANGED
@@ -75,6 +75,10 @@ module TestProf
|
|
75
75
|
defined?(::Spring::Application) && (disabled.nil? || disabled.empty? || disabled == "0")
|
76
76
|
end
|
77
77
|
|
78
|
+
def dry_run?
|
79
|
+
rspec? && ::RSpec.configuration.dry_run?
|
80
|
+
end
|
81
|
+
|
78
82
|
# Returns the current process time
|
79
83
|
def now
|
80
84
|
Process.clock_gettime_for_test_prof(Process::CLOCK_MONOTONIC)
|
@@ -1,6 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "test_prof/any_fixture"
|
4
|
+
require "test_prof/any_fixture/dsl"
|
5
|
+
require "test_prof/ext/active_record_refind"
|
6
|
+
|
4
7
|
require "test_prof/recipes/rspec/before_all"
|
5
8
|
|
6
9
|
RSpec.shared_context "any_fixture:clean" do
|
@@ -8,6 +11,11 @@ RSpec.shared_context "any_fixture:clean" do
|
|
8
11
|
|
9
12
|
before_all do
|
10
13
|
TestProf::AnyFixture.clean
|
14
|
+
TestProf::AnyFixture.disable!
|
15
|
+
end
|
16
|
+
|
17
|
+
after(:all) do
|
18
|
+
TestProf::AnyFixture.enable!
|
11
19
|
end
|
12
20
|
end
|
13
21
|
|
data/lib/test_prof/version.rb
CHANGED
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.
|
4
|
+
version: 1.4.1
|
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-
|
11
|
+
date: 2024-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -252,9 +252,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
252
252
|
version: 2.7.0
|
253
253
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
254
254
|
requirements:
|
255
|
-
- - "
|
255
|
+
- - ">="
|
256
256
|
- !ruby/object:Gem::Version
|
257
|
-
version:
|
257
|
+
version: '0'
|
258
258
|
requirements: []
|
259
259
|
rubygems_version: 3.4.19
|
260
260
|
signing_key:
|