I used to have the following
require 'factory_girl'
require_relative '../../support/factories/users.rb'
class UserMailerPreview < ActionMailer::Preview
def invitation
user = FactoryGirl.build(:user)
UserMailer.invitation(user)
end
end
and it was working with FactoryGirl 4.8
Now, I have updated to FactoryBot 4.8.2
require 'factory_bot'
require_relative '../../support/factories/users.rb'
class UserMailerPreview < ActionMailer::Preview
def invitation
user = FactoryBot.build(:user)
UserMailer.invitation(user)
end
end
But I get No such file to load -- factory_bot.rb
. What should I require?
Thanks for the help.
You need to include the methods:
require 'factory_bot_rails'
class MyEmailPreview < ActionMailer::Preview
include FactoryBot::Syntax::Methods
def foo
user = create(:user)
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With