Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Persisting to the database takes far longer than initializing objects in memory, and
while we’re talking fractions of a second, each of these round trips to the database
adds up when running your entire suite.
When you initialize new objects, try to do so with the least overhead. Depending
on what you need, you should choose your initialization method in this order:
Object.new - initializes the object without FactoryGirl. Use this when you
don’t care about any validations or default values.
FactoryGirl.build_stubbed(:object)-initializestheobjectwithFactoryGirl,
setting up default values and associates records using the build_stubbed
method. Nothing is persisted to the database.
FactoryGirl.build(:object) - initializes the object with FactoryGirl, setting
up default values and persisting associated records with create.
FactoryGirl.create(:object) - initializes and persists the object with Fac-
toryGirl, setting up default values and persisting associated records with
create.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment