cover_me

An RCov-esque coverage tool for Ruby 1.9

MIT License

Stars
204
Committers
16

h1. CoverMe - Code Coverage for Ruby 1.9

Ruby 1.9(.2) is an amazing language to develop applications in. It's faster, more powerful, cleaner, and a huge improvement over Ruby 1.8.x. Because of those reasons every Ruby developer should move to this exciting new version of our language.

When making a move of this size it's important to have the right tools to help us along. Unfortunately, one of the most useful tools as a Ruby developer, RCov, does not work with Ruby 1.9.

RCov, for those unfamiliar analyzes your code and tells you which part of your code was not executed. This is INCREDIBLY useful when hooked up to your test suite. While, it's not the only metric you should use when determining how good your test coverage it, it certainly is a great first step to point out exactly which parts of your code haven't been touched at all!

Enter CoverMe.

h2. History

While working on a Ruby 1.9/Rails 3 project, and loving everything about it (except for the lack of RCov), I came across a "post":http://engineering.attinteractive.com/2010/08/code-coverage-in-ruby-1-9/ by Aaron Patterson (of Nokogiri fame). In this post he quickly outlined a very basic coverage tool using the new built-in Coverage module in Ruby 1.9.

After spending a morning playing with it, I was quickly able to grow the idea into something useful for the project. Later that day the company I was consulting for ("BiddingForGood.com":http://www.biddingforgood.com), and in particular their chief architect, Stuart Garner, told me to take a day or two and clean it up and release it for the world to use, and so here it is.

h2. Features

h3. Index Page

  • Sortable column headers (File, Lines, Lines of Code, Tested %).
  • Searching/filtering by file name.
  • Filtering by coverage percent.
  • Color coded list of files to quickly see which ones are 100% covered, > 90% covered, or less than 90% covered.
  • Large color coded average coverage percent, for quick reference.

h3. Detail Page

  • Line by line coverage report
  • Color coded lines to quickly see which lines where executed and which ones were not.
  • Side by side viewing with the corresponding test/spec file (if one exists).

h2. Use

CoverMe is pretty easy to use, and has been tested with Ruby 1.9.2 and Rails 3. First, add CoverMe to your Gemfile:

Now make sure to install the gem with Bundler:

All that's left now is to require it as the first line of your 'spec_helper.rb' or 'test_helper.rb' file:

Now the next time your run your test suite it will create a series of HTML files in the coverage folder at the root of your project. Open coverage/index.html and you're off and running.

h3. Rails 3

If you are using CoverMe with Rails 3 run the following to get the cover me Rake task:

h2. Configuration

CoverMe is easily configurable, under the covers it uses the "Configatron":http://github.com/markbates/configatron library. Here are a few quick config options you might want to play with:

h2. Contributors

  • Mark Bates
  • Andrea Campi
  • KITAITI Makoto
  • Alex Crichton
  • Leif Bladt
  • Will Marshall
  • Matthew Albright
  • Josef Sin
  • Lasse Koskela
  • Stephen Delano
  • George Anderson
  • Rob Zolkos
  • jmthomas