FactoryBot: create the same object multiple times FactoryBot: create the same object multiple times ruby-on-rails ruby-on-rails

FactoryBot: create the same object multiple times


You can create a list like this (hence create x objects at once):

FactoryBot.create_list(:model_1, 3)

Documentation lives here.

Note: FactoryBot was originally named FactoryGirl


FactoryBot.create_list :factory_name, 2, attribute_name: 'value'

Simple and best way to move.

You can ignore the attribute names if not needed the same, and use sequence instead.


Not sure if this has been updated since the answer was posted, but now you would do the following

FactoryBot.create_list(:model_1, 3)

seeGetting Started