RubyTesting61

The information on this page pertains to NetBeans IDE 6.1. If you are looking for information about Testing in 6.5, look here.


This document describes support for testing in the NetBeans Ruby Support.

Contents


Test::Unit

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).

http://wiki.netbeans.org/wiki/attach/RubyProjects/ruby-unittests.png

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.

http://wiki.netbeans.org/wiki/attach/RubyTesting/goto-test.png

RSpec

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.

AutoTest

Note: Autotest menu on Netbeans edge (06/11/2008) + RSpec won't work. Hopefully, there is a http://21croissants.blogspot.com/2008/11/trick-for-netbeans-65-latest-build-and.html

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.

http://wiki.netbeans.org/wiki/attach/RubyTesting/autotest-menuitem.png

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.

http://wiki.netbeans.org/wiki/attach/RubyTesting/autotest-footer.png

(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.

Running Current Test

With the RSpec module installed, there are two additional editor actions available:

  • Run Focused Test. Runs the test around the caret in the editor.
  • Debug Focused Test. Same as Run Focused Test, but it runs the test under the debugger.

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.

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo