Autotest (part of ZenTest) now supports RSpec. This is fantastic news! For those of you who do not know about autotest, it is a program that runs in the background while you are writing your tests and code. Each time you make a change it automatically reruns your tests – and now your specs, too! This is a powerful addition to the TDD/BDD experience.

Recent releases of both tools overlapped a bit so there are changes in RSpec-0.9.1 that are not reflected yet in ZenTest. Also, while ZenTest-3.5.2 supports Spec::Rails, RSpec’s Ruby on Rails plugin, it does not support non-Rails Ruby projects.

I’ve submitted a patch to the ZenTest project which addresses both of these issues. Until the patch is applied, or the issues are addressed in some other way, you can apply it yourself to get autotest working with RSpec for Rails and other projects. These steps work on a mac. I assume that the commands are quite similar for Linux and Cygwin users.

  1. Go to http://rubyforge.org/frs/?group_id=419 and download ZenTest-3.5.2.tgz
  2. Unpack the tar and
    tar zxvf ZenTest-3.5.2.tgz
    cd ZenTest-3.5.2
    
  3. Get and install the patch
    curl -O http://blog.davidchelimsky.net/files/ZenTest-3.5.2-rspec.patch
    patch -p0 < ZenTest-3.5.2-rspec.patch
    
  4. Build and install the gem
    rake gem
    sudo gem install pkg/ZenTest-3.5.2.gem
    

Once you’ve built and installed the patched gem, you run autotest as normal. Stand in the root of your project and say:

autotest

If you have a spec directory at the root of your project, autotest will load up rspec_rails_autotest for Rails projects and rspec_autotest for everything else.

To quote Josh Knowles, Happy (Auto)Specing!

6 Responses to “RSpec-0.9.1 and Autotest (ZenTest-3.5.2)”

  1. Josh Knowles
    Josh Knowles Says:

    Nice work, thanks!

  2. Matt Aimonetti
  3. Hussein Morsy
    Hussein Morsy Says:

    Thanks !

    but i have two problem/questions: 1. If a example fails, autotest repeats the the execution of the failed example continiously.( although i didn’t change any file)

    2. How to enable synstax coloring ?

  4. David
    David Says:

    Hussein – take a look at spec/spec.opts and get rid of everything related to—failures and—example. That should do the trick for the continuous run problem.

    The coloring there is no solution for at the moment (that I am aware of).

  5. David James
    David James Says:

    I’m running ZenTest (3.5.2) and I’m using rspec 0.9.5. I got an error when running autotest; here is the log:

    $autotest
    loading rspec_rails_autotest
    spec --diff unified spec/models/spec/models/person_spec.rb ...
    /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:27: command not found:  spec --diff unified spec/models/person_spec.rb
    

    I guessed the fix pretty quickly. To run spec, I have to do `rake spec` or `script/spec`. Not just `spec`. So here is how I fixed the problem:

    In my rspec_rails_autotest.rb, I noticed this line:
    @spec_command = "spec --diff unified" 
    
    Changing it to this solved my problem:
    @spec_command = "script/spec --diff unified" 
    
    Then, as mentioned in other places, I needed to install diff-lcs as well:
    sudo gem install diff-lcs

    Are others having the same problem? Did my fix work for you?

  6. David James
    David James Says:

    I’m running ZenTest (3.5.2) and I’m using rspec 0.9.5. I got an error when running autotest; here is the log:

    $autotest
    loading rspec_rails_autotest
    spec --diff unified spec/models/spec/models/person_spec.rb ...
    /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:27: command not found:  spec --diff unified spec/models/person_spec.rb
    

    I guessed the fix pretty quickly. To run spec, I have to do `rake spec` or `script/spec`. Not just `spec`. So here is how I fixed the problem:

    In my rspec_rails_autotest.rb, I noticed this line:
    @spec_command = "spec --diff unified" 
    
    Changing it to this solved my problem:
    @spec_command = "script/spec --diff unified" 
    
    Then, as mentioned in other places, I needed to install diff-lcs as well:
    sudo gem install diff-lcs

    Are others having the same problem? Did my fix work for you?

Leave a Reply (Textile Enabled)