Is there a configuration parameter for global installation: default_strategy: build Factory_girl for all factories?

I know that you can override the default strategy for creating a Factory object as follows:

Factory.define :person, :default_strategy => :build do # stuff end Factory.define :person, :default_strategy => :create do # stuff end # same behavior as the previous factory Factory.define :person do # stuff end 

but I am wondering if I can add the parameter to the factory_girl configuration file or maybe to the /environments/test.rb file /environments/test.rb that

 Factory.define :person do # stuff end 

creates a default Person object and does not create it by default.

+4
source share
2 answers

From source:

 module FactoryGirl class Factory # ... def default_strategy #:nodoc: @options[:default_strategy] || :create end # ... end end 

The default strategy is equal to the strategy, which is passed as an option for determination, otherwise :create . It seems that it is impossible to establish a strategy for all plants unless you are monkey-patch FactoryGirl::Factory#default_strategy .

0
source

FactoryGirl.use_parent_strategy

Learn more about https://github.com/thoughtbot/factory_girl/pull/961 .

0
source

All Articles