Closed carols10cents closed 11 years ago
I think you can use Fabricate.build
or something to not save to the db.
Yes: http://www.fabricationgem.org/#!fabricating-objects
Fabricate.build(:person)
I'm pretty certain that the only way you can speed up the tests is to detect if they are cpu bound and stub, or io bound and not persist things to the slowest piece of hardware imaginable. :)
It's a wonder why databases make it so hard to go, "hey, you insufferable piece of junk. just wave your hands in the air and rest things in memory and then just forget they are there immediately afterward. thanks.' but that's generally what should happen and that should actually be quite quicker than what it might naively do.
I'd have to agree that just using the .build functionality should produce similar results. And that's a bit better than just giving up on using Fabricators (which honestly should just do the same thing) and that way we don't have places-where-we-use-it and places-where-we-dont.
.build also builds associations that are not necessary in most cases.
Also, some of the tests were taking advantage of some of the default values set in the fabricators that isn't particularly clear-- example
It doesn't make that much of a difference speed-wise though, so I'm happy to close this without merging :)
This follows the recommendation in the first fastrailstests.com newsletter i've gotten that we should avoid fabricating objects whenever possible. Especially avoiding saving objects to the database, but also avoid building associated objects that aren't needed for the test.
I also took this opportunity to minimize the number of fabricated objects in some of the tests.
Before this change:
After this change:
Soooo... meh, not that big a difference, but I think these improvements are good regardless.