动态添加所有引擎的工厂路径
在 support/factory_bot.rb
中,我们添加了所有引擎的工厂路径,如下所示:
require 'factory_bot'
FactoryBot.definition_file_paths.unshift(
MyEngine::One.factory_path,
MyEngine::Two.factory_path,
SomethingElse.factory_path,
)
FactoryBot.find_definitions
if defined? RSpec
RSpec.configure do |config|
config.include FactoryBot::Syntax::Methods
end
end
有没有办法动态添加所有引擎的工厂路径?例如,如果我们要添加新引擎,则不需要对此文件进行任何调整。
In support/factory_bot.rb
we add all the Engine's factory paths like this:
require 'factory_bot'
FactoryBot.definition_file_paths.unshift(
MyEngine::One.factory_path,
MyEngine::Two.factory_path,
SomethingElse.factory_path,
)
FactoryBot.find_definitions
if defined? RSpec
RSpec.configure do |config|
config.include FactoryBot::Syntax::Methods
end
end
Is there a way to dynamically add all my Engine's factory paths in? For example, if we were to add a new engine, we wouldn't need to make any adjustments to this file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我能够使用以下命令动态添加所有工厂路径:
I was able to dynamically add all the factory paths with the following: