Skip to content

Instantly share code, notes, and snippets.

@williamn
Created June 8, 2010 10:25
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 williamn/429844 to your computer and use it in GitHub Desktop.
Save williamn/429844 to your computer and use it in GitHub Desktop.
Shoulda and rcov the right way
#
# Original blog here http://honoluluhacker.com/2009/11/19/install-shoulda-and-rcov-the-right-way/
# Update your test/test_helper.rb, add
# require 'shoulda/rails'
#
require File.expand_path(File.dirname(__FILE__) + "/../../config/boot")
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
require 'tasks/rails'
require 'shoulda/tasks'
def run_coverage(files)
rm_f "coverage"
rm_f "coverage.data"
# turn the files we want to run into a string
if files.length == 0
puts "No files were specified for testing"
return
end
files = files.join(" ")
if PLATFORM =~ /darwin/
exclude = '--exclude "gems/*"'
else
exclude = '--exclude "rubygems/*"'
end
rcov = "rcov --rails -Ilib:test --sort coverage --text-report #{exclude} --aggregate coverage.data"
cmd = "#{rcov} #{files}"
puts cmd
sh cmd
end
namespace :test do
desc "Measures unit, functional, and integration test coverage"
task :coverage do
run_coverage Dir["test/**/*.rb"]
end
namespace :coverage do
desc "Runs coverage on unit tests"
task :units do
run_coverage Dir["test/unit/**/*.rb"]
end
desc "Runs coverage on functional tests"
task :functionals do
run_coverage Dir["test/functional/**/*.rb"]
end
desc "Runs coverage on integration tests"
task :integration do
run_coverage Dir["test/integration/**/*.rb"]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment