rcov_rake.txt

rcov rake file - surajit dey, 2011-07-05 11:31

Download (2.51 KB)

 
1
begin
2
  require 'rake'
3
  require 'rake/testtask'
4
  require 'rake/rdoctask'
5
  require 'tasks/rails'
6
  require 'cucumber/rake/task'
7
  
8
  def cleanup
9
    rm_f 'coverage'
10
    rm_f 'coverage.data'
11
  end
12
  
13
  # def prepare_test_db
14
  #   cmd = "rake db:test:prepare"
15
  #   puts cmd
16
  #   sh cmd
17
  # end
18
  
19
  def run_coverage(files)
20
    # turn the files we want to run into a  string
21
    if files.length == 0
22
      puts "No files were specified for testing"
23
      return
24
    end
25

    
26
    files = files.join(" ")
27

    
28
    if PLATFORM =~ /darwin/
29
      exclude = '--exclude "gems/*"'
30
    else
31
      exclude = '--exclude "rubygems/*"'
32
    end
33

    
34
    rcov = "rcov --rails -Ilib:test --sort coverage --text-report #{exclude}  --aggregate coverage.data"
35
    cmd = "#{rcov} #{files}"
36
    puts cmd
37
    sh cmd
38
  end
39
  
40
  def browse
41
    if PLATFORM =~ /darwin/
42
      system("open coverage/index.html") if PLATFORM['darwin']
43
    end
44
  end
45
  
46
  namespace :rcov do
47
    # Cucumber::Rake::Task.new(:cucumber) do |t|
48
    #   t.rcov = true
49
    #   t.rcov_opts = %w{ --rails --text-report --include-file vendor\/plugins\/redmine_crri_support --exclude config\/,features\/.+\/,^app\/,^lib\/,osx\/objc,gems\/ }
50
    #   t.rcov_opts << %[-o "features_rcov"]
51
    # end
52
    
53
    desc "Measures unit, functional test coverage"
54
    task :all do
55
      cleanup
56
      # prepare_test_db
57
      # Rake::Task["redmine:crri_support:rcov:cucumber"].invoke
58
      # Rake::Task["redmine:crri_support:rcov"].invoke
59
      rcov_opts = %w{ --rails --text-report --include-file vendor\/plugins\/redmine_crri_support --exclude config\/,features\/.+\/,^app\/,^lib\/,osx\/objc,gems\/ }
60
      run_coverage Dir["vendor/plugins/redmine_crri_support/test/unit/*.rb", "vendor/plugins/redmine_crri_support/test/functional/*.rb"]
61
      browse
62
    end
63
    
64
    desc "Runs coverage on unit tests"
65
    task :units do
66
      
67
      cleanup
68
      # prepare_test_db
69
      # run_coverage Dir["#{Rails.root.to_s}/vendor/plugins/redmine_crri_support/test/unit/*.rb"]
70
      rcov_opts = %w{ --rails --text-report --include-file vendor\/plugins\/redmine_crri_support --exclude config\/,features\/.+\/,^app\/,^lib\/,osx\/objc,gems\/ }
71
      run_coverage Dir["File.dirname(__FILE__)}/../test/unit/*.rb"]
72
      browse
73
    end
74
    
75
    desc "Runs coverage on functional tests"
76
    task :functionals do
77
      cleanup
78
      # prepare_test_db
79
      run_coverage Dir["File.dirname(__FILE__)}/../test/functional/**/*.rb"]
80
      browse
81
    end
82
    
83
  end
84
  
85
rescue LoadError => e
86
  desc 'Rcov rake task not available'
87
  task :rcov do
88
    abort e.message
89
  end
90
end