Coverage (rcov in Ruby on Rails 1.1.2

rcov code coverage for Ruby released by Mauricio Fernandez contains all that is needed to produce code-coverage reporting in Rails.


Ruby 1.8.4 (especially on Win32 requires updated libraries.)
Rails 1.1.2


There is only one file to add to your current rails app: lib/tasks/coverage.rake

require 'rcov/rcovtask'

namespace :test do do |t|
    t.libs << “test”
    t.test_files = FileList['test/unit/*.rb', 'test/functional/*.rb']
    t.output_dir = 'test/coverage'
    t.verbose = true

Rake -T

Here’s the new tasks with rake -T :

(in C:/radrailsworkspace/pimki/trunk)
[... snip standard tasks ...]
rake test:clobber_rcov         # Remove rcov products for rcov
rake test:rcov                 # Analyze code coverage with tests

The default taskname for the RcovTask instance is ‘rcov’. Rcov automatically creates the ‘clobber_’ task that is basically a rm_rf on the RcovTask#output_dir.

Cover it

Run rake test:rcov and see how much of your code is really tested!!

Report Coverage

The end of your rake run will contain a pretty-print text report of the rcov. Also, you can navigate to ./test/coverage/index.html to see the graphic report. See the docs for more info.