我正在根据this tutorial设置请求规范。
如果使用bundle exec rspec
运行测试,则会出现以下错误:
An error occurred while loading ./spec/factories/entities_spec.rb.
Failure/Error:
FactoryBot.define do
factory :entity do
name { FFaker::Lorem.word }
end
end
NameError:
uninitialized constant FactoryBot
本教程仅要求向rails_helper.rb文件添加一些配置。我不知道需要在哪里添加require 'factory_bot'
。如果将其添加到rails_helper.rb文件的顶部,该错误仍然存在。如果我将其添加到factory / entity_spec.rb文件,则会收到此错误:
An error occurred while loading ./spec/requests/entities_spec.rb.
Failure/Error:
factory :entity do
name { FFaker::Lorem.word }
end
FactoryBot::DuplicateDefinitionError:
Factory already registered: entity
答案 0 :(得分:0)
只需重命名我的factories/*.rb
文件即可,例如factories/user_spec.rb
至factories/user.rb
解决了该问题。