Setup Factory Bot in Rails
11 March 2022 (Updated 23 April 2022)
On this page
Install gem
Add to Gemfile:
group :development, :test do
gem 'factory_bot_rails'
end
Run:
./bin/bundle install
Configure with RSpec
Create spec/support/factory_bot.rb
:
# frozen_string_literal: true
RSpec.configure do |config|
config.include FactoryBot::Syntax::Methods
end
Make sure this file is included from your rails_helper.rb
or spec_helper.rb
.
Sources
Tagged:
Rails testing
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment