summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/tasks/coverage.rake86
1 files changed, 68 insertions, 18 deletions
diff --git a/lib/tasks/coverage.rake b/lib/tasks/coverage.rake
index b70f813..953cf7a 100644
--- a/lib/tasks/coverage.rake
+++ b/lib/tasks/coverage.rake
@@ -1,24 +1,74 @@
1require 'rcov/rcovtask' 1def run_coverage(files)
2 2 rm_f "coverage"
3namespace :test do 3 rm_f "coverage.data"
4 namespace :coverage do 4
5 desc "Delete aggregate coverage data." 5 # turn the files we want to run into a string
6 task(:clean) { rm_f "coverage.data" } 6 if files.empty?
7 puts "No files were specified for testing"
8 return
7 end 9 end
8 10
9 desc 'Aggregate code coverage for unit, functional and integration tests' 11 files = files.join(" ")
10 task :coverage => "test:coverage:clean" 12
11 %w[unit functional integration].each do |target| 13 if PLATFORM =~ /darwin/
12 namespace :coverage do 14 exclude = '--exclude "gems/*" --exclude "Library/Frameworks/*"'
13 Rcov::RcovTask.new(target) do |t| 15 else
14 t.libs << "test" 16 exclude = '--exclude "rubygems/*"'
15 t.test_files = FileList["test/#{target}/*_test.rb"] 17 end
16 t.output_dir = "test/coverage/#{target}" 18 # rake test:units:rcov SHOW_ONLY=models,controllers,lib,helpers
17 t.verbose = true 19 # rake test:units:rcov SHOW_ONLY=m,c,l,h
18 t.rcov_opts << '--rails --aggregate coverage.data' 20 if ENV['SHOW_ONLY']
21 params = String.new
22 show_only = ENV['SHOW_ONLY'].to_s.split(',').map{|x|x.strip}
23 if show_only.any?
24 reg_exp = []
25 for show_type in show_only
26 reg_exp << case show_type
27 when 'm', 'models' : 'app\/models'
28 when 'c', 'controllers' : 'app\/controllers'
29 when 'h', 'helpers' : 'app\/helpers'
30 when 'l', 'lib' : 'lib'
31 else
32 show_type
33 end
34 end
35 reg_exp.map!{ |m| "(#{m})" }
36 params << " --exclude \"^(?!#{reg_exp.join('|')})\""
19 end 37 end
38 exclude = exclude + params
39 end
40
41
42 rcov = "rcov --rails -Ilib:test --sort coverage --text-report #{exclude} --no-validator-links"
43 puts
44 puts
45 puts "Running tests..."
46 cmd = "#{rcov} #{files}"
47 puts cmd
48 sh cmd
49end
50
51namespace :test do
52
53 desc "Measures unit, functional, and integration test coverage"
54 task :coverage do
55 run_coverage Dir["test/unit/**/*.rb", "test/functional/**/*.rb", "test/integration/**/*.rb"]
20 end 56 end
21 57
22 task :coverage => "test:coverage:#{target}" 58 namespace :coverage do
59 desc "Runs coverage on unit tests"
60 task :units do
61 run_coverage Dir["test/unit/**/*.rb"]
62 end
63
64 desc "Runs coverage on functional tests"
65 task :functionals do
66 run_coverage Dir["test/functional/**/*.rb"]
67 end
68
69 desc "Runs coverage on integration tests"
70 task :integration do
71 run_coverage Dir["test/integration/**/*.rb"]
72 end
23 end 73 end
24end \ No newline at end of file 74end \ No newline at end of file