Flo Rahl
Flo Rahl

Reputation: 1054

Difference between FactoryGirl.create and create

Can you explain to me what is the difference to write in my tests :

FactoryGirl.create(:user, name: "boris", email: "[email protected]")

and

User.create(name: "boris", email: "[email protected]")

Upvotes: 2

Views: 257

Answers (1)

a.s.t.r.o
a.s.t.r.o

Reputation: 3338

FactoryGirl allows you to have some default (that can be overridden) values for User in the factory or even generate values using Faker or similar.

That being said, for fast tests in most cases you can use FactoryGirl.build_stubbed (or FactoryGirl.build) which doesn't save user in database.

More info: https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md

Upvotes: 4

Related Questions