The built-in testing framework in Ruby, Test::Unit, is supported directly. You can create new unit tests from the New menu. You run your unit tests by just invoking Run File (Shift-F6) on files. This opens an output window with the output from executing the unit tests. The output is hyperlinked, and you can navigate it using Next Error (F12).
The editor context menu has a "Goto Test" action which lets you jump quickly between a class and its corresponding test cases. This action is aware of Rails conventions, RSpec conventions, ZenTest conventions and obviously Test::Unit conventions. It is bound to Ctrl-Shift-T on the Mac; check your context menu to see the keybinding on your system.
RSpec is a framework that provides you a domain specific language for specifying the behavior of your Ruby code in your Ruby and Rails applications. It can help serve as verification, running tests, as well as documentation for what you have written in your application. You may find additional information at Rspec.info .
If you install the "Rspec" Ruby Gem (use Tools | Ruby Gems), your Rails projects will contain a spec directory which can contain specification files. If you open one of these (you can use the Goto Test action described above), you can run the specs by using Run File (Shift F6). This will run the current spec file under rspec. It will obey the file spec/spec.opts, but if you want to use a separate set of options when running under the IDE (for example, turning off the red/green colorization flags which don't work well under the IDE), create a file named spec/spec.opts.netbeans instead.
As with the AutoTest support, this support is preliminary. Look for Spec file templates etc. soon.
There is an additional RSpec module available. This module adds equivalent code templates for all the TextMate RSpec snippets. In addition, it adds an action for running the focused spec. See the last section in this document for more info.
View the Using RSpec with NetBeans screencast for a demonstration of behavior driven development using RSpec in the NetBeans Ruby support.
If you install the "ZenTest" Ruby Gem (use Tools | Ruby Gems), your projects will have an "AutoTest" menu item in their context menu. If you invoke it, it will launch AutoTest on your project, which will run unit tests automatically whenever you modify a file. AutoTest can in many cases figure out which unit tests need to be run - this is especially true for Rails projects. If not, it will run all unit tests.
If there are failures, the AutoTest support will post a summary message in the editor footer. You can then go back to the AutoTest window (which can be hidden) and look at the output to see what the failures are, and click on the hyperlinks to warp to the failing test cases.
(Note also that you can use the Goto Test action, Ctrl-Shift-T, to jump to the matching test file or rspec specification file directly.)
Note: This support is preliminary; in the future it's likely that test failures will show up in the new Tasklist instead.
Note 2: There is currently a bug preventing AutoTest from running correctly on JRuby. Switch to native Ruby for now, or keep your eyes on the JRuby issue for a resolution.
With the RSpec module installed, there are two additional editor actions available:
Debug Focused Test does not have an assigned keyboard shortcut, so you'll need to go to the Editor Options, locate it (under Other, named "Debug Focused Test") and pick something suitable.
Run Focused Test has a default keybinding (see RubyShortcuts) but it's not particularly convenient so you might want to assign it your own shortcut as well.
| autotest-footer.png | ![]() |
49521 bytes |
| autotest-menuitem.png | ![]() |
35090 bytes |
| goto-test.png | ![]() |
31928 bytes |