summaryrefslogtreecommitdiffstats
path: root/lib/tasks/testing.rake
blob: 42f756f68c5f2548da793dd7130e439605b955da (plain)
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
### From http://svn.geekdaily.org/public/rails/plugins/generally_useful/tasks/coverage_via_rcov.rake

### Inspired by http://blog.labratz.net/articles/2006/12/2/a-rake-task-for-rcov
begin
  require 'rcov/rcovtask'

  rcov_options = "--rails --aggregate test/coverage.data --exclude '/gems/'"

  namespace :test do 
    desc "Aggregate code coverage for all tests"
    Rcov::RcovTask.new('coverage') do |t|
      t.libs << 'test'
      t.test_files = FileList['test/{unit,integration,functional}/*_test.rb']
      t.verbose = true
      t.rcov_opts << rcov_options
    end

    namespace :coverage do
      desc "Delete coverage test data"
      task :clean do
        rm_f "test/coverage.data"
        rm_rf "test/coverage"
      end

      desc "Aggregate code coverage for all tests with HTML output"
      Rcov::RcovTask.new('html') do |t|
        t.libs << 'test'
        t.test_files = FileList['test/{unit,integration,functional}/*_test.rb']
        t.output_dir = "test/coverage"
        t.verbose = true
        t.rcov_opts << rcov_options
      end
    
      desc "Open the HTML coverage report"
      task :show_results do
        system "open test/coverage/index.html"
      end

      task :full => "test:coverage:clean"
      task :full => "test:coverage:html"
      task :full => "test:coverage:show_results"
    end
  end
rescue LoadError
  # rcov not available
end