Ruby Screenshot of the Week #29: Test Navigator for RSpec

Let's start with the screenshot:

The thing to notice here is that we have a number of RSpec do-blocks in this file. Until now, only classes, methods, fields and attributes were showing up in the navigator. But in the latest daily builds, rspec do blocks like these are shown in the navigator (bottom left corner), along with the string summary (if any) such that you can quickly navigate between them. Placing the caret in one of these blocks will highlight the corresponding item in the navigator.

Adding a better navigator outline for spec files has been on the TODO list for a while, but apparently in the latest Rails builds regular tests are also switching away from using test methods to using test blocks (according to issue 137925, thanks James). So it seemed high time to do something about this.

The other thing to notice is that these blocks are also folded, so you can use Command-Shift-+ and - to collapse/expand all blocks quickly.

By the way, another old issue was fixed in NetBeans recently, which makes it easy to configure filetypes. In the past, if you wanted say .mab files to get Ruby treatment in the IDE, you'd file an issue and I'd modify the Ruby mimetype resolver to include it. The list is already pretty long -- .rb, .rake, .rxml, .rjs, .rbw, .rbx, .mab, .builder, .gemspec, and so on.

Now you can add any extra types you want yourself, using the Options | Miscellaneous | File Associations. Add any extensions you want, and bind them to the Ruby mime type and all the various Ruby editing machinery should kick in for files of that type.

NetBeans 6.5 Milestone 1 is about to be released and there are a lot of goodies there - both in the Ruby specific featureset as well as generic IDE support (such as the new Quick Search functionality). I'll look into that for another entry. And apologies for the long delay since my last entry - I blame it on a combination of having been sick, having taken some time off and having been busy with work...


I've searched high and low, and I finally have to go to the source. Is there a way to run the full suite of RSpec tests in netbeans, akin to "rake spec" on the command line? Shift-F6 is a handy way to test the specific \*_spec.rb file I'm working on, but I'd like to be able to run all RSpec tests at once.

I'd even be happy with a hack. If there's a way to have Netbeans run a shell script and show the output in the output window, that would work.

Posted by Jaime Bellmyer on June 24, 2008 at 07:56 AM PDT #

To Jaime Bellmyer:
Project - right button - Run/Debug Rake Task - spec

Posted by ruby.freeman on June 24, 2008 at 12:17 PM PDT #

Thanks, after a lot of digging, that's the best I've found. I still don't get the nice color-coded status bar, which I miss, and I wish there was a keyboard shortcut :)

Posted by Jaime Bellmyer on June 25, 2008 at 07:00 AM PDT #

Hi Jaime,
Is this a Rails project or a plain Ruby project? In Rails projects, the "Test Project" action (which has a keyboard shortcut) should run the test Rake target automatically, AND it should be run under the testing infrastructure (e.g. color coded status bar and hopefully the new test runner as well).

In plain Ruby projects I don't think the Test Project action is hooked up to anything. Is there a good default rake target for tests that most projects should obey?

The new test runner however ought to make it easy to run all tests. I'll ping Erno (who wrote it) to see what is possible there.

Posted by Tor Norbye on June 25, 2008 at 07:07 AM PDT #

Hi Jaime,
In the development builds of NB there is the 'RSpec Test' action in the project context menu for running all RSpec tests in the project (though only if the project has RSpec installed). You can also assign a shortcut for that. In addition you can use the new Rake runner (Ctrl-Shift-R) for quickly running any rake tasks, including rake spec (also only in the devel builds). I'm currently working on integrating the rake runner and the new test runner so that all testing tasks will properly invoke the test runner; should be finished in a day or two.

You can get the latest build from

Posted by Erno Mononen on June 25, 2008 at 07:45 AM PDT #

Hi Tor,
I'm having a lot of custom Ruby-based DSLs with a syntax similar to RSpec. I'd like to specify my own Syntax to get integrated into the navigator.

my_custom_dsl "with", "params" do

I'd like to to show that in navigator, maybe with parsing the params included. Would be even cooler if definition blocks can be nested and if I could choose the icons myself.

Is that already possible in 6.5 or will it be available later?

Posted by Benjamin Bock on June 26, 2008 at 08:44 PM PDT #

Hi Tor,

First of all, thanks for all the work you're doing making NetBeans great for working with Ruby and Rails. This post may not be the best place to ask, but will NetBeans 6.1 patch2 include performance fixes for code completion in views (Rails)? I didn't see it in a list of planned features for this release. As I understand, it's just around the corner - July 2nd is the release date. NetBeans 6.1 is great as it is, but current performance of code-completion in views is a real pain in day-to-day work.

Again, thanks for your work!


Posted by Anton Djurasaj on June 28, 2008 at 11:53 AM PDT #

Ah, this is really great, I've been wishing to have this feature a lot lately (working on RubySpecs and all)! Thanks!

The only problem for me now is that the nightly NB builds on Vista have rather noticeable degradation of font rendering, especially letter w is bad. Looks like LCD subpixel rendering is disabled (and only gray colors are used).

And I couldn't find a way to revert to older, much better rendering.

Same JDK, same system, two NB builds running at the same time: NB 6.1 looks great, NB-dev looks blurry.

Posted by Vladimir Sizikov on July 02, 2008 at 09:34 PM PDT #

Good day, Tor! There is a bug in last versions of Netbeans - when I edit and save \*.js file - Netbeans removes trailing spaces before saving, that is not good when you use SVN and want to save only your changes without refactoring all the code.

Posted by ruby.freeman on July 06, 2008 at 01:51 PM PDT #

Hi everybody, thank you for the comments and sorry for the delay; I've been taking some time off and while I've done some coding I've also taken a holiday from my inbox.

there's no support for making the DSL display customizeable. That is a good idea though it would be even better if it could somehow figure out "the right thing to do" on its own. With do/end blocks that make a call without parens, and especially if it has a String argument, that might be a good candidate for automatic display in the navigator. I wonder if that will be enough.

Are you talking about ERB/RHTML editing? There was a huge performance bug in 6.1 that should be patched in one of the patch releases, but I'm not sure where that's at (backporting and patch release is done by a separate team). Would you mind using a daily 6.5 build for now to see if the performance is better? I've been working on performance related infrastructure (to support incremental parsing) which should improve things in various areas, more so ERB than plain Ruby files at this point. But more importantly, the big ERB performance bug in 6.1 should be fixed in 6.5.

Hi Vladimir,
I saw some follow up e-mail traffic on this on another alias but for anyone else coming across these comments: Yes, apparently there's a bug related to editor antialiasing in the dev builds, related to Vista - and there are bug reports on it and people working on it so hopefully it will be addressed soon.

Hi Ruby Freeman,
Automatic stripping of whitespace is a new editor feature in NetBeans 6.5, but the feature is supposed to ONLY strip whitespace on lines you've "touched" during editing. It sounds like you've come across a bug related to that where it's wrong in computing the edited-lines-set; I've forwarded your comment to the developer behind this feature so see if it's a known problem.

Posted by Tor Norbye on July 06, 2008 at 03:23 PM PDT #

Hi Tor,

Yes I was talking about ERB/HTML editing. I will try 6.5dev instead.


Posted by Anton Djurasaj on July 08, 2008 at 12:30 PM PDT #

Post a Comment:
Comments are closed for this entry.

Tor Norbye


« March 2015