15 July 2008

Hack to make Autotest + RSpec >=1.1.4 work in Netbeans

If you live on the edge (Netbeans Edge + Rails 2.1.0 + RSpec edge 1.1.4 + ZenTest 3.10.0) at the time of this writing - july 2008 - you'll have to hack autotest to be able to keep working with your favourite editor :-)

Indeed, when I upgradded to the latest stable versions, the wonderful "Auto test" feature in Netbeans stopped to work. It took me 45 minutes to find out what was happenning and to find a solution, hem hack.

As it says in the History file, there is now a command called "autospec" for running specs since RSpec 1.1.4. As Netbeans run the system command "/usr/bin/autotest", it won't discover any specs in your project

A quick hack to make it work, Add the following to /usr/bin/autotest:
ENV['RSPEC'] = 'true'
which will tell autotest we are actually using specs. The sad truth is I don't understand why it works, I need to dig in the code of the rspec-rails plugin I guess ... Enough time wasted!

I am not sure this change in will make RSpec users life easier ... Anyway, that's the way it is!

For netbeans developpers, it will be quite tricky to make it work with different versions of RSpec. I guess they'll have to test what version of RSpec is installed and use autospec for RSpec >= 1.1.4 ...

My /usr/bin/autotest file:

#!/usr/bin/ruby1.8 -ws
# This file was generated by RubyGems.
# The application 'ZenTest' is installed as part of a gem, and
# this file is here to facilitate running it.

require 'rubygems'

version = ">= 0"

if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
version = $1

ENV['RSPEC'] = 'true'
gem 'ZenTest', version
load 'autotest'

1 comment:

branajam said...

My name is James Branam and I'm the NetBeans Community Docs Manager. Your blog entry would make a fantastic Tips & Tricks entry for our Community Docs wiki (http://wiki.netbeans.org//CommunityDocs). Would you be willing to contribute it? If you need any help or have any questions, please contact me at james.branam@sun.com. I look forward to hearing from you.