I am setting up request specs following this tutorial . If I run the tests with bundle exec rspec
I get the following error:
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
The tutorial only asks to add some configuration to the rails_helper.rb file. I can't figure where I need to add a require 'factory_bot'
. If I add it to the top of the rails_helper.rb file, the error persists. And if I add it to the factories/entity_spec.rb file, I get this error:
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
只需将我的factories/*.rb
文件从例如factories/user_spec.rb
重命名为factories/user.rb
解决此问题。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.