How to run Rcov in the Ruby on Rails vendor directory

5 March 2009 in Ruby on Rails

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:


Spec::Rake::SpecTask.new(:rcov) 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']
end


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.

Tags: , , , ,

5 March 2009 Ruby on Rails

1 Comment to How to run Rcov in the Ruby on Rails vendor directory

  1. [...] Re-posted on the Integrum Blog [...]

  2. Integrum Tech on 5 March 2009

Leave a comment



Tweets

  • Tobi:
    ^^ shit, ok now I see it's not your fault, its (my...
  • Tobi:
    Thanks for this great writeup! btw. you missed...
  • Chris Young:
    Thanks for letting me know. I updated the link....
  • maxjgon:
    The link of the project in Github is broken!...
  • Chris Young:
    Oh I see . . . Maybe I should check out this so-c...