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!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With