Created
March 20, 2009 16:43
-
-
Save rubysolo/82430 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# based off of http://eigenclass.org/hiki.rb?rcov+FAQ#l3 | |
require 'rcov/rcovtask' | |
namespace :test do | |
namespace :coverage do | |
desc "Delete aggregate coverage data." | |
task(:clean) { rm_f "test/coverage/coverage.data" } | |
%w[units functionals integration].each do |target| | |
Rcov::RcovTask.new(target) do |t| | |
t.libs << "test" | |
t.test_files = FileList["test/#{target.sub(/s\Z/, '')}/**/*_test.rb"] | |
t.output_dir = "test/coverage/#{target}" | |
t.verbose = true | |
t.rcov_opts << '--rails --exclude "\\w*_test_helper.rb" --exclude "/Library/*" --aggregate test/coverage/coverage.data' | |
end | |
task target => 'test:coverage:clean' | |
end | |
Rcov::RcovTask.new('report') do |t| | |
t.test_files = FileList["lib/noop.rb"] | |
t.output_dir = "test/coverage/report" | |
t.verbose = true | |
t.rcov_opts = ['--rails --exclude "\\w*_test_helper.rb" --exclude "/Library/*" --text-summary --html --aggregate test/coverage/coverage.data'] | |
end | |
Rake::Task['test:coverage:report'].comment = 'Create report from existing coverage data' | |
Rake::Task['test:coverage:clobber_report'].comment = 'Remove rcov products for aggregate report' | |
end | |
desc 'Aggregate code coverage for unit, functional and integration tests' | |
task :coverage => 'test:coverage:clean' do | |
old_rcov_opts = ENV['RCOVOPTS'] | |
ENV['RCOVOPTS'] = '--rails --no-html --exclude "\\w*_test_helper.rb" --exclude "/Library/*" --text-summary --aggregate test/coverage/coverage.data' | |
got_error = false | |
Rake::Task["test:coverage:units"].invoke rescue got_error = true | |
Rake::Task["test:coverage:functionals"].invoke rescue got_error = true | |
Rake::Task["test:coverage:integration"].invoke rescue got_error = true | |
ENV['RCOVOPTS'] = old_rcov_opts | |
Rake::Task["test:coverage:report"].invoke | |
if PLATFORM['darwin'] | |
system('open test/coverage/report/index.html') | |
else | |
puts 'open test/coverage/report/index.html in your web browser to view the results' | |
end | |
raise "Test failures" if got_error | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment