FactoryBot and Faker
Configure FactoryBot
Create spec/support/factory_bot.rb
.
mkdir spec/support
touch spec/support/factory_bot.rb
Add the following blurb in that file to configure FactoryBot.
# spec/support/factory_bot.rb
require 'factory_bot'
RSpec.configure do |config|
config.include FactoryBot::Syntax::Methods
end
Add the following to your rails_helper.rb
file...
require 'spec_helper'
# NOTE -- you need to require factory bot AFTER spec_helper
require 'support/factory_bot'
# ...
ENV['RAILS_ENV'] ||= 'test'
Configure Faker
Create spec/support/faker.rb
touch spec/support/faker.rb
Paste in the following contents...
require "faker"
Faker::Config.locale = 'en-US'
Now add require 'support/faker'
to your rails_helper.rb
after the require for FactoryBot.