factory_bot 4.8.2 → 5.2.0

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.
Files changed (76) hide show
  1. checksums.yaml +5 -5
  2. data/.yardopts +1 -0
  3. data/GETTING_STARTED.md +226 -129
  4. data/LICENSE +1 -1
  5. data/NAME.md +12 -5
  6. data/NEWS.md +351 -0
  7. data/README.md +35 -27
  8. data/lib/factory_bot/aliases.rb +1 -1
  9. data/lib/factory_bot/attribute/dynamic.rb +1 -0
  10. data/lib/factory_bot/attribute.rb +4 -39
  11. data/lib/factory_bot/attribute_assigner.rb +21 -6
  12. data/lib/factory_bot/attribute_list.rb +2 -1
  13. data/lib/factory_bot/callback.rb +3 -2
  14. data/lib/factory_bot/configuration.rb +16 -20
  15. data/lib/factory_bot/declaration/association.rb +14 -1
  16. data/lib/factory_bot/declaration/dynamic.rb +3 -1
  17. data/lib/factory_bot/declaration/implicit.rb +7 -2
  18. data/lib/factory_bot/declaration.rb +4 -4
  19. data/lib/factory_bot/declaration_list.rb +1 -1
  20. data/lib/factory_bot/decorator/attribute_hash.rb +1 -1
  21. data/lib/factory_bot/decorator/invocation_tracker.rb +1 -1
  22. data/lib/factory_bot/decorator.rb +5 -1
  23. data/lib/factory_bot/definition.rb +10 -7
  24. data/lib/factory_bot/definition_hierarchy.rb +1 -11
  25. data/lib/factory_bot/definition_proxy.rb +65 -41
  26. data/lib/factory_bot/errors.rb +7 -4
  27. data/lib/factory_bot/evaluation.rb +1 -1
  28. data/lib/factory_bot/evaluator.rb +5 -5
  29. data/lib/factory_bot/factory.rb +8 -8
  30. data/lib/factory_bot/factory_runner.rb +3 -3
  31. data/lib/factory_bot/find_definitions.rb +1 -1
  32. data/lib/factory_bot/internal.rb +104 -0
  33. data/lib/factory_bot/linter.rb +36 -19
  34. data/lib/factory_bot/null_factory.rb +4 -1
  35. data/lib/factory_bot/null_object.rb +2 -2
  36. data/lib/factory_bot/registry.rb +15 -6
  37. data/lib/factory_bot/reload.rb +3 -3
  38. data/lib/factory_bot/sequence.rb +9 -1
  39. data/lib/factory_bot/strategy/null.rb +2 -4
  40. data/lib/factory_bot/strategy/stub.rb +32 -36
  41. data/lib/factory_bot/strategy_calculator.rb +1 -1
  42. data/lib/factory_bot/strategy_syntax_method_registrar.rb +13 -2
  43. data/lib/factory_bot/syntax/default.rb +12 -24
  44. data/lib/factory_bot/syntax/methods.rb +32 -9
  45. data/lib/factory_bot/syntax.rb +2 -2
  46. data/lib/factory_bot/trait.rb +6 -3
  47. data/lib/factory_bot/version.rb +1 -1
  48. data/lib/factory_bot.rb +103 -134
  49. metadata +79 -64
  50. data/.autotest +0 -9
  51. data/.gitignore +0 -10
  52. data/.rspec +0 -2
  53. data/.simplecov +0 -4
  54. data/.travis.yml +0 -38
  55. data/Appraisals +0 -19
  56. data/Gemfile +0 -8
  57. data/Gemfile.lock +0 -103
  58. data/NEWS +0 -293
  59. data/Rakefile +0 -36
  60. data/cucumber.yml +0 -1
  61. data/factory_bot.gemspec +0 -36
  62. data/factory_girl.gemspec +0 -40
  63. data/gemfiles/3.2.gemfile +0 -10
  64. data/gemfiles/3.2.gemfile.lock +0 -105
  65. data/gemfiles/4.0.gemfile +0 -10
  66. data/gemfiles/4.0.gemfile.lock +0 -105
  67. data/gemfiles/4.1.gemfile +0 -10
  68. data/gemfiles/4.1.gemfile.lock +0 -104
  69. data/gemfiles/4.2.gemfile +0 -10
  70. data/gemfiles/4.2.gemfile.lock +0 -104
  71. data/gemfiles/5.0.gemfile +0 -10
  72. data/gemfiles/5.0.gemfile.lock +0 -103
  73. data/lib/factory_bot/attribute/static.rb +0 -16
  74. data/lib/factory_bot/declaration/static.rb +0 -26
  75. data/lib/factory_bot/decorator/class_key_hash.rb +0 -28
  76. data/lib/factory_girl.rb +0 -5
@@ -1,37 +1,33 @@
1
1
  module FactoryBot
2
2
  # @api private
3
3
  class Configuration
4
- attr_reader :factories, :sequences, :traits, :strategies, :callback_names
5
-
6
- attr_accessor :allow_class_lookup, :use_parent_strategy
4
+ attr_reader(
5
+ :callback_names,
6
+ :factories,
7
+ :inline_sequences,
8
+ :sequences,
9
+ :strategies,
10
+ :traits,
11
+ )
7
12
 
8
13
  def initialize
9
- @factories = Decorator::DisallowsDuplicatesRegistry.new(Registry.new('Factory'))
10
- @sequences = Decorator::DisallowsDuplicatesRegistry.new(Registry.new('Sequence'))
11
- @traits = Decorator::DisallowsDuplicatesRegistry.new(Registry.new('Trait'))
12
- @strategies = Registry.new('Strategy')
14
+ @factories = Decorator::DisallowsDuplicatesRegistry.new(Registry.new("Factory"))
15
+ @sequences = Decorator::DisallowsDuplicatesRegistry.new(Registry.new("Sequence"))
16
+ @traits = Decorator::DisallowsDuplicatesRegistry.new(Registry.new("Trait"))
17
+ @strategies = Registry.new("Strategy")
13
18
  @callback_names = Set.new
14
- @definition = Definition.new
15
-
16
- @allow_class_lookup = true
19
+ @definition = Definition.new(:configuration)
20
+ @inline_sequences = []
17
21
 
18
- to_create { |instance| instance.save! }
22
+ to_create(&:save!)
19
23
  initialize_with { new }
20
24
  end
21
25
 
22
26
  delegate :to_create, :skip_create, :constructor, :before, :after,
23
- :callback, :callbacks, to: :@definition
27
+ :callback, :callbacks, to: :@definition
24
28
 
25
29
  def initialize_with(&block)
26
30
  @definition.define_constructor(&block)
27
31
  end
28
-
29
- def duplicate_attribute_assignment_from_initialize_with
30
- false
31
- end
32
-
33
- def duplicate_attribute_assignment_from_initialize_with=(value)
34
- ActiveSupport::Deprecation.warn 'Assignment of duplicate_attribute_assignment_from_initialize_with is unnecessary as this is now default behavior in FactoryBot 4.0; this line can be removed', caller
35
- end
36
32
  end
37
33
  end
@@ -10,19 +10,32 @@ module FactoryBot
10
10
  end
11
11
 
12
12
  def ==(other)
13
- name == other.name &&
13
+ self.class == other.class &&
14
+ name == other.name &&
14
15
  options == other.options
15
16
  end
16
17
 
17
18
  protected
19
+
18
20
  attr_reader :options
19
21
 
20
22
  private
21
23
 
22
24
  def build
25
+ ensure_factory_is_not_a_declaration!
26
+
23
27
  factory_name = @overrides[:factory] || name
24
28
  [Attribute::Association.new(name, factory_name, [@traits, @overrides.except(:factory)].flatten)]
25
29
  end
30
+
31
+ def ensure_factory_is_not_a_declaration!
32
+ if @overrides[:factory].is_a?(Declaration)
33
+ raise ArgumentError.new(<<~MSG)
34
+ Association '#{name}' received an invalid factory argument.
35
+ Did you mean? 'factory: :#{@overrides[:factory].name}'
36
+ MSG
37
+ end
38
+ end
26
39
  end
27
40
  end
28
41
  end
@@ -8,12 +8,14 @@ module FactoryBot
8
8
  end
9
9
 
10
10
  def ==(other)
11
- name == other.name &&
11
+ self.class == other.class &&
12
+ name == other.name &&
12
13
  ignored == other.ignored &&
13
14
  block == other.block
14
15
  end
15
16
 
16
17
  protected
18
+
17
19
  attr_reader :block
18
20
 
19
21
  private
@@ -8,12 +8,14 @@ module FactoryBot
8
8
  end
9
9
 
10
10
  def ==(other)
11
- name == other.name &&
11
+ self.class == other.class &&
12
+ name == other.name &&
12
13
  factory == other.factory &&
13
14
  ignored == other.ignored
14
15
  end
15
16
 
16
17
  protected
18
+
17
19
  attr_reader :factory
18
20
 
19
21
  private
@@ -21,8 +23,11 @@ module FactoryBot
21
23
  def build
22
24
  if FactoryBot.factories.registered?(name)
23
25
  [Attribute::Association.new(name, name, {})]
24
- elsif FactoryBot.sequences.registered?(name)
26
+ elsif FactoryBot::Internal.sequences.registered?(name)
25
27
  [Attribute::Sequence.new(name, name, @ignored)]
28
+ elsif @factory.name.to_s == name.to_s
29
+ message = "Self-referencing trait '#{@name}'"
30
+ raise TraitDefinitionError, message
26
31
  else
27
32
  @factory.inherit_traits([name])
28
33
  []
@@ -1,7 +1,6 @@
1
- require 'factory_bot/declaration/static'
2
- require 'factory_bot/declaration/dynamic'
3
- require 'factory_bot/declaration/association'
4
- require 'factory_bot/declaration/implicit'
1
+ require "factory_bot/declaration/dynamic"
2
+ require "factory_bot/declaration/association"
3
+ require "factory_bot/declaration/implicit"
5
4
 
6
5
  module FactoryBot
7
6
  # @api private
@@ -18,6 +17,7 @@ module FactoryBot
18
17
  end
19
18
 
20
19
  protected
20
+
21
21
  attr_reader :ignored
22
22
  end
23
23
  end
@@ -39,7 +39,7 @@ module FactoryBot
39
39
  end
40
40
 
41
41
  def to_attributes
42
- @declarations.inject([]) { |result, declaration| result += declaration.to_attributes }
42
+ @declarations.reduce([]) { |result, declaration| result + declaration.to_attributes }
43
43
  end
44
44
 
45
45
  def overridable?
@@ -8,7 +8,7 @@ module FactoryBot
8
8
 
9
9
  def attributes
10
10
  @attributes.each_with_object({}) do |attribute_name, result|
11
- result[attribute_name] = send(attribute_name)
11
+ result[attribute_name] = @component.send(attribute_name)
12
12
  end
13
13
  end
14
14
  end
@@ -6,7 +6,7 @@ module FactoryBot
6
6
  @invoked_methods = []
7
7
  end
8
8
 
9
- def method_missing(name, *args, &block)
9
+ def method_missing(name, *args, &block) # rubocop:disable Style/MissingRespondToMissing
10
10
  @invoked_methods << name
11
11
  super
12
12
  end
@@ -6,10 +6,14 @@ module FactoryBot
6
6
  @component = component
7
7
  end
8
8
 
9
- def method_missing(name, *args, &block)
9
+ def method_missing(name, *args, &block) # rubocop:disable Style/MethodMissingSuper
10
10
  @component.send(name, *args, &block)
11
11
  end
12
12
 
13
+ def respond_to_missing?(name, include_private = false)
14
+ @component.respond_to?(name, true) || super
15
+ end
16
+
13
17
  def send(symbol, *args, &block)
14
18
  __send__(symbol, *args, &block)
15
19
  end
@@ -1,9 +1,10 @@
1
1
  module FactoryBot
2
2
  # @api private
3
3
  class Definition
4
- attr_reader :defined_traits, :declarations
4
+ attr_reader :defined_traits, :declarations, :name
5
5
 
6
- def initialize(name = nil, base_traits = [])
6
+ def initialize(name, base_traits = [])
7
+ @name = name
7
8
  @declarations = DeclarationList.new(name)
8
9
  @callbacks = []
9
10
  @defined_traits = Set.new
@@ -48,7 +49,7 @@ module FactoryBot
48
49
 
49
50
  defined_traits.each do |defined_trait|
50
51
  base_traits.each { |bt| bt.define_trait defined_trait }
51
- additional_traits.each { |bt| bt.define_trait defined_trait }
52
+ additional_traits.each { |at| at.define_trait defined_trait }
52
53
  end
53
54
 
54
55
  @compiled = true
@@ -73,7 +74,7 @@ module FactoryBot
73
74
  end
74
75
 
75
76
  def skip_create
76
- @to_create = ->(instance) { }
77
+ @to_create = ->(instance) {}
77
78
  end
78
79
 
79
80
  def define_trait(trait)
@@ -94,7 +95,7 @@ module FactoryBot
94
95
 
95
96
  def callback(*names, &block)
96
97
  names.each do |name|
97
- FactoryBot.register_callback(name)
98
+ FactoryBot::Internal.register_callback(name)
98
99
  add_callback(Callback.new(name, block))
99
100
  end
100
101
  end
@@ -110,17 +111,19 @@ module FactoryBot
110
111
  end
111
112
 
112
113
  def trait_by_name(name)
113
- trait_for(name) || FactoryBot.trait_by_name(name)
114
+ trait_for(name) || Internal.trait_by_name(name)
114
115
  end
115
116
 
116
117
  def trait_for(name)
117
- defined_traits.detect { |trait| trait.name == name }
118
+ @defined_traits_by_name ||= defined_traits.each_with_object({}) { |t, memo| memo[t.name] ||= t }
119
+ @defined_traits_by_name[name.to_s]
118
120
  end
119
121
 
120
122
  def initialize_copy(source)
121
123
  super
122
124
  @attributes = nil
123
125
  @compiled = false
126
+ @defined_traits_by_name = nil
124
127
  end
125
128
 
126
129
  def aggregate_from_traits_and_self(method_name, &block)
@@ -1,16 +1,6 @@
1
1
  module FactoryBot
2
2
  class DefinitionHierarchy
3
- def callbacks
4
- FactoryBot.callbacks
5
- end
6
-
7
- def constructor
8
- FactoryBot.constructor
9
- end
10
-
11
- def to_create
12
- FactoryBot.to_create
13
- end
3
+ delegate :callbacks, :constructor, :to_create, to: Internal
14
4
 
15
5
  def self.build_from_definition(definition)
16
6
  build_to_create(&definition.to_create)
@@ -1,6 +1,19 @@
1
1
  module FactoryBot
2
2
  class DefinitionProxy
3
- UNPROXIED_METHODS = %w(__send__ __id__ nil? send object_id extend instance_eval initialize block_given? raise caller method)
3
+ UNPROXIED_METHODS = %w(
4
+ __send__
5
+ __id__
6
+ nil?
7
+ send
8
+ object_id
9
+ extend
10
+ instance_eval
11
+ initialize
12
+ block_given?
13
+ raise
14
+ caller
15
+ method
16
+ ).freeze
4
17
 
5
18
  (instance_methods + private_instance_methods).each do |method|
6
19
  undef_method(method) unless UNPROXIED_METHODS.include?(method.to_s)
@@ -21,42 +34,21 @@ module FactoryBot
21
34
  raise FactoryBot::MethodDefinitionError, message
22
35
  end
23
36
 
24
- # Adds an attribute that should be assigned on generated instances for this
25
- # factory.
26
- #
27
- # This method should be called with either a value or block, but not both. If
28
- # called with a block, the attribute will be generated "lazily," whenever an
29
- # instance is generated. Lazy attribute blocks will not be called if that
37
+ # Adds an attribute to the factory.
38
+ # The attribute value will be generated "lazily"
39
+ # by calling the block whenever an instance is generated.
40
+ # The block will not be called if the
30
41
  # attribute is overridden for a specific instance.
31
42
  #
32
- # When defining lazy attributes, an instance of FactoryBot::Strategy will
33
- # be yielded, allowing associations to be built using the correct build
34
- # strategy.
35
- #
36
43
  # Arguments:
37
44
  # * name: +Symbol+ or +String+
38
45
  # The name of this attribute. This will be assigned using "name=" for
39
46
  # generated instances.
40
- # * value: +Object+
41
- # If no block is given, this value will be used for this attribute.
42
- def add_attribute(name, value = nil, &block)
43
- raise AttributeDefinitionError, 'Both value and block given' if value && block_given?
44
-
45
- declaration = if block_given?
46
- Declaration::Dynamic.new(name, @ignore, block)
47
- else
48
- Declaration::Static.new(name, value, @ignore)
49
- end
50
-
47
+ def add_attribute(name, &block)
48
+ declaration = Declaration::Dynamic.new(name, @ignore, block)
51
49
  @definition.declare_attribute(declaration)
52
50
  end
53
51
 
54
- def ignore(&block)
55
- ActiveSupport::Deprecation.warn "`#ignore` is deprecated and will be "\
56
- "removed in 5.0. Please use `#transient` instead."
57
- transient(&block)
58
- end
59
-
60
52
  def transient(&block)
61
53
  proxy = DefinitionProxy.new(@definition, true)
62
54
  proxy.instance_eval(&block)
@@ -66,40 +58,48 @@ module FactoryBot
66
58
  # attribute, so that:
67
59
  #
68
60
  # factory :user do
69
- # name 'Billy Idol'
61
+ # name { 'Billy Idol' }
70
62
  # end
71
63
  #
72
64
  # and:
73
65
  #
74
66
  # factory :user do
75
- # add_attribute :name, 'Billy Idol'
67
+ # add_attribute(:name) { 'Billy Idol' }
76
68
  # end
77
69
  #
78
70
  # are equivalent.
79
71
  #
80
- # If no argument or block is given, factory_bot will look for a sequence
81
- # or association with the same name. This means that:
72
+ # If no argument or block is given, factory_bot will first look for an
73
+ # association, then for a sequence, and finally for a trait with the same
74
+ # name. This means that given an "admin" trait, an "email" sequence, and an
75
+ # "account" factory:
82
76
  #
83
- # factory :user do
84
- # email { create(:email) }
77
+ # factory :user, traits: [:admin] do
78
+ # email { generate(:email) }
85
79
  # association :account
86
80
  # end
87
81
  #
88
82
  # and:
89
83
  #
90
84
  # factory :user do
85
+ # admin
91
86
  # email
92
87
  # account
93
88
  # end
94
89
  #
95
90
  # are equivalent.
96
- def method_missing(name, *args, &block)
97
- if args.empty? && block.nil?
98
- @definition.declare_attribute(Declaration::Implicit.new(name, @definition, @ignore))
99
- elsif args.first.respond_to?(:has_key?) && args.first.has_key?(:factory)
100
- association(name, *args)
91
+ def method_missing(name, *args, &block) # rubocop:disable Style/MissingRespondToMissing, Style/MethodMissingSuper
92
+ association_options = args.first
93
+
94
+ if association_options.nil?
95
+ __declare_attribute__(name, block)
96
+ elsif __valid_association_options?(association_options)
97
+ association(name, association_options)
101
98
  else
102
- add_attribute(name, *args, &block)
99
+ raise NoMethodError.new(<<~MSG)
100
+ undefined method '#{name}' in '#{@definition.name}' factory
101
+ Did you mean? '#{name} { #{association_options.inspect} }'
102
+ MSG
103
103
  end
104
104
  end
105
105
 
@@ -121,6 +121,7 @@ module FactoryBot
121
121
  # Except that no globally available sequence will be defined.
122
122
  def sequence(name, *args, &block)
123
123
  sequence = Sequence.new(name, *args, &block)
124
+ FactoryBot::Internal.register_inline_sequence(sequence)
124
125
  add_attribute(name) { increment_sequence(sequence) }
125
126
  end
126
127
 
@@ -148,7 +149,15 @@ module FactoryBot
148
149
  # name of the factory. For example, a "user" association will by
149
150
  # default use the "user" factory.
150
151
  def association(name, *options)
151
- @definition.declare_attribute(Declaration::Association.new(name, *options))
152
+ if block_given?
153
+ raise AssociationDefinitionError.new(
154
+ "Unexpected block passed to '#{name}' association "\
155
+ "in '#{@definition.name}' factory",
156
+ )
157
+ else
158
+ declaration = Declaration::Association.new(name, *options)
159
+ @definition.declare_attribute(declaration)
160
+ end
152
161
  end
153
162
 
154
163
  def to_create(&block)
@@ -170,5 +179,20 @@ module FactoryBot
170
179
  def initialize_with(&block)
171
180
  @definition.define_constructor(&block)
172
181
  end
182
+
183
+ private
184
+
185
+ def __declare_attribute__(name, block)
186
+ if block.nil?
187
+ declaration = Declaration::Implicit.new(name, @definition, @ignore)
188
+ @definition.declare_attribute(declaration)
189
+ else
190
+ add_attribute(name, &block)
191
+ end
192
+ end
193
+
194
+ def __valid_association_options?(options)
195
+ options.respond_to?(:has_key?) && options.has_key?(:factory)
196
+ end
173
197
  end
174
198
  end
@@ -2,6 +2,9 @@ module FactoryBot
2
2
  # Raised when a factory is defined that attempts to instantiate itself.
3
3
  class AssociationDefinitionError < RuntimeError; end
4
4
 
5
+ # Raised when a trait is defined that references itself.
6
+ class TraitDefinitionError < RuntimeError; end
7
+
5
8
  # Raised when a callback is defined that has an invalid name
6
9
  class InvalidCallbackNameError < RuntimeError; end
7
10
 
@@ -11,12 +14,12 @@ module FactoryBot
11
14
  # Raised when attempting to register a sequence from a dynamic attribute block
12
15
  class SequenceAbuseError < RuntimeError; end
13
16
 
14
- # Raised when defining an invalid attribute:
15
- # * Defining an attribute which has a name ending in "="
16
- # * Defining an attribute with both a static and lazy value
17
- # * Defining an attribute twice in the same factory
17
+ # Raised when defining an attribute twice in the same factory
18
18
  class AttributeDefinitionError < RuntimeError; end
19
19
 
20
+ # Raised when attempting to pass a block to an association definition
21
+ class AssociationDefinitionError < RuntimeError; end
22
+
20
23
  # Raised when a method is defined in a factory or trait with arguments
21
24
  class MethodDefinitionError < RuntimeError; end
22
25
 
@@ -1,4 +1,4 @@
1
- require 'observer'
1
+ require "observer"
2
2
 
3
3
  module FactoryBot
4
4
  class Evaluation
@@ -1,5 +1,5 @@
1
- require 'active_support/core_ext/hash/except'
2
- require 'active_support/core_ext/class/attribute'
1
+ require "active_support/core_ext/hash/except"
2
+ require "active_support/core_ext/class/attribute"
3
3
 
4
4
  module FactoryBot
5
5
  # @api private
@@ -37,7 +37,7 @@ module FactoryBot
37
37
  @instance = object_instance
38
38
  end
39
39
 
40
- def method_missing(method_name, *args, &block)
40
+ def method_missing(method_name, *args, &block) # rubocop:disable Style/MethodMissingSuper
41
41
  if @instance.respond_to?(method_name)
42
42
  @instance.send(method_name, *args, &block)
43
43
  else
@@ -45,7 +45,7 @@ module FactoryBot
45
45
  end
46
46
  end
47
47
 
48
- def respond_to_missing?(method_name, include_private = false)
48
+ def respond_to_missing?(method_name, _include_private = false)
49
49
  @instance.respond_to?(method_name) || SyntaxRunner.new.respond_to?(method_name)
50
50
  end
51
51
 
@@ -66,7 +66,7 @@ module FactoryBot
66
66
  end
67
67
 
68
68
  def self.define_attribute(name, &block)
69
- if method_defined?(name) || private_method_defined?(name)
69
+ if instance_methods(false).include?(name) || private_instance_methods(false).include?(name)
70
70
  undef_method(name)
71
71
  end
72
72
 
@@ -1,5 +1,5 @@
1
- require 'active_support/core_ext/hash/keys'
2
- require 'active_support/inflector'
1
+ require "active_support/core_ext/hash/keys"
2
+ require "active_support/inflector"
3
3
 
4
4
  module FactoryBot
5
5
  # @api private
@@ -21,10 +21,10 @@ module FactoryBot
21
21
 
22
22
  def build_class
23
23
  @build_class ||= if class_name.is_a? Class
24
- class_name
25
- else
26
- class_name.to_s.camelize.constantize
27
- end
24
+ class_name
25
+ else
26
+ class_name.to_s.camelize.constantize
27
+ end
28
28
  end
29
29
 
30
30
  def run(build_strategy, overrides, &block)
@@ -91,7 +91,7 @@ module FactoryBot
91
91
  end
92
92
 
93
93
  def with_traits(traits)
94
- self.clone.tap do |factory_with_traits|
94
+ clone.tap do |factory_with_traits|
95
95
  factory_with_traits.append_traits traits
96
96
  end
97
97
  end
@@ -145,7 +145,7 @@ module FactoryBot
145
145
 
146
146
  def parent
147
147
  if @parent
148
- FactoryBot.factory_by_name(@parent)
148
+ FactoryBot::Internal.factory_by_name(@parent)
149
149
  else
150
150
  NullFactory.new
151
151
  end
@@ -9,7 +9,7 @@ module FactoryBot
9
9
  end
10
10
 
11
11
  def run(runner_strategy = @strategy, &block)
12
- factory = FactoryBot.factory_by_name(@name)
12
+ factory = FactoryBot::Internal.factory_by_name(@name)
13
13
 
14
14
  factory.compile
15
15
 
@@ -22,10 +22,10 @@ module FactoryBot
22
22
  strategy: runner_strategy,
23
23
  traits: @traits,
24
24
  overrides: @overrides,
25
- factory: factory
25
+ factory: factory,
26
26
  }
27
27
 
28
- ActiveSupport::Notifications.instrument('factory_bot.run_factory', instrumentation_payload) do
28
+ ActiveSupport::Notifications.instrument("factory_bot.run_factory", instrumentation_payload) do
29
29
  factory.run(runner_strategy, @overrides, &block)
30
30
  end
31
31
  end
@@ -16,7 +16,7 @@ module FactoryBot
16
16
  load("#{path}.rb") if File.exist?("#{path}.rb")
17
17
 
18
18
  if File.directory? path
19
- Dir[File.join(path, '**', '*.rb')].sort.each do |file|
19
+ Dir[File.join(path, "**", "*.rb")].sort.each do |file|
20
20
  load file
21
21
  end
22
22
  end