我已经浏览过这些页面并尝试了在这些页面上找到的许多内容:
FactoryGirl: Factory not registered: user (ArgumentError) Cannot get factory_girl running under rails 3.0.5,unexpected tCONSTANT 'Factory not registered' error in Rails 4 FactoryGirl: Factory not registered
但继续“工厂未注册:用户”
文件test / factories.rb(也试过test / factories / user_factory.rb)看起来像:
FactoryGirl.define do
factory :user do
login 'mbrown@yahoo.com'
email 'mbrown@yahoo.com'
end
end
Stub for test:
it 'just_a_test_of_testing' do
u = FactoryGirl.create(:user)
end
不起作用,给我“ArgumentError:Factory not registered:user”
有谁知道“正确的解决方案”?它似乎与“引擎”有关,但我只是不知道下一步该尝试什么,有什么想法吗?也许这与User是测试/虚拟应用程序的模型这一事实有关?
答案 0 :(得分:0)
您是否在{/ 3}}建议的spec / support / factory_girl.rb文件中配置了定义路径?
FactoryGirl.definition_file_paths = %w(custom_factories_directory)
FactoryGirl.find_definitions
答案 1 :(得分:0)
一位同事开始了,他的班级看起来像
Module MyEngineMod
FactoryGirl.define do
factory :user, class: User do
# content not shown
end
end
end
所以它似乎至少需要名称间隔,并且可能也需要class:属性。