factory_bot 4.11.1 → 6.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +58 -13
- data/GETTING_STARTED.md +785 -153
- data/LICENSE +1 -1
- data/NEWS.md +379 -0
- data/README.md +20 -30
- data/lib/factory_bot/aliases.rb +2 -2
- data/lib/factory_bot/attribute/association.rb +2 -2
- data/lib/factory_bot/attribute/dynamic.rb +3 -2
- data/lib/factory_bot/attribute.rb +4 -39
- data/lib/factory_bot/attribute_assigner.rb +24 -10
- data/lib/factory_bot/attribute_list.rb +3 -2
- data/lib/factory_bot/callback.rb +4 -11
- data/lib/factory_bot/configuration.rb +15 -19
- data/lib/factory_bot/declaration/association.rb +33 -3
- data/lib/factory_bot/declaration/dynamic.rb +3 -1
- data/lib/factory_bot/declaration/implicit.rb +7 -2
- data/lib/factory_bot/declaration.rb +5 -5
- data/lib/factory_bot/declaration_list.rb +3 -3
- data/lib/factory_bot/decorator/attribute_hash.rb +1 -1
- data/lib/factory_bot/decorator/invocation_tracker.rb +2 -1
- data/lib/factory_bot/decorator.rb +20 -4
- data/lib/factory_bot/definition.rb +69 -21
- data/lib/factory_bot/definition_hierarchy.rb +1 -11
- data/lib/factory_bot/definition_proxy.rb +119 -64
- data/lib/factory_bot/enum.rb +27 -0
- data/lib/factory_bot/errors.rb +7 -4
- data/lib/factory_bot/evaluation.rb +1 -1
- data/lib/factory_bot/evaluator.rb +10 -11
- data/lib/factory_bot/evaluator_class_definer.rb +1 -1
- data/lib/factory_bot/factory.rb +12 -12
- data/lib/factory_bot/factory_runner.rb +4 -4
- data/lib/factory_bot/find_definitions.rb +2 -2
- data/lib/factory_bot/internal.rb +91 -0
- data/lib/factory_bot/linter.rb +41 -28
- data/lib/factory_bot/null_factory.rb +13 -4
- data/lib/factory_bot/null_object.rb +2 -6
- data/lib/factory_bot/registry.rb +17 -8
- data/lib/factory_bot/reload.rb +2 -3
- data/lib/factory_bot/sequence.rb +5 -6
- data/lib/factory_bot/strategy/stub.rb +37 -32
- data/lib/factory_bot/strategy_calculator.rb +1 -1
- data/lib/factory_bot/strategy_syntax_method_registrar.rb +13 -2
- data/lib/factory_bot/syntax/default.rb +13 -25
- data/lib/factory_bot/syntax/methods.rb +32 -9
- data/lib/factory_bot/syntax.rb +2 -2
- data/lib/factory_bot/trait.rb +7 -4
- data/lib/factory_bot/version.rb +1 -1
- data/lib/factory_bot.rb +71 -140
- metadata +46 -34
- data/NEWS +0 -306
- data/lib/factory_bot/attribute/static.rb +0 -16
- data/lib/factory_bot/declaration/static.rb +0 -26
- data/lib/factory_bot/decorator/class_key_hash.rb +0 -28
data/lib/factory_bot.rb
CHANGED
@@ -1,59 +1,61 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
|
6
|
-
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
16
|
-
require
|
17
|
-
require
|
18
|
-
require
|
19
|
-
require
|
20
|
-
require
|
21
|
-
require
|
22
|
-
require
|
23
|
-
require
|
24
|
-
require
|
25
|
-
require
|
26
|
-
require
|
27
|
-
require
|
28
|
-
require
|
29
|
-
require
|
30
|
-
require
|
31
|
-
require
|
32
|
-
require
|
33
|
-
require
|
34
|
-
require
|
35
|
-
require
|
36
|
-
require
|
37
|
-
require
|
38
|
-
require
|
39
|
-
require
|
40
|
-
require
|
41
|
-
require
|
42
|
-
require
|
43
|
-
require
|
44
|
-
require
|
45
|
-
require
|
46
|
-
require
|
47
|
-
require
|
1
|
+
require "set"
|
2
|
+
require "active_support/core_ext/module/delegation"
|
3
|
+
require "active_support/core_ext/module/attribute_accessors"
|
4
|
+
require "active_support/deprecation"
|
5
|
+
require "active_support/notifications"
|
6
|
+
|
7
|
+
require "factory_bot/internal"
|
8
|
+
require "factory_bot/definition_hierarchy"
|
9
|
+
require "factory_bot/configuration"
|
10
|
+
require "factory_bot/errors"
|
11
|
+
require "factory_bot/factory_runner"
|
12
|
+
require "factory_bot/strategy_syntax_method_registrar"
|
13
|
+
require "factory_bot/strategy_calculator"
|
14
|
+
require "factory_bot/strategy/build"
|
15
|
+
require "factory_bot/strategy/create"
|
16
|
+
require "factory_bot/strategy/attributes_for"
|
17
|
+
require "factory_bot/strategy/stub"
|
18
|
+
require "factory_bot/strategy/null"
|
19
|
+
require "factory_bot/registry"
|
20
|
+
require "factory_bot/null_factory"
|
21
|
+
require "factory_bot/null_object"
|
22
|
+
require "factory_bot/evaluation"
|
23
|
+
require "factory_bot/factory"
|
24
|
+
require "factory_bot/attribute_assigner"
|
25
|
+
require "factory_bot/evaluator"
|
26
|
+
require "factory_bot/evaluator_class_definer"
|
27
|
+
require "factory_bot/attribute"
|
28
|
+
require "factory_bot/callback"
|
29
|
+
require "factory_bot/callbacks_observer"
|
30
|
+
require "factory_bot/declaration_list"
|
31
|
+
require "factory_bot/declaration"
|
32
|
+
require "factory_bot/sequence"
|
33
|
+
require "factory_bot/attribute_list"
|
34
|
+
require "factory_bot/trait"
|
35
|
+
require "factory_bot/enum"
|
36
|
+
require "factory_bot/aliases"
|
37
|
+
require "factory_bot/definition"
|
38
|
+
require "factory_bot/definition_proxy"
|
39
|
+
require "factory_bot/syntax"
|
40
|
+
require "factory_bot/syntax_runner"
|
41
|
+
require "factory_bot/find_definitions"
|
42
|
+
require "factory_bot/reload"
|
43
|
+
require "factory_bot/decorator"
|
44
|
+
require "factory_bot/decorator/attribute_hash"
|
45
|
+
require "factory_bot/decorator/disallows_duplicates_registry"
|
46
|
+
require "factory_bot/decorator/invocation_tracker"
|
47
|
+
require "factory_bot/decorator/new_constructor"
|
48
|
+
require "factory_bot/linter"
|
49
|
+
require "factory_bot/version"
|
48
50
|
|
49
51
|
module FactoryBot
|
50
|
-
|
51
|
-
@configuration ||= Configuration.new
|
52
|
-
end
|
52
|
+
Deprecation = ActiveSupport::Deprecation.new("7.0", "factory_bot")
|
53
53
|
|
54
|
-
|
55
|
-
|
56
|
-
|
54
|
+
mattr_accessor :use_parent_strategy, instance_accessor: false
|
55
|
+
self.use_parent_strategy = true
|
56
|
+
|
57
|
+
mattr_accessor :automatically_define_enum_traits, instance_accessor: false
|
58
|
+
self.automatically_define_enum_traits = true
|
57
59
|
|
58
60
|
# Look for errors in factories and (optionally) their traits.
|
59
61
|
# Parameters:
|
@@ -61,100 +63,29 @@ module FactoryBot
|
|
61
63
|
# options:
|
62
64
|
# traits: true - to lint traits as well as factories
|
63
65
|
# strategy: :create - to specify the strategy for linting
|
66
|
+
# verbose: true - to include full backtraces for each linting error
|
64
67
|
def self.lint(*args)
|
65
68
|
options = args.extract_options!
|
66
69
|
factories_to_lint = args[0] || FactoryBot.factories
|
67
|
-
|
68
|
-
factory_strategy = options[:strategy] || :create
|
69
|
-
Linter.new(factories_to_lint, linting_strategy, factory_strategy).lint!
|
70
|
-
end
|
71
|
-
|
72
|
-
class << self
|
73
|
-
delegate :factories,
|
74
|
-
:sequences,
|
75
|
-
:traits,
|
76
|
-
:callbacks,
|
77
|
-
:strategies,
|
78
|
-
:callback_names,
|
79
|
-
:to_create,
|
80
|
-
:skip_create,
|
81
|
-
:initialize_with,
|
82
|
-
:constructor,
|
83
|
-
:duplicate_attribute_assignment_from_initialize_with,
|
84
|
-
:duplicate_attribute_assignment_from_initialize_with=,
|
85
|
-
:allow_class_lookup,
|
86
|
-
:allow_class_lookup=,
|
87
|
-
:use_parent_strategy,
|
88
|
-
:use_parent_strategy=,
|
89
|
-
to: :configuration
|
90
|
-
end
|
91
|
-
|
92
|
-
def self.register_factory(factory)
|
93
|
-
factory.names.each do |name|
|
94
|
-
factories.register(name, factory)
|
95
|
-
end
|
96
|
-
factory
|
97
|
-
end
|
98
|
-
|
99
|
-
def self.factory_by_name(name)
|
100
|
-
factories.find(name)
|
101
|
-
end
|
102
|
-
|
103
|
-
def self.register_sequence(sequence)
|
104
|
-
sequence.names.each do |name|
|
105
|
-
sequences.register(name, sequence)
|
106
|
-
end
|
107
|
-
sequence
|
108
|
-
end
|
109
|
-
|
110
|
-
def self.sequence_by_name(name)
|
111
|
-
sequences.find(name)
|
112
|
-
end
|
113
|
-
|
114
|
-
def self.rewind_sequences
|
115
|
-
sequences.each(&:rewind)
|
116
|
-
end
|
117
|
-
|
118
|
-
def self.register_trait(trait)
|
119
|
-
trait.names.each do |name|
|
120
|
-
traits.register(name, trait)
|
121
|
-
end
|
122
|
-
trait
|
123
|
-
end
|
124
|
-
|
125
|
-
def self.trait_by_name(name)
|
126
|
-
traits.find(name)
|
70
|
+
Linter.new(factories_to_lint, **options).lint!
|
127
71
|
end
|
128
72
|
|
129
|
-
|
130
|
-
|
131
|
-
|
73
|
+
# Set the starting value for ids when using the build_stubbed strategy
|
74
|
+
#
|
75
|
+
# Arguments:
|
76
|
+
# * starting_id +Integer+
|
77
|
+
# The new starting id value.
|
78
|
+
def self.build_stubbed_starting_id=(starting_id)
|
79
|
+
Strategy::Stub.next_id = starting_id - 1
|
132
80
|
end
|
133
81
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
register_strategy(:create, FactoryBot::Strategy::Create)
|
141
|
-
register_strategy(:attributes_for, FactoryBot::Strategy::AttributesFor)
|
142
|
-
register_strategy(:build_stubbed, FactoryBot::Strategy::Stub)
|
143
|
-
register_strategy(:null, FactoryBot::Strategy::Null)
|
144
|
-
end
|
145
|
-
|
146
|
-
def self.register_default_callbacks
|
147
|
-
register_callback(:after_build)
|
148
|
-
register_callback(:after_create)
|
149
|
-
register_callback(:after_stub)
|
150
|
-
register_callback(:before_create)
|
151
|
-
end
|
152
|
-
|
153
|
-
def self.register_callback(name)
|
154
|
-
name = name.to_sym
|
155
|
-
callback_names << name
|
82
|
+
class << self
|
83
|
+
delegate :factories,
|
84
|
+
:register_strategy,
|
85
|
+
:rewind_sequences,
|
86
|
+
:strategy_by_name,
|
87
|
+
to: Internal
|
156
88
|
end
|
157
89
|
end
|
158
90
|
|
159
|
-
FactoryBot.register_default_strategies
|
160
|
-
FactoryBot.register_default_callbacks
|
91
|
+
FactoryBot::Internal.register_default_strategies
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: factory_bot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 6.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Clayton
|
8
8
|
- Joe Ferris
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-05-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -17,42 +17,42 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
20
|
+
version: 5.0.0
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
27
|
+
version: 5.0.0
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: activerecord
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
32
|
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version:
|
34
|
+
version: '0'
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version:
|
41
|
+
version: '0'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: appraisal
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
|
-
- - "
|
46
|
+
- - ">="
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version:
|
48
|
+
version: '0'
|
49
49
|
type: :development
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
|
-
- - "
|
53
|
+
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version:
|
55
|
+
version: '0'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: aruba
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -71,46 +71,60 @@ dependencies:
|
|
71
71
|
name: cucumber
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
|
-
- - "
|
74
|
+
- - ">="
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
version:
|
76
|
+
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
|
-
- - "
|
81
|
+
- - ">="
|
82
82
|
- !ruby/object:Gem::Version
|
83
|
-
version:
|
83
|
+
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: rake
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
84
98
|
- !ruby/object:Gem::Dependency
|
85
99
|
name: rspec
|
86
100
|
requirement: !ruby/object:Gem::Requirement
|
87
101
|
requirements:
|
88
|
-
- - "
|
102
|
+
- - ">="
|
89
103
|
- !ruby/object:Gem::Version
|
90
|
-
version: '
|
104
|
+
version: '0'
|
91
105
|
type: :development
|
92
106
|
prerelease: false
|
93
107
|
version_requirements: !ruby/object:Gem::Requirement
|
94
108
|
requirements:
|
95
|
-
- - "
|
109
|
+
- - ">="
|
96
110
|
- !ruby/object:Gem::Version
|
97
|
-
version: '
|
111
|
+
version: '0'
|
98
112
|
- !ruby/object:Gem::Dependency
|
99
113
|
name: rspec-its
|
100
114
|
requirement: !ruby/object:Gem::Requirement
|
101
115
|
requirements:
|
102
|
-
- - "
|
116
|
+
- - ">="
|
103
117
|
- !ruby/object:Gem::Version
|
104
|
-
version: '
|
118
|
+
version: '0'
|
105
119
|
type: :development
|
106
120
|
prerelease: false
|
107
121
|
version_requirements: !ruby/object:Gem::Requirement
|
108
122
|
requirements:
|
109
|
-
- - "
|
123
|
+
- - ">="
|
110
124
|
- !ruby/object:Gem::Version
|
111
|
-
version: '
|
125
|
+
version: '0'
|
112
126
|
- !ruby/object:Gem::Dependency
|
113
|
-
name:
|
127
|
+
name: standard
|
114
128
|
requirement: !ruby/object:Gem::Requirement
|
115
129
|
requirements:
|
116
130
|
- - ">="
|
@@ -124,7 +138,7 @@ dependencies:
|
|
124
138
|
- !ruby/object:Gem::Version
|
125
139
|
version: '0'
|
126
140
|
- !ruby/object:Gem::Dependency
|
127
|
-
name:
|
141
|
+
name: simplecov
|
128
142
|
requirement: !ruby/object:Gem::Requirement
|
129
143
|
requirements:
|
130
144
|
- - ">="
|
@@ -165,7 +179,7 @@ files:
|
|
165
179
|
- GETTING_STARTED.md
|
166
180
|
- LICENSE
|
167
181
|
- NAME.md
|
168
|
-
- NEWS
|
182
|
+
- NEWS.md
|
169
183
|
- README.md
|
170
184
|
- lib/factory_bot.rb
|
171
185
|
- lib/factory_bot/aliases.rb
|
@@ -173,7 +187,6 @@ files:
|
|
173
187
|
- lib/factory_bot/attribute/association.rb
|
174
188
|
- lib/factory_bot/attribute/dynamic.rb
|
175
189
|
- lib/factory_bot/attribute/sequence.rb
|
176
|
-
- lib/factory_bot/attribute/static.rb
|
177
190
|
- lib/factory_bot/attribute_assigner.rb
|
178
191
|
- lib/factory_bot/attribute_list.rb
|
179
192
|
- lib/factory_bot/callback.rb
|
@@ -183,17 +196,16 @@ files:
|
|
183
196
|
- lib/factory_bot/declaration/association.rb
|
184
197
|
- lib/factory_bot/declaration/dynamic.rb
|
185
198
|
- lib/factory_bot/declaration/implicit.rb
|
186
|
-
- lib/factory_bot/declaration/static.rb
|
187
199
|
- lib/factory_bot/declaration_list.rb
|
188
200
|
- lib/factory_bot/decorator.rb
|
189
201
|
- lib/factory_bot/decorator/attribute_hash.rb
|
190
|
-
- lib/factory_bot/decorator/class_key_hash.rb
|
191
202
|
- lib/factory_bot/decorator/disallows_duplicates_registry.rb
|
192
203
|
- lib/factory_bot/decorator/invocation_tracker.rb
|
193
204
|
- lib/factory_bot/decorator/new_constructor.rb
|
194
205
|
- lib/factory_bot/definition.rb
|
195
206
|
- lib/factory_bot/definition_hierarchy.rb
|
196
207
|
- lib/factory_bot/definition_proxy.rb
|
208
|
+
- lib/factory_bot/enum.rb
|
197
209
|
- lib/factory_bot/errors.rb
|
198
210
|
- lib/factory_bot/evaluation.rb
|
199
211
|
- lib/factory_bot/evaluator.rb
|
@@ -201,6 +213,7 @@ files:
|
|
201
213
|
- lib/factory_bot/factory.rb
|
202
214
|
- lib/factory_bot/factory_runner.rb
|
203
215
|
- lib/factory_bot/find_definitions.rb
|
216
|
+
- lib/factory_bot/internal.rb
|
204
217
|
- lib/factory_bot/linter.rb
|
205
218
|
- lib/factory_bot/null_factory.rb
|
206
219
|
- lib/factory_bot/null_object.rb
|
@@ -224,7 +237,7 @@ homepage: https://github.com/thoughtbot/factory_bot
|
|
224
237
|
licenses:
|
225
238
|
- MIT
|
226
239
|
metadata: {}
|
227
|
-
post_install_message:
|
240
|
+
post_install_message:
|
228
241
|
rdoc_options: []
|
229
242
|
require_paths:
|
230
243
|
- lib
|
@@ -232,16 +245,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
232
245
|
requirements:
|
233
246
|
- - ">="
|
234
247
|
- !ruby/object:Gem::Version
|
235
|
-
version:
|
248
|
+
version: 2.5.0
|
236
249
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
237
250
|
requirements:
|
238
251
|
- - ">="
|
239
252
|
- !ruby/object:Gem::Version
|
240
253
|
version: '0'
|
241
254
|
requirements: []
|
242
|
-
|
243
|
-
|
244
|
-
signing_key:
|
255
|
+
rubygems_version: 3.2.16
|
256
|
+
signing_key:
|
245
257
|
specification_version: 4
|
246
258
|
summary: factory_bot provides a framework and DSL for defining and using model instance
|
247
259
|
factories.
|