When including the factory_bot_rails gem in your dev and test blocks in Gemfile, rails will generate factories automatically when your models are generated.
Is there a way to generate factories after your models have been generated?
Note: FactoryBot was previously named FactoryGirl
Best Answer
First thing, look at the source project to find out how it was implemented:
https://github.com/thoughtbot/factory_bot_rails/blob/master/lib/generators/factory_bot/model/model_generator.rb
After that, try to guess how it works:
The result is:
And the content:
Remember, when you use rails g, you can always undo it, with rails d
Note: FactoryBot was previously named FactoryGirl