How to run Rcov in the Ruby on Rails vendor directory

Originally posted at:

We have a long-term project at Integrum which stores rails apps as extensions in the vendor directory. For the longest time we have not been able to get test coverage stats on these extensions. When we ran rcov it would run our specs – but when we opened the index.html file in the coverage folder, none of our extension code had been analyzed.

It turns out that rcov by default ignores the vendor directory – which makes sense generally. So it turns out you have to be explicit when you want to run rcov on anything in the folder: do |task|
    task.rcov           = args[:rcov]
    task.spec_opts  = @spec_opts
    extension_path =  “vendor/other_extensions/#{ENV['EXTENSION']}”
    task.spec_files  = ["#{extension_path}/spec/**/*_spec.rb"]
    task.rcov_opts  = ["--include-file #{extension_path}/",
                                 '--exclude app,config,lib,spec']

The important thing here is

task.rcov_opts = [”–include-file . . .

This line lets Rcov know to run stats on that folder, even though it is part of vendor. Hope that helps.

Step up to the mic.

Your email address will not be published.