1 # |
|
2 # Testing Rake Tasks |
|
3 # $Id$ |
|
4 # |
|
5 # |
|
6 |
|
7 |
|
8 # Keep these tasks optional by handling LoadErrors with stub task |
|
9 # replacements. |
|
10 begin |
|
11 gem 'rspec', '>= 1.1.1' |
|
12 require 'spec/rake/spectask' |
|
13 |
|
14 COMMON_SPEC_OPTS = ['-c', '-f', 's'] |
|
15 |
|
16 ### Task: spec |
|
17 Spec::Rake::SpecTask.new( :spec ) do |task| |
|
18 task.spec_files = SPEC_FILES |
|
19 task.libs += [LIBDIR] |
|
20 task.spec_opts = COMMON_SPEC_OPTS |
|
21 end |
|
22 task :test => [:spec] |
|
23 |
|
24 |
|
25 namespace :spec do |
|
26 desc "Generate HTML output for a spec run" |
|
27 Spec::Rake::SpecTask.new( :html ) do |task| |
|
28 task.spec_files = SPEC_FILES |
|
29 task.spec_opts = ['-f','h', '-D'] |
|
30 end |
|
31 |
|
32 desc "Generate plain-text output for a CruiseControl.rb build" |
|
33 Spec::Rake::SpecTask.new( :text ) do |task| |
|
34 task.spec_files = SPEC_FILES |
|
35 task.spec_opts = ['-f','p'] |
|
36 end |
|
37 end |
|
38 rescue LoadError => err |
|
39 task :no_rspec do |
|
40 $stderr.puts "Testing tasks not defined: RSpec rake tasklib not available: %s" % |
|
41 [ err.message ] |
|
42 end |
|
43 |
|
44 task :spec => :no_rspec |
|
45 namespace :spec do |
|
46 task :autotest => :no_rspec |
|
47 task :html => :no_rspec |
|
48 task :text => :no_rspec |
|
49 end |
|
50 end |
|
51 |
|
52 |
|
53 |
|
54 ### RCov (via RSpec) tasks |
|
55 begin |
|
56 gem 'rcov' |
|
57 gem 'rspec', '>= 1.1.1' |
|
58 |
|
59 COVERAGE_TARGETDIR = STATICWWWDIR + 'coverage' |
|
60 |
|
61 RCOV_OPTS = ['--exclude', SPEC_EXCLUDES, '--xrefs', '--save'] |
|
62 |
|
63 ### Task: coverage (via RCov) |
|
64 ### Task: spec |
|
65 desc "Build test coverage reports" |
|
66 Spec::Rake::SpecTask.new( :coverage ) do |task| |
|
67 task.spec_files = SPEC_FILES |
|
68 task.libs += [LIBDIR] |
|
69 task.spec_opts = ['-f', 'p', '-b'] |
|
70 task.rcov_opts = RCOV_OPTS |
|
71 task.rcov = true |
|
72 end |
|
73 |
|
74 |
|
75 task :rcov => [:coverage] do; end |
|
76 |
|
77 ### Other coverage tasks |
|
78 namespace :coverage do |
|
79 desc "Generate a detailed text coverage report" |
|
80 Spec::Rake::SpecTask.new( :text ) do |task| |
|
81 task.spec_files = SPEC_FILES |
|
82 task.rcov_opts = RCOV_OPTS + ['--text-report'] |
|
83 task.rcov = true |
|
84 end |
|
85 |
|
86 desc "Show differences in coverage from last run" |
|
87 Spec::Rake::SpecTask.new( :diff ) do |task| |
|
88 task.spec_files = SPEC_FILES |
|
89 task.rcov_opts = ['--text-coverage-diff'] |
|
90 task.rcov = true |
|
91 end |
|
92 |
|
93 ### Task: verify coverage |
|
94 desc "Build coverage statistics" |
|
95 VerifyTask.new( :verify => :rcov ) do |task| |
|
96 task.threshold = 85.0 |
|
97 end |
|
98 |
|
99 desc "Run RCov in 'spec-only' mode to check coverage from specs" |
|
100 Spec::Rake::SpecTask.new( :speconly ) do |task| |
|
101 task.spec_files = SPEC_FILES |
|
102 task.rcov_opts = ['--exclude', SPEC_EXCLUDES, '--text-report', '--save'] |
|
103 task.rcov = true |
|
104 end |
|
105 end |
|
106 |
|
107 task :clobber_coverage do |
|
108 rmtree( COVERAGE_TARGETDIR ) |
|
109 end |
|
110 |
|
111 rescue LoadError => err |
|
112 task :no_rcov do |
|
113 $stderr.puts "Coverage tasks not defined: RSpec+RCov tasklib not available: %s" % |
|
114 [ err.message ] |
|
115 end |
|
116 |
|
117 task :coverage => :no_rcov |
|
118 task :clobber_coverage |
|
119 task :rcov => :no_rcov |
|
120 namespace :coverage do |
|
121 task :text => :no_rcov |
|
122 task :diff => :no_rcov |
|
123 end |
|
124 task :verify => :no_rcov |
|
125 end |
|
126 |
|
127 |
|