hotsh / rstat.us

Simple microblogging network based on the ostatus protocol.
http://rstat.us/
Other
722 stars 215 forks source link

Faster tests #727

Closed carols10cents closed 11 years ago

carols10cents commented 11 years ago

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:

$ time rake test:models
real    1m41.507s

$ time rake test:decorators
real    0m27.177s

After this change:

$ time rake test:models
real    1m34.589s

$ time rake test:decorators
real    0m29.138s

Soooo... meh, not that big a difference, but I think these improvements are good regardless.

steveklabnik commented 11 years ago

I think you can use Fabricate.build or something to not save to the db.

steveklabnik commented 11 years ago

Yes: http://www.fabricationgem.org/#!fabricating-objects

Fabricate.build(:person)
wilkie commented 11 years ago

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.

wilkie commented 11 years ago

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.

carols10cents commented 11 years ago

.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 :)