blog.mhartl | Michael Hartl's tech blog

2009-05-15

Running rcov with RSpec

Filed under: RSpec, Ruby, Ruby on Rails — mhartl @ 16:01

I recently wanted to run rcov, the Ruby code coverage tool, on a project tested with RSpec. I think I’d done it once before, but I’d forgotten how. After searching to no avail (both the rcov home page and the RSpec page on rcov proved unhelpful), I applied the tried-and-true Wild-Assed Guess™ method and typed

$ rake spec:rcov

That worked.

The reports themselves are in the coverage/ directory:

$ open coverage/index.html

(or navigate your browser to file:///path/to/project/coverage/index.html). If you’re using Git, add coverage/* to your .gitignore file.

N.B. The inverse Rake task also exists:

$ rake -T rcov
rake spec:clobber_rcov  # Remove rcov products for rcov
rake spec:rcov          # Run all specs in spec directory with RCov (excluding plugin specs)
About these ads

5 Comments

  1. Interesting. That sort of thing should not be so hard to find out.

    Thanks for the tip. Unfortunately, for me, rake spec:rcov segfaults on my mac pro. I’ll have to try to figure out what’s up with that…

    Comment by Evan Dorn — 2009-05-16 @ 11:18

  2. This is a known problem with rcov on some systems. Try the suggested solution by installing this rcov fork (maintained by Relevance).

    Comment by mhartl — 2009-05-16 @ 11:51

  3. There’s always the -T option with rack which will list all of the tasks, as illustrated below.

    $ rake -T

    Comment by Nathan — 2010-09-3 @ 01:04

    • I could read a book about this without finding such real-world apopracehs!

      Comment by Jakayla — 2011-10-2 @ 12:03

  4. Bear in mind, as I blogged about here, that “RCov does not, and will not support C based Ruby 1.9.x implementations due to significant changes between 1.8 and 1.9″, to quote the apparent team lead. As agile developers, we’re supposed to embrace change; not only in our projects, but in our tools as well.

    Comment by Jeff Dickey — 2011-12-20 @ 10:31


RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

The Shocking Blue Green Theme. Create a free website or blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 76 other followers

%d bloggers like this: