Coverage (rcov 0.5.0.1) in Ruby on Rails 1.1.2

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

Requirements

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

Classes

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

require 'rcov/rcovtask'

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

Rake -T

Here’s the new tasks with rake -T :

[code]
(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
[…]
[/code]

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.