FactoryBot: create the same object multiple times

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)

see Getting Started


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.


If you need to do this for a model with validation, I was able to do the following in my test.

10.times do |i|
  create(
    :object,
    property: i
  )
end

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