asplake

Wednesday, January 11, 2006

Revert that Rakefile!

To my slight embarrassment, I just noticed the following comments at the top of the Rails-generated Rakefile:

# Add your own tasks in files placed in lib/tasks ending in .rake
# for example lib/tasks/switchtower.rake, and they will automatically be available to Rake

So ignore my suggestion to edit your Rakefile, and create a lib/tasks/rcov.rake instead.

Combining the tips from the past couple of posts and tidying up a bit, mine looks like this:

require 'rake/clean'

# output goes to subdirectories of this one
RCOV_OUT = "coverage"

# "rake clobber" to remove output directory (along with other generated stuff)
CLOBBER.include(RCOV_OUT)

# don't report coverage on these files
RCOV_EXCLUDE = %w(boot.rb environment.rb).join(',')

# RCOV command, run as though from the commandline.  Amend as required or perhaps move to config/environment.rb?
RCOV = "/ruby/bin/ruby /ruby/bin/rcov --no-color --exclude #{RCOV_EXCLUDE}"

desc "generate a unit test coverage report in coverage/unit; see coverage/unit/index.html afterwards"
task :coverage_units do
  sh "#{RCOV} --output #{RCOV_OUT}/unit test/unit_tests.rb"
end

desc "generate a functional test coverage report in coverage/functional; see coverage/functional/index.html afterwards"
task :coverage_functional do
  sh "#{RCOV} --output #{RCOV_OUT}/functional test/functional_tests.rb"
end

desc "generate a coverage report for unit and functional tests together in coverage/all; see coverage/all/index.html afterwards"
task :coverage_all do
  sh "#{RCOV} --output #{RCOV_OUT}/all test/all_tests.rb"
end

desc "equivalent to coverage_all"
task :coverage => [:coverage_all]

Technorati tags:

1 Comments:

  • if you pass --rails to rcov it skips config/, environment/ and vendor/

    By Blogger Jared, at 8:10 pm  

Post a Comment

<< Home