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.
Ruby 1.8.4 (especially on Win32 requires updated libraries.)
There is only one file to add to your current rails app:
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
Here’s the new tasks with
rake -T :
[… 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.
rake test:rcov and see how much of your code is really tested!!
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.