Read my latest article: Announcing RailsDeveloper (posted Wed, 01 Sep 2010 17:01:00 GMT)

The Zen of Auto Rspec

Posted by Robby Russell Wed, 10 Jan 2007 17:08:00 GMT

32 comments Latest by used cars  Tue, 31 Aug 2010 06:02:48 GMT

Several months ago, I heard that people were using a program called autotest to have their tests continue to run as you made changes to your code base, which comes with ZenTest. It’s a really nice tool written by Ryan Davis and I hadn’t gotten a chance to play with it as of yet. Well, our team isn’t spending too much time in the test/ directory these days as we jumped ship near the end of last summer and found ourselves hanging out on the Isle of BDD. The locals are quite thoughtful about these sorts of things.

I just started working on a project that has been under development for several months and as I’m getting to learn the ins/outs of the system, I find myself having to rerun the specs, which can take quite a bit of time watching. Watching your specs or tests run sometimes is as productive as watching your code compile. Oddly enough, this is as close to compilation as we really get when working with Ruby on Rails… and it’s a productivity killer for me.

There Must Be a Better Way!

So, I did a quick google search and found an announcement for Rails that ran specs through ZenTest. This was exactly what I was searching for!

Some requirements

Please makes sure that you have the following gems installed in your development environment as they are dependencies to make this all work.

  • zentest
  • diff-lcs

$ sudo gem install zentest diff-lcs 

note I’m going to assume that you have rspec and rspec for rails installed… if not… tsk. ;-)

Install RSpec autotest


$ script/plugin install http://svn.caldersphere.net/svn/main/plugins/rspec_autotest

If you’re using subversion, you might consider installing it as an external.


$ script/plugin install -x http://svn.caldersphere.net/svn/main/plugins/rspec_autotest

Running RSpec autotest

This is where it gets tricky. ;-)


$ rake spec:autotest

Now, you can keep a terminal window open and autotest will watch your application and detect when files change. When they change, it’ll attempt to rerun your specs (specifically those that changed). This helps save you the time of having to rerun all your specs throughout the development process and keep your spec:all sanity checks for when you’re about to commit code to your repository.

I’ll post another entry in the next few days to show you how you can use Growl with RSpec Autotest to keep you from having to look at your terminal all the time.

Until then… have fun!

Subscribe to my RSS feed Enjoying the content? Be sure to subscribe to my RSS feed.
Comments

Leave a response

  1. Avatar
    Thomas Wed, 10 Jan 2007 17:32:48 GMT

    This is excellent! I took time over the holidays to start diving into rspec and amazed at how quickly I changed how I was thinking about the problems that I’m solving.

    I can see this being very useful when your application size grows. Thanks for the tip!

  2. Avatar
    Dylan Wed, 10 Jan 2007 22:23:41 GMT

    Head into rspec_autotest.rb and change the command to drbspec and combine it with the server for much better performance.

  3. Avatar
    Dylan Wed, 10 Jan 2007 22:23:47 GMT

    Head into rspec_autotest.rb and change the command to drbspec and combine it with the server for much better performance.

  4. Avatar
    Thomas Thu, 11 Jan 2007 05:53:59 GMT

    Thank you so much for posting this! I easily saved a half hour of my day by not rerunning tests all the time. I had my terminal running and my textmate alongside and it was simply wonderful. :-)

  5. Avatar
    Merlyn Albery-Speyer Mon, 12 Mar 2007 19:09:20 GMT

    Have you tried to do anything like this with JRuby?

  6. Avatar
    Merlyn Albery-Speyer Mon, 12 Mar 2007 19:09:31 GMT

    Have you tried to do anything like this with JRuby?

  7. Avatar
    Wayword Sat, 26 May 2007 08:37:15 GMT

    nice article… what is up with all the porn names in the comments though?

  8. Avatar
    Ben Thu, 19 Jul 2007 19:11:22 GMT

    I am having troubles getting auto rspec running on Windows. First I discovered that I had to define a HOME environment variable – see this post: http://groups.google.de/group/comp.lang.ruby/browse_thread/thread/b351f7fa101ff9f6

    But now I am receiving a format error: “rake aborted! Exec format error – spec—diff unified spec/models/education_level_spec.rb spec/models/activities_lung_sound_spec.rb spec/models/case_status_spec.rb spec/models/danger_sign_spec.rb spec/models/employment_status_spec.rb spec/models/closure_reason_spec.rb spec/models/activity_spec.rb spec/models/activities_intervention_spec.rb”

    I am Using: WinXP SP2 zentest version 3.6.0 rspec version 1.0.5 diff-lcs version 1.1.2 rails version 1.1.2

    Has anyone else come across this issue?

  9. Avatar
    nieruchomości Szczecin Mon, 24 Sep 2007 13:08:58 GMT

    This is very good! Thanks for the post !

  10. Avatar
    Brian Corrales Fri, 07 Dec 2007 20:29:52 GMT

    Where do you set the HOMe environment variable? I cn’t find File.expand_path. Any help would be GREATLY appreciated.

  11. Avatar
    nieruchomości szczecin Tue, 15 Jul 2008 11:04:56 GMT

    Very nice article…Thanks!

  12. Avatar
    Charles Sun, 09 Nov 2008 21:25:26 GMT

    I too am having the same problem Ben was having; the “exec format error”. I also am running windows. I have seen other folks on forums with the same issue, but no one has offered any suggestions that work for me (eg update zentest, using script/spec instead of just spec and trying spec.cmd instead of just spec). When I type

    spec—diff unified test/test_helper.rb

    into the console directly, there seems to be no problem; it only occurs when this line is run via the rake task. Any suggestions would be appreciated… (it seems a little odd that it is not looking for my other test files, just the test_helper.rb)

    cheers, charles de b

  13. Avatar
    Citroen Xsara Picasso Tue, 25 Aug 2009 10:55:30 GMT

    Thanx For sharing ur greeat stuff

  14. Avatar
    Matthew Tue, 09 Feb 2010 06:13:37 GMT

    How lucky I found this post! I am just looking information to solve the same problem. Thanks for your post. It’s really helpful.

  15. Avatar
    Birmingham Moving Company Thu, 18 Feb 2010 11:18:21 GMT

    Nice Post . I liked the way you started and compiled the ending of your article.

    Good Job Done!!!

  16. Avatar
    laptop adapter supplier Thu, 13 May 2010 06:58:15 GMT

    Oddly enough, this is as close to compilation as we really get when working with Ruby on Rails… and it’s a productivity killer for me.

  17. Avatar
    Nike Air Jordan Mon, 07 Jun 2010 09:43:17 GMT

    Nice Post . I liked the way you started and compiled the ending of your article.

  18. Avatar
    jordan VII Thu, 17 Jun 2010 05:57:00 GMT

    tyu t

  19. Avatar
    jordan six rings Thu, 17 Jun 2010 05:57:18 GMT

    try rt

  20. Avatar
    Vintage coffee grinder Thu, 08 Jul 2010 19:04:51 GMT

    Now, you can keep a terminal window open and autotest will watch your application and detect when files change. When they change, it’ll attempt to rerun your specs (specifically those that changed).

  21. Avatar
    Louis Vuitton Wallets Mon, 19 Jul 2010 17:19:59 GMT

    Louis Vuitton Chicago leather Marco wallet M95991 Louis Vuitton Chicago leather Marco wallet Louis Vuitton Chicago 8 CC wallet M95788 Louis Vuitton Chicago 8 CC wallet Louis Vuitton Compact Trifold Chicago M95787 Louis Vuitton Compact Trifold Chicago Louis Vuitton Chicago 12 CC bill holder M95789 Louis Vuitton Chicago 12 CC bill holder

    Louis Vuitton Zippy Wallet M85068 Louis Vuitton Zippy Wallet Louis Vuitton Zippy Wallet M85069 Louis Vuitton Zippy Wallet

    Louis Vuitton Zippy Wallet M95871 Louis Vuitton Zippy Wallet Louis Vuitton Zippy Wallet M93029 Louis Vuitton Zippy Wallet Louis Vuitton Zippy Wallet M93026 Louis Vuitton Zippy Wallet Louis Vuitton Zippy Wallet M93028 Louis Vuitton Zippy Wallet Louis Vuitton suhali leather le favori wallet M95645 Louis Vuitton suhali leather le favori wallet Louis Vuitton suhali leather le favori wallet M95646 Louis Vuitton suhali leather le favori wallet Louis Vuitton suhali leather le favori wallet M95649 Louis Vuitton suhali leather le favori wallet Louis Vuitton Le Somptueux Wallet M95855 Louis Vuitton Le Somptueux Wallet

  22. Avatar
    asics running shoes Wed, 21 Jul 2010 10:31:59 GMT

    This was a useful post and I think it is rather easy to see from the other comments as well that this post is well written and useful. Keep up the good work women’s asics gel nimbus men’s asics running shoes asics running shoes women reviews asics gel kinsei 2 men’s shoes

  23. Avatar
    kemi Sat, 31 Jul 2010 13:26:47 GMT

    Cartier Jewelry However, a source close to tiffany co necklaces Grigorieva did confirm to ABC replica tag heuer watches

  24. Avatar
    coach handbags Mon, 02 Aug 2010 05:38:30 GMT
  25. Avatar
    Adidas Online Shop Tue, 03 Aug 2010 01:17:36 GMT

    really good read. keep posting like this!

  26. Avatar
    Louboutin Pumps Tue, 03 Aug 2010 01:18:08 GMT

    Simple, clever? and very useful.

  27. Avatar
    SPEEDY 25 Thu, 05 Aug 2010 17:45:26 GMT

    have a good time

  28. Avatar
    Louis Vuitton Sofia Coppola SLIM MONOGRAM M42427 Thu, 05 Aug 2010 17:46:46 GMT

    thank you

  29. Avatar
    diaper bag factory Mon, 09 Aug 2010 03:34:23 GMT

    em, I find myself having to rerun the specs, which can take quite a bit of time watchin

  30. Avatar
    http://www.bestretroshoes.com Tue, 10 Aug 2010 09:50:46 GMT
    women jordan shoes,women jordan shoes
    Nike Shox,Nike Shox
    Nike Air Dunks,Nike Air Dunks
    Timberlands Boots,Timberlands Boots
    Women Air Yeezy shoes,Women Air Yeezy shoes
    discount Air jordan 9.5,discount Air jordan 9.5
    discount Air jordan 1.5,discount Air jordan 1.5
    discount Air jordan 24,discount Air jordan 24
    Jordan retro VI,Jordan retro VI
  31. Avatar
    used cars  Tue, 31 Aug 2010 06:02:06 GMT

    Too often bloggers take the time to write quality detailed posts like this and people fly back, absorb, and move on.I want to thank you for sharing this in depth knowledge with us. Hope you can keep up your blog and not fall into the 80% who eventually abandon their blog.

  32. Avatar
    used cars  Tue, 31 Aug 2010 06:02:48 GMT

    Too often bloggers take the time to write quality detailed posts like this and people fly back, absorb, and move on.I want to thank you for sharing this in depth knowledge with us. Hope you can keep up your blog and not fall into the 80% who eventually abandon their blog.

Share your thoughts... (really...I want to hear them)

Comments