diff options
| author | hukl <contact@smyck.org> | 2009-02-27 12:53:03 +0100 |
|---|---|---|
| committer | hukl <contact@smyck.org> | 2009-02-27 12:53:03 +0100 |
| commit | e29d765bf6b6bae70ae332ae7c05318a8dec923e (patch) | |
| tree | f4c6dfe4207c9ca9dd84f712f9551a4dc15c7541 /lib | |
| parent | 3d6749bf2163bdd5ffbad282490c04e5c11a7eab (diff) | |
new coverage rake task - finally
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/tasks/coverage.rake | 86 |
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 @@ | |||
| 1 | require 'rcov/rcovtask' | 1 | def run_coverage(files) |
| 2 | 2 | rm_f "coverage" | |
| 3 | namespace :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 | ||
| 49 | end | ||
| 50 | |||
| 51 | namespace :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 |
| 24 | end \ No newline at end of file | 74 | end \ No newline at end of file |
