a better progress bar for rspec

Updated 2008-12-10: added screenshot and video.

I’ve always been a little bit bemused by the default ruby test/unit and rspec output: a series of dots, one for each passing test (or example), and the dots become “F” characters in the event of a failure.  Most importantly: it’s simple, unambiguous about pass/fail, and easy to read at a glance, so no problem there.  You get a feel for the speed at which the tests are running, and you can visualize how many tests have run already.  And it’s easy enough to have them output in color (red or green), to make the errors visually pop out.  And it’s drop dead simple.  That’s good.

So what’s missing?

(for my tastes)

  • Immediate Feedback: Yeah, the default output gives me an “F”, but what am I supposed to do with an “F”? I won’t know where and what that “F” was until the end of the entire test run, when the summary is dumped.  When running through a (functional) test suite that takes three minutes or even fifteen minutes, that just doesn’t work.
  • Concise output: if everything is passing, I don’t need to see 4000+ dots displayed across my screen. It would be nice if the entire output would fit into a single line (when there are no failures).
  • Percentage: A nice to have, not a need to have. But knowing how many tests have already run is generally not as interesting to me as how many tests are there total, and what percentage of them have run.
  • ETA: This isn’t so important for the short test runs that I do over and over again during the BDD cycle… because I expect those tests to finish in under 10 seconds anyway.  But anything more than 10 seconds, and I get distracted. An ETA helps me limit my distraction.

So what do I do about it?

Basically, what I want is a progress bar and that the errors and warnings be displayed immediately. I also want warnings to be printed for slow specs. When using color, I want the entire progress bar printed in green if everything is good, yellow if there has been a warning, and red if there has been an error.

Fortunately, rspec makes it very simple to write a custom output formatter. So, a couple of weekends ago, I threw something together in about half an hour. I’ve used it ever since, and I’m pretty happy with it (I’ve tweaked it a little bit).

What does it look like?

A static image doesn’t really show off the progress bar very well, but here’s a screenshot (click thumbnail for full-size):

And here is a video, so you can see it in action (very low quality, sorry):

The code

http://ekenosen.net/bzr/rspec_support/compact_progress_bar_formatter.rb

It’s currently hosted in a bzr branch, but I’ll stick it up on github if anyone really cares about that.  Also, it depends upon the progressbar gem, so you’ll need to install that.

To use it

The location you download the script to is not important, but this is where I’m (currently) keeping it. You could also use bzr to pull down the entire branch.

$ gem install progressbar

$ mkdir -p ~/lib/rspec/
$ cd ~/lib/rspec
$ wget http://ekenosen.net/bzr/rspec_support/compact_progress_bar_formatter.rb

$ spec --require ~/lib/rspec/compact_progress_bar_formatter.rb -c -f Spec::Runner::Formatter::CompactProgressBarFormatter path/to/specs

I’m currently using some bash aliases to keep the spec command line nice and short. Perhaps there’s a better way?  In ~/.bash_aliases:

alias  spb='spec        --require ~/lib/rspec/compact_progress_bar_formatter.rb --format Spec::Runner::Formatter::CompactProgressBarFormatter --color'
alias sspb='script/spec --require ~/lib/rspec/compact_progress_bar_formatter.rb --format Spec::Runner::Formatter::CompactProgressBarFormatter --color'

For rake tasks, I use a spec/local_spec.opts (spec/spec.opts is checked into version control as a default).

Nitpicking

I cheated: I didn’t develop it BDD-style.  I intend to fix that soon by rewriting it spec-first; certainly before adding any more functionality. TATFT indeed.

I’d really like to be able to send the threshold (for reporting of slow specs) in on the command line.  It might be easy to do, I haven’t looked into it… I’m currently just editing the file every time I want to change the threshold (e.g. normal specs run with a threshold of 0.1 sec, functional specs run with a threshold of 5 or 10 seconds).  Messy.

Also, it would be nice if the command line didn’t need to be so long… perhaps a supported gem/plugin system for rspec?  If that were easily doable, then I would probably package this up into a gem.

I had to break into the progressbar’s internals a little bit… it didn’t publically expose all of the functionality I wanted.  Still, that’s better than creating my own progressbar library.

Tags: , , ,

5,834 Responses to “a better progress bar for rspec”

  1. car rentals says:

    My overall experience was good. What I experienced was what I expected.

  2. rumiko world says:

    Real good information can be found on website .

  3. Hello! I’ve been reading your web site for some time now and finally got the courage to go ahead and give you a shout out from New Caney Texas! Just wanted to tell you keep up the good job!

  4. Good – I should definitely say I’m impressed with your site. I had no trouble navigating through all the tabs as well as related information. The site ended up being truly simple to access. Great job…

  5. Good blog! I truly love how it is easy on my eyes it is. I’m wondering how I could be notified when a new post has been made. I have subscribed to your feed which may do the trick? Have a great day!

  6. Thanks for the suggestions shared in your blog. Something else I would like to talk about is that weight-loss is not about going on a dietary fads and trying to get rid of as much weight that you can in a few days. The most effective way to shed weight is by having it slowly but surely and right after some basic points which can make it easier to make the most out of your attempt to shed pounds. You may know and be following some tips, but reinforcing understanding never affects.

  7. mondafinil says:

    Many thanks for creating the effort to discuss this, I feel strongly about this and enjoy learning a great deal more on this matter. If possible, as you gain knowledge, would you mind updating your webpage with a great deal more information? It’s extremely useful for me.

  8. I was wondering if you ever considered changing the layout of your blog? Its very well written; I love what youve got to say. But maybe you could a little more in the way of content so people could connect with it better. Youve got an awful lot of text for only having one or two images. Maybe you could space it out better?

  9. Deference to website author , some superb entropy. “If you don’t leap, you’ll never know what it’s like to fly.” by Guy Finley.

  10. Spot on with this write-up, I truly think this website needs much more consideration. I’ll probably be again to read much more, thanks for that info.

  11. Grant Lemere says:

    Good – I should definitely pronounce, impressed with your web site. I had no trouble navigating through all tabs and related information ended up being truly simple to do to access. I recently found what I hoped for before you know it at all. Reasonably unusual. Is likely to appreciate it for those who add forums or something, site theme . a tones way for your customer to communicate. Excellent task.

  12. Superior write-up however Let me tell you that I think there is issue with your RSS feeds as they quite simply appear to not be working for me. Might be just me but I thought overall I would note it.

  13. || # http://www.Getlinklist.com is a backhat SEO Forum where you can get: #||

  14. Excellent blog post nevertheless I want to tell you that I think there is issue with your RSS feeds since they seem to not be working for me. Might be just me but I was thinking I would note it.

  15. I always was interested in this topic and still am, appreciate it for posting.

  16. Hi there. Very nice website!! Man .. Excellent .. Superb .. I’ll bookmark your blog and take the feeds also…I’m glad to find so much useful information right here in the article. Thank you for sharing..

  17. skincare…

    I used to be very pleased to seek out this internet-site.I needed to thanks to your time for this glorious read!! I definitely having fun with every little bit of it and I have you bookmarked to check out new stuff you blog post….

  18. thanks, I believe your visitors could possibly want significantly more articles similar to this carry on the good work.

  19. OMFG do NOT listen to Vinnie! Do NOT put Neg cable on the Positive! What a moron!

  20. I enjoy the efforts you have put in this, appreciate it for all the great blog posts.

  21. kylling says:

    kylling…

    [...]a better progress bar for rspec « nick evans – devblog[...]…

  22. Keep up the good work , I read few posts on this website and I think that your site is really interesting and has got lots of fantastic info .

  23. I have been gone for a while, but now I remember why I used to love this blog. Thank you, I will try and check back more often. How often do you update your site?

  24. naples jobs says:

    Certainly I like your website, however you have to test the spelling on several of your posts. Several of them are rife with spelling issues and I find it very silly to tell you. However I’ll definitely come back again!

  25. I think this site contains some really good info for everyone :D . “Years wrinkle the skin, but to give up enthusiasm wrinkles the soul.” by Samuel Ullman.

  26. Howdy. Very nice web site!! Man .. Beautiful .. Wonderful .. I’ll bookmark your web site and take the feeds additionally…I’m glad to find numerous helpful information here within the article. Thank you for sharing..

  27. Usually I do not learn post on blogs, however I wish to say that this write-up very forced me to take a look at and do it! Your writing style has been surprised me. Thanks, very nice article.

  28. Hello there! I know this is kinda off topic but I was wondering if you knew where I could get a captcha plugin for my comment form? I’m using the same blog platform as yours and I’m having problems finding one? Thanks a lot!

  29. Sprawdzalem ten portal jest genialny

  30. I was wondering if you ever considered changing the layout of your blog? Its very well written; I love what youve got to say. But maybe you could a little more in the way of content so people could connect with it better. Youve got an awful lot of text for only having one or two images. Maybe you could space it out better?

  31. aephi neu says:

    Really nice style and design and good written content, nothing else we require :D .

  32. Awsome info and right to the point. I don’t know if this is truly the best place to ask but do you people have any ideea where to hire some professional writers? Thank you :)

  33. Outstanding read, I just passed this onto a colleague who was doing a little research on that. And he actually bought me lunch because I discovered it for him smile So let me rephrase that: Thanks for lunch!

  34. Only a smiling visitant here to share the love (:, btw wonderful design and style .

Leave a Reply