Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Factory Girl vs. User.create -- what's the difference?

This is an additional note to the question "Factory Girl - what's the purpose?"

I'm not sure whether my question is counted as a repetitive one, but I'm simply still not very clear after reading that post, since I think my doubt is still different.

Alright, so now that we can always use User.create() in before(:each) block in a Rspec test, why do we still bother using Factory Girl then?

This whole confuse occurred to me when I'm reading Michael Hartl's "Rails 3 tutorial", when he suddenly jumped into Factory Girl but used User.create() to build a User instance all the way through before that.

I wish someone can clarify this point for me, thx a lot!

like image 904
adam_0628 Avatar asked Oct 01 '11 08:10

adam_0628


1 Answers

You are correct but gems like factory girl and fabrication allow for significantly less code duplication across clases and within different tests when you need to test large sets of data that require different attribute values due to uniqueness requirements. It mixes in methods to easily "manufacture" many different objects for these types of tests.

like image 118
dbkbali Avatar answered Sep 20 '22 09:09

dbkbali