test-prof 1.4.0.rc.1 → 1.4.0.rc.2

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: 2bb23a2e0630d64b02f4f755f801189a19a5d26179dcb5d9d9420b73a0b78319
4
- data.tar.gz: 56fe8596860ac93bb46adb6d6c9ff027de6eddf43eb3fbd28d69f2fddd76c1eb
3
+ metadata.gz: 24fc1f10f015aca5ffcaa3fa9568bd397f31d4a23c043d2b2781a1ebb2158a9e
4
+ data.tar.gz: fe79040f5a8455525e42d8b282cd6a48ff9d1be63ee9de2975c25f561419d7d9
5
5
  SHA512:
6
- metadata.gz: 03f0304518182b46058f20f2a818067f264901278da60f0449cbc9ca37e3283bd093e737f7dff4312b3e4e99e3f24106d620ba90c6561b6218b3f99077785d53
7
- data.tar.gz: 37608d5a827f5caff39f1fdd0ad066fed97d9cf42c1da532dac6b0019f3372f89b0779daf4ad3e570435c3aea624789d61723c6155c147e9d140d27d9db5f071
6
+ metadata.gz: 29e36545b692685977c96fd0f489a71189ee3472f2e1a09896c34635d43f01fe60de58a52a6bbec9f0352668057a4178d2f1f15aa454f94cafc4a87a933150ed
7
+ data.tar.gz: a80468699056d18f936e53b7474f9082b39105d222b05e713e2bd2bf3d992568d0cc51a308ba679e123a1e3c8f222e2522b545a2db60fbc07869044c53b9449e
data/CHANGELOG.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  ## master (unreleased)
4
4
 
5
+ - FactoryDefault: add Fabrication support. ([@palkan][])
6
+
5
7
  - Drop support for **Ruby <2.7** and **Rails <6**.
6
8
 
7
9
  - FactoryDefault: Add `#get_factory_default`. [[@john-h-k][]]
@@ -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 RunnerExt
6
- refine TestProf::FactoryBot::FactoryRunner do
7
- attr_reader :name, :traits, :overrides
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
- using RunnerExt
55
+ def self.patch
56
+ require "test_prof/factory_bot"
57
+ return unless defined?(TestProf::FactoryBot)
12
58
 
13
- module StrategyExt
14
- def association(runner)
15
- FactoryDefault.get(runner.name, runner.traits, runner.overrides, **{}) ||
16
- FactoryDefault.profiler.instrument(runner.name, runner.traits, runner.overrides) { super }
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
- require "test_prof/factory_bot"
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
- TestProf::FactoryBot::Syntax::Methods.include DefaultSyntax
206
- TestProf::FactoryBot.extend DefaultSyntax
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(workers: workers, with: with).nil?
117
+ if super.nil?
118
118
  return
119
119
  end
120
120
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TestProf
4
- VERSION = "1.4.0.rc.1"
4
+ VERSION = "1.4.0.rc.2"
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.0.rc.1
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-06-13 00:00:00.000000000 Z
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