After years of using Eclipse as my Java IDE of choice, it was easy for me to switch over to RadRails/Aptana when I started working in Ruby on Rails. Despite these inclinations, when I heard that NetBeans had Rspec support and a few other niceties, I couldn’t resist checking it out.
Although all of the necessary pieces for getting started with Rails in NetBeans and Rspec/Autotest support are have already been documented in bits and pieces, I thought it’d be useful to lay out a guide for setting this up from scratch. Since IDEs tend to have graphic interfaces, we’ll rely heavily on screenshots.
Prerequisites
Before starting, I’ll assume you have the following installed and working:
Download and install NetBeans 6.0 Beta 2 or newer
At the time of writing, the latest beta release of NetBeans 6.0 can be obtained here. The installation should be straightforward, assuming you have a recent JDK installed.

With installation complete, launch NetBeans. Here’s the default interface layout. Nothing to groundbreaking, with the editing pane surrounded by navigation on the left, and output on the bottom.

Now we’ll need some gems, which we may as well install through NetBeans. Go to the Tools -> Ruby Gems menu option.

Go to the New Gem tab. We’ll need rails, ZenTest, ruby-debug-ide and sqlite3-ruby (plus all their dependencies). Select these and Install.

Be sure to include dependencies, and in this case we can just use that latest rails (1.2.5 at the moment).

If all goes well, you should see something like this. Repeat the process for the remaining gems you’ll need (ZenTest, ruby-debug-ide, sqlite3-ruby)

Now to actually create a project. Go to the File -> New Project… menu option.

Choose Ruby on Rails Application, and hit Next

We’ll draw on the original Tutorial in Ruby on Rails for inspiration, hence ‘MyProject’ as a title, but name the project whatever you want. Use sqlite3 as the database unless you have another preference. Make sure the ruby interpreter you want to use is selected. Next.

The last screen in the new project wizard should show that Rails is already installed, if the Ruby Gems steps above worked correctly. Finish.

NetBeans has created the skeleton of our Rails app, which can be explored through the navigation pane on the left. It pops open the database.yml so that your database configuration can be defined. No changes are needed if you’re using sqlite2 or sqlite3.

Now we need to install the necessary plugins so that we can use Rspec. In the navigation pane on the left, right-click on the project name and choose Rails Plugins…

We need to add the repository for Rspec. Go to the Repositories tab, and choose to Add URL…

Enter the URL for the Rspec Subversion repository:svn://rubyforge.org/var/svn/rspec/tags/CURRENT. Hit OK.

Now go to the New Plugins tab, and select both rspec and rspec_on_rails. Choose Install.

You have the option of installing the plugins as svn:externals or as an svn checkout. I tend to skip the elegant svn options so that I have the files in my own subversion repository, rather than relying on someone else’s indefinitely being around. Hit OK.

Now the plugins have been installed, so we can make use of Rspec in our project. Close.

Next, we have to generate some files in our project for Rspec. Right click on the project name in the left-hand navigation pane, and click Generate…

Choose rspec and hit OK. Now we’re all set to use Rspec.

Now to generate a controller and it’s spec. Right-click on the project name, and pick Generate…

Using the rspec_controller will provide us with a controller as well as the necessary spec files. By entering ‘hello index’, we’ll produce a controller named hello with one method called index. Hit OK.

In the navigation pane on the left, there will now be some files under Rspec.

Open up hello_controller_spec.r. To run the spec, either choose Run->Run File->Run “hello_controller_spec.rb”, or use the keyboard shortcut Shift-F6.

The output window at the bottom will display the output of running the spec, plus in the editor pane you’ll get a summary that’s either colored green if your spec had no failures, or red if there were failures.

We can take Rspec a step further if we like, and get Autotest running (assuming you installed the ZenTest gem). Just right-click on the project name in the left-hand navigation pane, and choose Autotest. This will start an initial run through all your specs, and then re-run every time a file is saved.

Now we’ll add a trivial spec for our ‘hello’ controller, saying that there should be a ‘message’ assign that says “Hello World”. If we then save our spec, autotest kicks in and says we now have a failure.

Another nice feature of NetBeans is that you can quickly switch between a spec and the controller/model/view that’s being spec’d, using the keyboard shortcut Control-shift-T. Do this to switch to the ‘hello’ controller itself. Add a line so that @message is set to “Hello World”. Save the controller file, and autotest kicks in again, saying that our tests pass!
So that’s all there is to getting going with Ruby on Rails in NetBeans, with added bonuses of Rspec and Autotest. Enjoy!