In 2.11.4, attempting to modify a factory defined in the spec/factories/ directory of an application ends up failing with a Factory not registered error. This same factory worked just fine in 2.11.3, but fails in 2.11.4.
For context, here's an example of one of our factories which extends a built in Solidus factory:
# file: spec/factories/option_types.rb
# frozen_string_literal: true
require 'spree/testing_support/factories'
FactoryBot.modify do
factory :option_type do
description { 'Testing testing testing' }
end
end
Solidus Version:
2.11.4
To Reproduce
- Author a factory that modifies a built-in factory as described above.
- Run any spec of your application.
Current behavior
Fails to run with Factory not registered error.
Expected behavior
Specs should run and find the modified factories.
Context
It looks like the problem is this line here: https://github.com/solidusio/solidus/blob/master/core/lib/spree/testing_support.rb#L36
Assuming I'm understanding the behavior of the FactoryBot railtie correctly, I believe this puts "spec/factories/_factory.rb" into the FactoryBot.definition_file_paths list first, which means it attempts to load these factories before it loads the default Spree factories.
It seems like this may be fixable either by reordering the traversal of the file definitions for FactoryBot, or perhaps by documenting a better naming convention/location for overrides of Solidus default factories.
In 2.11.4, attempting to modify a factory defined in the
spec/factories/directory of an application ends up failing with aFactory not registerederror. This same factory worked just fine in 2.11.3, but fails in 2.11.4.For context, here's an example of one of our factories which extends a built in Solidus factory:
Solidus Version:
2.11.4
To Reproduce
Current behavior
Fails to run with
Factory not registerederror.Expected behavior
Specs should run and find the modified factories.
Context
It looks like the problem is this line here: https://github.com/solidusio/solidus/blob/master/core/lib/spree/testing_support.rb#L36
Assuming I'm understanding the behavior of the FactoryBot railtie correctly, I believe this puts "spec/factories/_factory.rb" into the
FactoryBot.definition_file_pathslist first, which means it attempts to load these factories before it loads the default Spree factories.It seems like this may be fixable either by reordering the traversal of the file definitions for FactoryBot, or perhaps by documenting a better naming convention/location for overrides of Solidus default factories.