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)

2 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


RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.