Skip to content

Instantly share code, notes, and snippets.

@dvgica
Created November 4, 2011 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dvgica/1340469 to your computer and use it in GitHub Desktop.
Save dvgica/1340469 to your computer and use it in GitHub Desktop.
Rake tasks for running your Rails tests with Rcov
# modified from original by Tim Su at http://www.betaful.com/2010/11/rails-3-rcov-test-coverage/
# place this in lib/tasks/
namespace :coverage do
task :clean do
rm_rf "test/coverage"
rm_f "test/coverage.data"
Rcov = "rcov --rails --aggregate coverage.data -Ilib \
--text-summary -x 'bundler/*,gems/*'"
end
def display_coverage
system("sensible-browser test/coverage/index.html")
end
desc 'Measures unit test coverage'
task :unit => :clean do
system("cd test && find unit -name \*test.rb -print0 | xargs -0 #{Rcov} --html")
display_coverage
end
desc 'Measures functional test coverage'
task :functional => :clean do
system("cd test && find functional -name \*test.rb -print0 | xargs -0 #{Rcov} --html")
display_coverage
end
desc 'Measures integration test coverage'
task :integration => :clean do
system("cd test && find integration -name \*test.rb -print0 | xargs -0 #{Rcov} --html")
display_coverage
end
desc 'All unit test coverage'
task :all => :clean do
system("cd test && find -name \*test.rb -print0 | xargs -0 #{Rcov} --html")
display_coverage
end
end
task :coverage do
Rake::Task["coverage:all"].invoke
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment