test-prof 1.4.0.rc.1 → 1.4.0.rc.2
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 +2 -0
- data/lib/test_prof/factory_default/fabrication_patch.rb +60 -0
- data/lib/test_prof/factory_default/factory_bot_patch.rb +56 -9
- data/lib/test_prof/factory_default.rb +5 -40
- data/lib/test_prof/recipes/minitest/before_all.rb +1 -1
- data/lib/test_prof/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24fc1f10f015aca5ffcaa3fa9568bd397f31d4a23c043d2b2781a1ebb2158a9e
|
4
|
+
data.tar.gz: fe79040f5a8455525e42d8b282cd6a48ff9d1be63ee9de2975c25f561419d7d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29e36545b692685977c96fd0f489a71189ee3472f2e1a09896c34635d43f01fe60de58a52a6bbec9f0352668057a4178d2f1f15aa454f94cafc4a87a933150ed
|
7
|
+
data.tar.gz: a80468699056d18f936e53b7474f9082b39105d222b05e713e2bd2bf3d992568d0cc51a308ba679e123a1e3c8f222e2522b545a2db60fbc07869044c53b9449e
|
data/CHANGELOG.md
CHANGED
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TestProf
|
4
|
+
module FactoryDefault # :nodoc: all
|
5
|
+
module FabricationPatch
|
6
|
+
module DefaultExt
|
7
|
+
def create_default(name, overrides = {}, &block)
|
8
|
+
obj = ::Fabricate.create(name, overrides, &block)
|
9
|
+
set_fabricate_default(name, obj)
|
10
|
+
end
|
11
|
+
|
12
|
+
def set_fabricate_default(name, obj, **opts)
|
13
|
+
FactoryDefault.register(
|
14
|
+
name, obj,
|
15
|
+
preserve_attributes: FactoryDefault.config.preserve_attributes,
|
16
|
+
preserve_traits: FactoryDefault.config.preserve_traits,
|
17
|
+
**opts
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_fabricate_default(name, **overrides)
|
22
|
+
FactoryDefault.get(name, nil, overrides, skip_stats: true)
|
23
|
+
end
|
24
|
+
|
25
|
+
def skip_fabricate_default(&block)
|
26
|
+
FactoryDefault.disable!(&block)
|
27
|
+
end
|
28
|
+
|
29
|
+
def create(name, overrides = {}, &block)
|
30
|
+
self.fabrication_depth += 1
|
31
|
+
# We do not support defaults for objects created with attribute blocks
|
32
|
+
return super if block
|
33
|
+
|
34
|
+
return super if fabrication_depth < 2
|
35
|
+
|
36
|
+
FactoryDefault.get(name, nil, overrides, **{}) ||
|
37
|
+
FactoryDefault.profiler.instrument(name, nil, overrides) { super }
|
38
|
+
ensure
|
39
|
+
self.fabrication_depth -= 1
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def fabrication_depth
|
45
|
+
Thread.current[:_fab_depth_] ||= 0
|
46
|
+
end
|
47
|
+
|
48
|
+
def fabrication_depth=(value)
|
49
|
+
Thread.current[:_fab_depth_] = value
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.patch
|
54
|
+
TestProf.require "fabrication" do
|
55
|
+
::Fabricate.singleton_class.prepend(DefaultExt)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -2,18 +2,65 @@
|
|
2
2
|
|
3
3
|
module TestProf
|
4
4
|
module FactoryDefault # :nodoc: all
|
5
|
-
module
|
6
|
-
|
7
|
-
|
5
|
+
module FactoryBotPatch
|
6
|
+
module RunnerExt
|
7
|
+
refine TestProf::FactoryBot::FactoryRunner do
|
8
|
+
attr_reader :name, :traits, :overrides
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
using RunnerExt
|
13
|
+
|
14
|
+
module StrategyExt
|
15
|
+
def association(runner)
|
16
|
+
FactoryDefault.get(runner.name, runner.traits, runner.overrides, **{}) ||
|
17
|
+
FactoryDefault.profiler.instrument(runner.name, runner.traits, runner.overrides) { super }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module SyntaxExt
|
22
|
+
def create_default(name, *args, &block)
|
23
|
+
options = args.extract_options!
|
24
|
+
default_options = {}
|
25
|
+
default_options[:preserve_traits] = options.delete(:preserve_traits) if options.key?(:preserve_traits)
|
26
|
+
default_options[:preserve_attributes] = options.delete(:preserve_attributes) if options.key?(:preserve_attributes)
|
27
|
+
|
28
|
+
obj = TestProf::FactoryBot.create(name, *args, options, &block)
|
29
|
+
|
30
|
+
# Factory with traits
|
31
|
+
name = [name, *args] if args.any?
|
32
|
+
|
33
|
+
set_factory_default(name, obj, **default_options)
|
34
|
+
end
|
35
|
+
|
36
|
+
def set_factory_default(*name, obj, preserve_traits: FactoryDefault.config.preserve_traits, preserve_attributes: FactoryDefault.config.preserve_attributes, **other)
|
37
|
+
name = name.first if name.size == 1
|
38
|
+
FactoryDefault.register(
|
39
|
+
name, obj,
|
40
|
+
preserve_traits: preserve_traits,
|
41
|
+
preserve_attributes: preserve_attributes,
|
42
|
+
**other
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
def get_factory_default(name, *traits, **overrides)
|
47
|
+
FactoryDefault.get(name, traits, overrides, skip_stats: true)
|
48
|
+
end
|
49
|
+
|
50
|
+
def skip_factory_default(&block)
|
51
|
+
FactoryDefault.disable!(&block)
|
52
|
+
end
|
8
53
|
end
|
9
|
-
end
|
10
54
|
|
11
|
-
|
55
|
+
def self.patch
|
56
|
+
require "test_prof/factory_bot"
|
57
|
+
return unless defined?(TestProf::FactoryBot)
|
12
58
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
59
|
+
TestProf::FactoryBot::Syntax::Methods.include SyntaxExt
|
60
|
+
TestProf::FactoryBot.extend SyntaxExt
|
61
|
+
TestProf::FactoryBot::Strategy::Create.prepend StrategyExt
|
62
|
+
TestProf::FactoryBot::Strategy::Build.prepend StrategyExt
|
63
|
+
TestProf::FactoryBot::Strategy::Stub.prepend StrategyExt
|
17
64
|
end
|
18
65
|
end
|
19
66
|
end
|
@@ -1,8 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "test_prof/core"
|
4
|
-
|
4
|
+
|
5
5
|
require "test_prof/factory_default/factory_bot_patch"
|
6
|
+
require "test_prof/factory_default/fabrication_patch"
|
7
|
+
|
6
8
|
require "test_prof/ext/float_duration"
|
7
9
|
require "test_prof/ext/active_record_refind" if defined?(::ActiveRecord::Base)
|
8
10
|
|
@@ -144,40 +146,6 @@ module TestProf
|
|
144
146
|
end
|
145
147
|
end
|
146
148
|
|
147
|
-
module DefaultSyntax # :nodoc:
|
148
|
-
def create_default(name, *args, &block)
|
149
|
-
options = args.extract_options!
|
150
|
-
default_options = {}
|
151
|
-
default_options[:preserve_traits] = options.delete(:preserve_traits) if options.key?(:preserve_traits)
|
152
|
-
default_options[:preserve_attributes] = options.delete(:preserve_attributes) if options.key?(:preserve_attributes)
|
153
|
-
|
154
|
-
obj = TestProf::FactoryBot.create(name, *args, options, &block)
|
155
|
-
|
156
|
-
# Factory with traits
|
157
|
-
name = [name, *args] if args.any?
|
158
|
-
|
159
|
-
set_factory_default(name, obj, **default_options)
|
160
|
-
end
|
161
|
-
|
162
|
-
def set_factory_default(*name, obj, preserve_traits: FactoryDefault.config.preserve_traits, preserve_attributes: FactoryDefault.config.preserve_attributes, **other)
|
163
|
-
name = name.first if name.size == 1
|
164
|
-
FactoryDefault.register(
|
165
|
-
name, obj,
|
166
|
-
preserve_traits: preserve_traits,
|
167
|
-
preserve_attributes: preserve_attributes,
|
168
|
-
**other
|
169
|
-
)
|
170
|
-
end
|
171
|
-
|
172
|
-
def get_factory_default(name, *traits, **overrides)
|
173
|
-
FactoryDefault.get(name, traits, overrides, skip_stats: true)
|
174
|
-
end
|
175
|
-
|
176
|
-
def skip_factory_default(&block)
|
177
|
-
FactoryDefault.disable!(&block)
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
149
|
class Configuration
|
182
150
|
attr_accessor :preserve_traits, :preserve_attributes,
|
183
151
|
:report_summary, :report_stats,
|
@@ -202,11 +170,8 @@ module TestProf
|
|
202
170
|
attr_reader :stats, :profiler
|
203
171
|
|
204
172
|
def init
|
205
|
-
|
206
|
-
|
207
|
-
TestProf::FactoryBot::Strategy::Create.prepend StrategyExt
|
208
|
-
TestProf::FactoryBot::Strategy::Build.prepend StrategyExt
|
209
|
-
TestProf::FactoryBot::Strategy::Stub.prepend StrategyExt
|
173
|
+
FactoryBotPatch.patch
|
174
|
+
FabricationPatch.patch
|
210
175
|
|
211
176
|
@profiler = config.profiling_enabled? ? Profiler.new : NoopProfiler.new
|
212
177
|
@enabled = ENV["FACTORY_DEFAULT_DISABLED"] != "1"
|
@@ -114,7 +114,7 @@ module TestProf
|
|
114
114
|
base.singleton_class.prepend(Module.new do
|
115
115
|
def parallelize(workers: :number_of_processors, with: :processes)
|
116
116
|
# super.parallelize returns nil when no parallelization is set up
|
117
|
-
if super
|
117
|
+
if super.nil?
|
118
118
|
return
|
119
119
|
end
|
120
120
|
|
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.0.rc.
|
4
|
+
version: 1.4.0.rc.2
|
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-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -164,6 +164,7 @@ files:
|
|
164
164
|
- lib/test_prof/factory_all_stub/factory_bot_patch.rb
|
165
165
|
- lib/test_prof/factory_bot.rb
|
166
166
|
- lib/test_prof/factory_default.rb
|
167
|
+
- lib/test_prof/factory_default/fabrication_patch.rb
|
167
168
|
- lib/test_prof/factory_default/factory_bot_patch.rb
|
168
169
|
- lib/test_prof/factory_doctor.rb
|
169
170
|
- lib/test_prof/factory_doctor/fabrication_patch.rb
|