rspec and autotest 10

Posted by David Tue, 29 May 2007 12:19:00 GMT

At RailsConf 2007 in Portland, I had the privilege of sitting down w/ Ryan Davis and working with him to improve the runtime relationship between RSpec and Autotest. David Goodlad was at the table as well, and helped me work out some of the mappings so autotest runs the right examples when you change application code.

The result is that with RSpec >= 1.0.3 and ZenTest >= 3.6.0, you can now use Autotest with RSpec on your Ruby projects, Rails or otherwise, simply by typing “autotest” in the project root. No additional plugins necessary. Sweet.

One gotcha: Some have reported that when an example fails, autotest keeps running it over and over again until you get it to pass. This is due to a conflict between RSpec’s and autotest’s mechanisms for narrowing down the set of files to run. This is easily resolved by removing the following lines from spec/spec.opts:

--format
failing_examples:previous_failures.txt
--example
previous_failures.txt

If you run ‘script/generate rspec’, these lines will not be included in the generated spec.opts file. Otherwise you can just delete them yourself.

Comments

Leave a response

  1. Avatar
    http://www.21croissants.com Tue, 29 May 2007 17:43:12 GMT

    Hi David,

    I have encoutered the same problem as Ed Brannin (see http://www.ruby-forum.com/topic/109537 ): I am using rspec 1.0.3 (installed in vendor/plugins) and ZenTest 3.6.0. I have written a post about my .autotest config in my blog: http://21croissants.blogspot.com/2007/04/set-up-rspec-on-rails.html

    I will update the post as soon as I get a working config, I guess I’ll have to comment the : Autotest.add_hook :initialize do |autotest| if autotest.is_a? RspecRailsAutotest autotest.spec_command = ‘script/spec—options spec/spec.opts’ end end

    The stack trace: /usr/local/lib/site_ruby/1.8/rubygems.rb:382:in `latest_partials’: undefined method `[]’ for nil:NilClass (NoMethodError) from /usr/local/lib/site_ruby/1.8/rubygems.rb:379:in `latest_partials’ from /usr/local/lib/site_ruby/1.8/rubygems.rb:342:in `latest_load_paths’ from /usr/local/lib/site_ruby/1.8/rubygems.rb:341:in `latest_load_paths’ from /usr/lib/ruby/gems/1.8/gems/ZenTest-3.6.0/lib/autotest.rb:109:in `autodiscover’ from /usr/lib/ruby/gems/1.8/gems/ZenTest-3.6.0/bin/autotest:36 from /usr/bin/autotest:16

    Any clue where should I watch?

    Cheers,

    Jean-Michel Garnier

  2. Avatar
    David Chelimsky Tue, 29 May 2007 23:22:37 GMT

    Jean-Michel – just get rid of your .autotest file and you should be fine. You don’t need it for RSpec-1.0.3 and ZenTest-3.6.0 to play nice together. They just do.

  3. Avatar
    Wintermute Wed, 30 May 2007 03:52:33 GMT

    You released RSpec 1.0.4 again with an “incompatible” RSpec on Rails version again:

    Your RSpec on Rails plugin is incompatible with your installed RSpec.

    RSpec : 1.0.4 (r2054) RSpec on Rails : r2008

  4. Avatar
    Wintermute Wed, 30 May 2007 04:03:24 GMT

    Disregard my previous comment. I had placed the previous plugins in a sub-directory named “OLD” and didn’t realize that Rails was autoloading all subdirectories in vendor/plugins.

  5. Avatar
    Josh Knowles Wed, 30 May 2007 06:54:06 GMT

    David,

    Thanks for all the hard work getting this integrated. Unfortunately it doesn’t work if you don’t have the Rails Gem installed. Patch/Details here: http://rubyforge.org/tracker/index.php?func=detail&aid=11221&group_id=797&atid=3151

  6. Avatar
    http://www.21croissants.com Wed, 30 May 2007 12:05:47 GMT

    Thanks David for your quick feedback.

    I have upgraded to rspec 1.0.4 and applied the patch submitted by Josh because I have also Rails in my vendors folder. On the other hand, I upgraded rubygems from 0.9.2 to 0.94 because I realized I did not have the latest version. it still gives me the same stack trace:

    $ autotest /usr/local/lib/site_ruby/1.8/rubygems.rb:385:in `latest_partials’: undefined method `[]’ for nil:NilClass (NoMethodError) from /usr/local/lib/site_ruby/1.8/rubygems.rb:382:in `latest_partials’ from /usr/local/lib/site_ruby/1.8/rubygems.rb:345:in `latest_load_paths’ from /usr/local/lib/site_ruby/1.8/rubygems.rb:344:in `latest_load_paths’ from /usr/lib/ruby/gems/1.8/gems/ZenTest-3.6.0/lib/autotest.rb:109:in `autodiscover’ from /usr/lib/ruby/gems/1.8/gems/ZenTest-3.6.0/bin/autotest:36 from /usr/bin/autotest:16

    Are you sure I should get rid of the .autotest file though. Check out this excellent guide in http://ph7spot.com/articles/getting_started_with_autotest/ (Configure Plugins)

    I am using it to hook a notifier for my ubuntu. I have posted a comment in the blog of Ryan to ask him.

  7. Avatar
    David Chelimsky Wed, 30 May 2007 18:32:33 GMT

    Josh – I got and applied your patch just an hour or so after releasing 1.0.4. It’ll be in 1.0.5.

    Jean-Michel – if you want to keep .autotest around for other things, that’s fine, but you should be able to get rid of any of the rspec-specific hooks that deal w/ the spec command or file mappings.

  8. Avatar
    http://www.21croissants.com Wed, 30 May 2007 19:34:45 GMT

    Josh & David:

    UPDATE

    Ryan Davis (Zenspider) found the solution in 5 minutes chatting. I had a weird web_spec gem in my gems, check out the list in http://rafb.net/p/212ywT51.html I had to delete it with rm -Rf and then it almost worked.

    But … I got another stacktrace: $ autotest loading autotest/rails_rspec ./vendor/plugins/rspec_on_rails/lib/autotest/rails_rspec.rb:33:in `initialize’: undefined method `singularize’ for .svn/text-base/user (NoMethodError) from /usr/lib/ruby/gems/1.8/gems/ZenTest-3.6.0/lib/autotest.rb:395:in `tests_for_file’ from ./vendor/plugins/rspec/lib/autotest/rspec.rb:19:in `tests_for_file’ from /usr/lib/ruby/gems/1.8/gems/ZenTest-3.6.0/lib/autotest.rb:319:in `find_files_to_test’ from /usr/lib/ruby/gems/1.8/gems/ZenTest-3.6.0/lib/autotest.rb:318:in `find_files_to_test’ from /usr/lib/ruby/gems/1.8/gems/ZenTest-3.6.0/lib/autotest.rb:373:in `reset’ from /usr/lib/ruby/gems/1.8/gems/ZenTest-3.6.0/lib/autotest.rb:164:in `run’ from /usr/lib/ruby/gems/1.8/gems/ZenTest-3.6.0/lib/autotest.rb:123:in `run’ from /usr/lib/ruby/gems/1.8/gems/ZenTest-3.6.0/bin/autotest:48 from /usr/bin/autotest:16

    As I had installed Josh’s patch which removed the require ‘active_support’ line, it could not find the method `singularize’.

    When I put back the require, I got everything worked as a charm, including my hook defined in .autotest

    I have updated the http://rubyforge.org/tracker/index.php?func=detail&aid=11221&group_id=797&atid=3151 in rubyforge.

    Cheers Ryan!

  9. Avatar
    http://www.21croissants.com Wed, 30 May 2007 19:37:42 GMT

    On a side note, Ryan wanted to know where did the web_spec gem came from, any idea?

  10. Avatar
    David Chelimsky Thu, 31 May 2007 12:41:01 GMT

    Jean-Michel – Glad you and Ryan got that all worked out. Josh submitted a new patch. It wasn’t as simple as replacing the removed require – but it was almost as simple ;)

    The web_spec gem was from an old, old version of rspec that was breaking the law and generating stuff outside its own directories. This was removed months ago, so I can only guess that you had it lying around from an old version of rspec.

Comments