Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I run tests on RoR faster?

I'm using Ruby on Rails 3 and writing tests but it's too slow. Is there some good configure or tools to make that faster?

like image 772
yaotti Avatar asked Jul 05 '11 13:07

yaotti


1 Answers

Probably the biggest speed gain comes from being careful not to hit the database unless you need to. Mock objects rather than fetch them from the database, and/or (if you are using factory girl for example) use Factory.build(:stuff) instead of Factory(:stuff) wherever possible. Only when you have done that should you start trying to optimise further with spork

Update: Personally, I'm also starting to think that you should not become to hung up about the speed of your tests anyway. Faster is obviously better, but as an application grows, the test suite will grow, and however careful you are it will eventually become slower than you would like. I'm coming to rely more and more on the autotest gem which tests changing code and works in the background (guard-rspec does a similar job). By the time your app reaches 1000 tests you will not want to wait for the whole suite to finish every time you make a change, however fast the tests run.

like image 148
chrispanda Avatar answered Oct 01 '22 17:10

chrispanda