Aptana RadRails and the test_helper.rb LoadError
Since moving to more recent versions of Rails, I’ve noticed that the auto-generated Rails tests assume that the myapp/test directory is on the load path. And the bundled Rake testing tasks do indeed take care of that requirement. But the Aptana RadRails plugins for Eclipse don’t. The result is that whenever you run a test, either with the test buttons or the Run As | Test::UnitTest context menu, you get something like the following:
./test/unit/user_test.rb:1:in `require': no such file to load -- test_helper (LoadError)
There is an open issue on the Aptana issue tracker, but it doesn’t seem to be resolved yet. Some people have suggested prefixing your requires with the test directory when requiring the test_helper file at the start of your test files -but I don’t think that’s a good solution, especially if you’re working with multiple developers. Frustrated by not getting my daily green bar fix, I found this work-around:
- From the Eclipse Preferences option, choose Ruby | Installed Interpreters
- Select your interpreter (I use the Standard VM default interpreter named usr) and choose ‘Edit’.
- Add -Itest to the Default VM Arguments option. Don’t forget the leading dash!
- Click ‘OK’.
You should now be able to run your tests without having to edit each one to include the test directory. The downside is that you now have an ‘extra’ directory in your load path which will give you a (tiny) performance hit to all your ruby ops -not just tests. Conceivably this could also introduce an incompatibility if you have some conflicting stuff in the test directory -extremely unlikely if you only have test_helper.rb in there.
Tested against Edge Rails (d37e6413366c9a3fafa02c4298a2946dc8327a42), Aptana RadRails 1.0.3.200807071913NGT, Ruby 1.8.6 patchlevel 114 running under Darwin 9.4.0