ZenTest+Autospec Is An RSpec TDDer’s Best Friend

In all the time that I’ve been using RSpec (almost a year now), I never knew about the zentest or autospec tools until I was recently watching a code kata that was using Ruby and RSpec. … so, now I have to ask… why didn’t I know about ZenTest and autospec until just over a week ago?! For the last year or so, I’ve been manually running my albacore test suite after every change that I made. This meant a series of time wasting steps, dependent on what I was doing:

Run New Tests: alt-tab over to my command prompt, type in “spec spec/whatever_spec.rb –fs –c”, hit enter and wait for the tests to complete

Re-Run Tests: alt-tab over to my command prompt, pressing the up arrow on my keyboard to reload the previously run command, hitting enter to re-run the tests and wait for them to complete

But NO MORE! With ZenTest installed, I can use the autospec feature of Rspec and be done with the manual execution of tests! Now All I need to do is run the “autospec” command from the home directory of my albacore project. This will configure ZenTests’s autotest feature to run my rspec tests. It will then run the entire suite of tests (which takes a couple of minutes, since albacore is nothing but integration tests). Once the suite has finished running, autotest will pause and wait for a file system change in my albacore folder structure. When it sees a file system change, it will attempt to find the tests that correspond to the file being changed and re-run only the changed tests.

For example… when I write out my tests for the xunit task from gVim


autospec picks up on the changes to the tests and re-runs just the xunit tests:



Install ZenTest and RSpec

Installation is easy. You only need rspec and ZenTest (note the capital Z and T in ZenTest when installing the gem)


Now you, too, can enjoy the awesomeness that is automatic test runs without having to go through a CI server. :)


Questions: How Do I … ????

Unfortunately, the documentation for ZenTest and RSpec’s autotest are somewhat lacking. It seems to be very difficult to find any single source of information, other than the implementations in the source code. There are a few places with “official” documentation, but the options and configurations are not completely specified. There’s also an html file with examples and plugins listed, that comes with ZenTest.

Here are the places that I know of, to find information:

Some things that I really want to know, which I can’t find anyhwere…

  • How do I get it to produce my “Format: SpecDoc” from rspec (the “-fs” parameter that I use)?
  • How do I get it to produce my “Colour” specs from rspec (the “-c” parameter that I use)?

There are some pretty cool plugins for this, though. Maybe one of them will help answer my questions or provide functionality that replaces what I want. Does anyone know of a good list of plugins, other than the “getting started” html file I mentioned? Does anyone know of a good place to get information on how to configure autotest, other than reading through the source code and what little rdocs there are?

About Derick Bailey

Derick Bailey is an entrepreneur, problem solver (and creator? :P ), software developer, screecaster, writer, blogger, speaker and technology leader in central Texas (north of Austin). He runs SignalLeaf.com - the amazingly awesome podcast audio hosting service that everyone should be using, and WatchMeCode.net where he throws down the JavaScript gauntlets to get you up to speed. He has been a professional software developer since the late 90's, and has been writing code since the late 80's. Find me on twitter: @derickbailey, @mutedsolutions, @backbonejsclass Find me on the web: SignalLeaf, WatchMeCode, Kendo UI blog, MarionetteJS, My Github profile, On Google+.
This entry was posted in Albacore, Behavior Driven Development, Command Line, Continuous Integration, Productivity, Rake, RSpec, Ruby, Unit Testing, Vim. Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • I’m actually in the middle of writing a very similar blogpost. To answer your two questions (I think)…

    You can create a spec.opts file to add your options to. I have a line that has “–color” and “–format specdoc” in mine, so I get color and formatting. However… for some reason coloring is broken inside of autospec on windows ATM.

    BTW, growl integration (gem: autotest-growl) works for the windows version of growl also… I highly recommend.

  • Jon is right, a few more details.

    Create a spec.opts file within your spec directory and autospec will automatically respect it when you run it from the parent directory. I similarly use: -f specdoc –color

    Within the root of your project you can create a file: .autotest
    There you can gain access to the hooks in the program. I haven’t spent much time exploring that, save the common example to add a hook to ignore a file type:

    Autotest.add_hook :initialize do |at|
    %w{ spec/ignoretests/** }.each {|exception| at.add_exception(exception)}

  • Junky

    “Continuous Testing” from Pragmatic goes into some detail on autotest.