factory_bot

Getting Started guide

FactoryBot.define do
  factory :post do
    user # association
    sequence(:title) { |n| "Title #{n}" }
    last_name { "Doe" }
    admin { false }
  end
end

FactoryBot.create(:model, …overrides) # persisted
FactoryBot.build(:model, …overrides) # not persisted