Search code examples
ruby-on-railsfactory-bot

Does factory girl call the model?


If I just need a basic model is there any difference in creating a model directly vs creating a model with factory girl?

I.E.

User.new(..all the correct params)

vs

Factory.create :user

My ultimate question is:

When testing controller does creating a model directly make the test less reliable?


Solution

  • There is no big difference. You can create a new object directly. However factory girl can deal with associations and you usually put there some default data so it is just easier for you.

    It is also easier to re-use the code. Otherwise whenever you create user you have to set these params.

    That is why it is kind of good practise to use factory-girl