1

I'm looking for the quickest way to run unit tests for a rails app on a Windows machine, preferably automatically. My environment is:

  • Ruby 1.8.7
  • Rails 3.0.9
  • ZenTest 3.6.0 (the latest versions 4.6.2/4.5.0 failed when I tried them for some reason)

Currently they run very slowly, eg. 30s to run a suite of 12 very simple unit tests, time mostly spent starting ruby it seems. The tests themselves take 5s to run according to autotest. For someone used to running 100s of tests in 10s, this is agony, and makes TDD infeasible. I'd even be happy if I could re-run one unit test in less than 5s...

I've searched other questions. Some are old and some conflict. What's the latest accepted wisdom on this? Here are the suggestions I'm aware of:

  • Use faster_require and/or faster_gem_script (though I had problems getting this working...)
  • Try JRuby (though that seems as slow starting?)
  • Upgrade ruby to 1.9.x
  • spork?
  • doze?
  • rails-dev-boost?

Getting a Linux box (or VMware) is out of the question at present, though getting more tempting...

Graeme Moss
  • 7,995
  • 4
  • 29
  • 42

2 Answers2

1

You may want to look at something like spork (and a blog entry).

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
  • I tried once to run spork under Windows (and Ruby 1.9.2 and Rails 3.0.x) and did not succeed. I think the that forking a process will not work in windows and Ruby 1.8.7. – mliebelt Sep 13 '11 at 05:39
  • No, under Windows 7. Reason for that is, that I am working 100% under Windows 7, and do not want to use Ruby (only) then under Cygwin. Do you think that should work then? Perhaps I should give it a try. – mliebelt Sep 13 '11 at 12:57
  • I'd *think* it'd work, but haven't done it myself. IMO doing Rails dev work under Windows is pretty painful; I'd really recommend using a VM if you're dead-set on running Windows. I mean, presumably you're not deploying under Windows. – Dave Newton Sep 13 '11 at 13:02
  • ... which I do, I use the 2 Rails apps every day 100s of times :-( – mliebelt Sep 13 '11 at 14:13
  • So far, spork is definitely a winner. Assuming I do not run the tests more often than once every minute, the time from file edit to finishing a run of 6 unit tests has gone from 50s to 8s. Much better! I used the following [guide](http://blog.agoragames.com/blog/2011/04/29/speed-up-testing-with-spork/) to install spork, but note: I had to manually install the gem win32-process, "spork --bootstrap" has two "-" characters, and I could not use bundle but installed via "gem install spork" etc. (probably a local issue). – Graeme Moss Sep 13 '11 at 19:27
  • Hoops through which to jump :D – Dave Newton Sep 13 '11 at 19:38
0

I write my tests using rspec and I have had great success making my tests run much faster with spork. The reasons tests rails tests run so slowly is because of the amount of time it takes to load rails and all the other gems that you use in your app.

If you can also upgrade to ruby 1.9.2 that would be quite useful.

Moiz Raja
  • 5,612
  • 6
  • 40
  • 52