Saturday, December 22, 2007

AutoTest with InstantRails on Windows

Testing you app is important. A useful and recommended plugin is the autotest plugin. Here's what is says in the box:

  • Improves feedback by running tests continuously.
  • Continually runs tests based on files you've changed.
  • Get feedback as soon as you save. Keeps you in your editor allowing you to get stuff done faster.
  • Focuses on running previous failures until you've fixed them.
Cool. To get it type:
>>gem install ZenTest
to run cd into your app dir and type:
>>autotest -rails
Simple, isn't it?

Well... not really.
When I did this I got a whole bunch of error messages:
.../InstantRails/ruby/lib/ruby/gems/1.8/gems/ZenTest-3.6.1/lib/autotest.rb:435:in `expand_path': couldn't find HOME environment -- expanding `~/.autotest' (ArgumentError)
from .../InstantRails/ruby/lib/ruby/gems/1.8/gems/ZenTest-3.6.1/lib/autotest.rb:435
from .../InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
from .../InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
from .../InstantRails/ruby/lib/ruby/gems/1.8/gems/ZenTest-3.6.1/bin/autotest:35
from .../InstantRails/ruby/bin/autotest:19:in `load'
from .../InstantRails/ruby/bin/autotest:19
Turns out that it's looking for an environment variable called HOME. From my tests and from what I read you can put any valid path there. I just used the local path.
Actually, I just set the variable before running autotest.
>>set HOME=.
>>autotest -rails
However, a fresh new list of errors are now generated, the gist of them is this:
.../InstantRails/ruby/lib/ruby/gems/1.8/gems/ZenTest-3.6.1/lib/unit_diff.rb:187:in ''': No such file or directory - diff.exe -u D:/temp/expect.1480.0 D:/temp/butwas.1480.0n (Errno::ENOENT)
1. from .../InstantRails/ruby/lib/ruby/gems/1.8/gems/ZenTest-3.6.1/lib/unit_diff.rb:187:in 'unit_diff'
Basically, it's complaining that it cannot find diff.exe. Of course, most (all?) Unix systems have this installed but my Windows machine with InstantRails does not, so therein lies the problem. This post explains it simply. Go here to get diff.exe for Windows.

Once installed (or unzipped), just set your path to wherever you put it, and run autotest. e.g.:
>>set HOME=.
>>set path=%path%;"C:\Program Files\GnuWin32\bin\"
>>autotest -rails
Right? Wrong.
diff.exe is still not found. For some reason it's not enough to set the environment like this.

You will need to set it in the Windows settings (Start-> Settings-> Control Panel-> System-> Advanced-> Environment Variables...) and change the PATH variable to include the diff.exe path.

Now you can begin enjoying the joys of autotest.

If you found this post helpful, please leave a message in the comments. If you want to hear more about my adventures on the Rails, subscribe to the blog feed and you won't miss a thing.


Toons said...

Thanks for this. I've just switched from Eclipse to Netbeans, so autotest had to be set up again. The hassle I had setting it up in the first place. So to clarify you need to do these steps to get Netbeans autotest to work.

DEfusion said...

I followed your instructions but still had trouble getting it to find diff.exe. The path is set ok as I can call diff.exe from anywhere using command prompt.

The only way I got it to work was to edit the zentest source (not a good idea) to include the full path to diff.exe.

Is there something else I'm missing?

A.S. said...

I'm a rookie myself struggling with this. I just did what worked.
DEfusion, I suggest you post a question on ZenTest's site.

DEfusion said...

Thanks for the update, after I got this working I really started to notice how slow Ruby is on Windows (it was taking ages for autotest to start running the tests, but the tests run quickly).

So I moved my setup to use andLinux and now it's instantaneous and I didn't need to jump through any hoops to get stuff working.

TopDawg said...

Thanks for posting this, it was a great help getting my environment setup. Can't wait to move to a Mac!

Bruno said...

greate tips. Saved my day

Norbert Toth-Gati said...

Thanks for the post. It did really help me of debugging and wasting much time.

A.S. said...

NTG: You're most welcome.