Rcov

May 23rd, 2007

I really like using rcov for my testing. It helps show those little places in your code that could use more tests. However, it gets annoying to keep writing out the rcov test/unit/* rcov test/functional/*. Perhaps there is a better way to run those that is quicker, I’m not sure, but I wrote a little rake task to take care of it for me. Here it is:

1
2
3
4
5
6
7
8
9
namespace :test do
  desc "Run rcov for both unit and functional tests."
  task :rcov => :environment do
    return unless %w[development test staging].include? RAILS_ENV
    `rcov test/unit/*`
    `rcov test/functional/*`
    `open -a firefox #[RAILS_ROOT}/coverage/index.html`
  end
end

That “open -a” line will open up firefox to the index.html page that was just created so you can view your test coverage. It is OSX specific. To for windows, just use start firefox and I assume you can pass the url as I’ve done above, but I’m not quite sure – I haven’t tested it.

Sorry, comments are closed for this article.