public
Last active

Shoulda and rcov the right way

  • Download Gist
rcov.rake
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
#
# 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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.