1
|
### From http://svn.geekdaily.org/public/rails/plugins/generally_useful/tasks/coverage_via_rcov.rake
|
2
|
|
3
|
namespace :test do
|
4
|
namespace :scm do
|
5
|
namespace :setup do
|
6
|
desc "Creates directory for test repositories"
|
7
|
task :create_dir do
|
8
|
FileUtils.mkdir_p Rails.root + '/tmp/test'
|
9
|
end
|
10
|
|
11
|
supported_scms = [:subversion, :cvs, :bazaar, :mercurial, :git, :darcs, :filesystem]
|
12
|
|
13
|
desc "Creates a test subversion repository"
|
14
|
task :subversion => :create_dir do
|
15
|
repo_path = "tmp/test/subversion_repository"
|
16
|
system "svnadmin create #{repo_path}"
|
17
|
system "gunzip < test/fixtures/repositories/subversion_repository.dump.gz | svnadmin load #{repo_path}"
|
18
|
end
|
19
|
|
20
|
(supported_scms - [:subversion]).each do |scm|
|
21
|
desc "Creates a test #{scm} repository"
|
22
|
task scm => :create_dir do
|
23
|
system "gunzip < test/fixtures/repositories/#{scm}_repository.tar.gz | tar -xv -C tmp/test"
|
24
|
end
|
25
|
end
|
26
|
|
27
|
desc "Creates all test repositories"
|
28
|
task :all => supported_scms
|
29
|
end
|
30
|
end
|
31
|
end
|
32
|
|
33
|
### Inspired by http://blog.labratz.net/articles/2006/12/2/a-rake-task-for-rcov
|
34
|
begin
|
35
|
require 'rcov/rcovtask'
|
36
|
|
37
|
rcov_options = "--rails --aggregate test/coverage.data --exclude '/gems/'"
|
38
|
|
39
|
namespace :test do
|
40
|
desc "Aggregate code coverage for all tests"
|
41
|
Rcov::RcovTask.new('coverage') do |t|
|
42
|
t.libs << 'test'
|
43
|
t.test_files = FileList['test/{unit,integration,functional}/*_test.rb']
|
44
|
t.verbose = true
|
45
|
t.rcov_opts << rcov_options
|
46
|
end
|
47
|
|
48
|
namespace :coverage do
|
49
|
desc "Delete coverage test data"
|
50
|
task :clean do
|
51
|
rm_f "test/coverage.data"
|
52
|
rm_rf "test/coverage"
|
53
|
end
|
54
|
|
55
|
desc "Aggregate code coverage for all tests with HTML output"
|
56
|
Rcov::RcovTask.new('html') do |t|
|
57
|
t.libs << 'test'
|
58
|
t.test_files = FileList['test/{unit,integration,functional}/*_test.rb']
|
59
|
t.output_dir = "test/coverage"
|
60
|
t.verbose = true
|
61
|
t.rcov_opts << rcov_options
|
62
|
end
|
63
|
|
64
|
desc "Open the HTML coverage report"
|
65
|
task :show_results do
|
66
|
system "open test/coverage/index.html"
|
67
|
end
|
68
|
|
69
|
task :full => "test:coverage:clean"
|
70
|
task :full => "test:coverage:html"
|
71
|
task :full => "test:coverage:show_results"
|
72
|
end
|
73
|
end
|
74
|
rescue LoadError
|
75
|
# rcov not available
|
76
|
end
|