rcov_rails 0.1.7 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/rcov_rails/rcovtask.rb +159 -0
- data/lib/tasks/coverage.rake +9 -11
- metadata +4 -3
@@ -0,0 +1,159 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Define a task library for performing code coverage analysis of unit tests
|
4
|
+
# using rcov.
|
5
|
+
|
6
|
+
require 'rake'
|
7
|
+
require 'rake/tasklib'
|
8
|
+
|
9
|
+
module RcovRails
|
10
|
+
|
11
|
+
# A variant of Rcov::RcovTask
|
12
|
+
# which lets me switch off descriptions on auto-generated tasks
|
13
|
+
#
|
14
|
+
# Example:
|
15
|
+
#
|
16
|
+
# require 'rcov_rails/rcovtask'
|
17
|
+
#
|
18
|
+
# RcovRails::RcovTask.new do |t|
|
19
|
+
# t.libs << "test"
|
20
|
+
# t.test_files = FileList['test/test*.rb']
|
21
|
+
# t.verbose = true
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# If rake is invoked with a "TEST=filename" command line option,
|
25
|
+
# then the list of test files will be overridden to include only the
|
26
|
+
# filename specified on the command line. This provides an easy way
|
27
|
+
# to run just one test.
|
28
|
+
#
|
29
|
+
# If rake is invoked with a "RCOVOPTS=options" command line option,
|
30
|
+
# then the given options are passed to rcov.
|
31
|
+
#
|
32
|
+
# If rake is invoked with a "RCOVPATH=path/to/rcov" command line option,
|
33
|
+
# then the given rcov executable will be used; otherwise the one in your
|
34
|
+
# PATH will be used.
|
35
|
+
#
|
36
|
+
# Examples:
|
37
|
+
#
|
38
|
+
# rake rcov # run tests normally
|
39
|
+
# rake rcov TEST=just_one_file.rb # run just one test file.
|
40
|
+
# rake rcov RCOVOPTS="-p" # run in profile mode
|
41
|
+
# rake rcov RCOVOPTS="-T" # generate text report
|
42
|
+
#
|
43
|
+
class RcovTask < Rake::TaskLib
|
44
|
+
|
45
|
+
# Name of test task. (default is :rcov)
|
46
|
+
attr_accessor :name
|
47
|
+
|
48
|
+
# List of directories to added to $LOAD_PATH before running the
|
49
|
+
# tests. (default is 'lib')
|
50
|
+
attr_accessor :libs
|
51
|
+
|
52
|
+
# True if verbose test output desired. (default is false)
|
53
|
+
attr_accessor :verbose
|
54
|
+
|
55
|
+
# Request that the tests be run with the warning flag set.
|
56
|
+
# E.g. warning=true implies "ruby -w" used to run the tests.
|
57
|
+
attr_accessor :warning
|
58
|
+
|
59
|
+
# Add Rake task descriptions to the generated tasks
|
60
|
+
attr_accessor :add_descriptions
|
61
|
+
|
62
|
+
# Glob pattern to match test files. (default is 'test/test*.rb')
|
63
|
+
attr_accessor :pattern
|
64
|
+
|
65
|
+
# Array of commandline options to pass to ruby when running the rcov loader.
|
66
|
+
attr_accessor :ruby_opts
|
67
|
+
|
68
|
+
# Array of commandline options to pass to rcov. An explicit
|
69
|
+
# RCOVOPTS=opts on the command line will override this. (default
|
70
|
+
# is <tt>["--text-report"]</tt>)
|
71
|
+
attr_accessor :rcov_opts
|
72
|
+
|
73
|
+
# Output directory for the XHTML report.
|
74
|
+
attr_accessor :output_dir
|
75
|
+
|
76
|
+
# Explicitly define the list of test files to be included in a
|
77
|
+
# test. +list+ is expected to be an array of file names (a
|
78
|
+
# FileList is acceptable). If both +pattern+ and +test_files+ are
|
79
|
+
# used, then the list of test files is the union of the two.
|
80
|
+
def test_files=(list)
|
81
|
+
@test_files = list
|
82
|
+
end
|
83
|
+
|
84
|
+
# Create a testing task.
|
85
|
+
def initialize(name=:rcov)
|
86
|
+
@name = name
|
87
|
+
@libs = ["lib"]
|
88
|
+
@pattern = nil
|
89
|
+
@test_files = nil
|
90
|
+
@verbose = false
|
91
|
+
@warning = false
|
92
|
+
@add_descriptions = true
|
93
|
+
@rcov_opts = ["--text-report"]
|
94
|
+
@ruby_opts = []
|
95
|
+
@output_dir = "coverage"
|
96
|
+
yield self if block_given?
|
97
|
+
@pattern = 'test/test*.rb' if @pattern.nil? && @test_files.nil?
|
98
|
+
define
|
99
|
+
end
|
100
|
+
|
101
|
+
# Create the tasks defined by this task lib.
|
102
|
+
def define
|
103
|
+
lib_path = @libs.join(File::PATH_SEPARATOR)
|
104
|
+
actual_name = Hash === name ? name.keys.first : name
|
105
|
+
if add_descriptions && !Rake.application.last_comment
|
106
|
+
desc "Analyze code coverage with tests" +
|
107
|
+
(@name==:rcov ? "" : " for #{actual_name}")
|
108
|
+
end
|
109
|
+
task @name do
|
110
|
+
run_code = ''
|
111
|
+
RakeFileUtils.verbose(@verbose) do
|
112
|
+
run_code =
|
113
|
+
case rcov_path
|
114
|
+
when nil, ''
|
115
|
+
"-S rcov"
|
116
|
+
else %!"#{rcov_path}"!
|
117
|
+
end
|
118
|
+
ruby_opts = @ruby_opts.clone
|
119
|
+
ruby_opts.push( "-I#{lib_path}" )
|
120
|
+
ruby_opts.push run_code
|
121
|
+
ruby_opts.push( "-w" ) if @warning
|
122
|
+
ruby ruby_opts.join(" ") + " " + option_list +
|
123
|
+
%[ -o "#{@output_dir}" ] +
|
124
|
+
file_list.collect { |fn| %["#{fn}"] }.join(' ')
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
desc "Remove rcov products for #{actual_name}" if add_descriptions
|
129
|
+
task paste("clobber_", actual_name) do
|
130
|
+
rm_r @output_dir rescue nil
|
131
|
+
end
|
132
|
+
|
133
|
+
clobber_task = paste("clobber_", actual_name)
|
134
|
+
task :clobber => [clobber_task]
|
135
|
+
|
136
|
+
task actual_name => clobber_task
|
137
|
+
self
|
138
|
+
end
|
139
|
+
|
140
|
+
def rcov_path # :nodoc:
|
141
|
+
ENV['RCOVPATH']
|
142
|
+
end
|
143
|
+
|
144
|
+
def option_list # :nodoc:
|
145
|
+
ENV['RCOVOPTS'] || @rcov_opts.join(" ") || ""
|
146
|
+
end
|
147
|
+
|
148
|
+
def file_list # :nodoc:
|
149
|
+
if ENV['TEST']
|
150
|
+
FileList[ ENV['TEST'] ]
|
151
|
+
else
|
152
|
+
result = []
|
153
|
+
result += @test_files.to_a if @test_files
|
154
|
+
result += FileList[ @pattern ].to_a if @pattern
|
155
|
+
FileList[result]
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
data/lib/tasks/coverage.rake
CHANGED
@@ -11,14 +11,12 @@
|
|
11
11
|
|
12
12
|
begin
|
13
13
|
|
14
|
-
require
|
14
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "rcov_rails/rcovtask"))
|
15
15
|
|
16
|
-
def coverage_task(name, aspects,
|
16
|
+
def coverage_task(name, aspects, task_description)
|
17
17
|
aspect_tasks = aspects.map{ |aspect| "test:coverage:_#{aspect}" }
|
18
18
|
|
19
|
-
|
20
|
-
desc options[:description]
|
21
|
-
end
|
19
|
+
desc(task_description)
|
22
20
|
|
23
21
|
task name => ["test:coverage:reset"] + aspect_tasks + ["test:coverage:generate"] do
|
24
22
|
if PLATFORM['darwin']
|
@@ -34,14 +32,14 @@ begin
|
|
34
32
|
namespace :coverage do
|
35
33
|
|
36
34
|
["units", "functionals", "integration"].each do |scope|
|
37
|
-
|
35
|
+
RcovRails::RcovTask.new("_#{scope}" => "db:test:prepare") do |t|
|
38
36
|
t.libs << "test"
|
39
37
|
t.test_files = Dir["test/#{scope.singularize}/**/*_test.rb"]
|
40
|
-
t.add_descriptions = false
|
38
|
+
t.add_descriptions = false
|
41
39
|
t.rcov_opts = ["--no-html", "--aggregate coverage.data", "--exclude '^(?!(app|lib))'"]
|
42
40
|
end
|
43
41
|
|
44
|
-
coverage_task(scope, [scope],
|
42
|
+
coverage_task(scope, [scope], "run the #{scope} tests with coverage")
|
45
43
|
end
|
46
44
|
|
47
45
|
task :reset do
|
@@ -49,16 +47,16 @@ begin
|
|
49
47
|
rm_f "coverage"
|
50
48
|
end
|
51
49
|
|
52
|
-
|
50
|
+
RcovRails::RcovTask.new(:generate) do |t|
|
53
51
|
t.libs << "test"
|
54
52
|
t.test_files = []
|
55
|
-
t.add_descriptions = false
|
53
|
+
t.add_descriptions = false
|
56
54
|
t.rcov_opts = ["--html", "--aggregate coverage.data", "--exclude '^(?!(app|lib))'"]
|
57
55
|
end
|
58
56
|
|
59
57
|
end
|
60
58
|
|
61
|
-
coverage_task(:coverage, [:units, :functionals, :integration])
|
59
|
+
coverage_task(:coverage, [:units, :functionals, :integration], "run all the tests with coverage")
|
62
60
|
|
63
61
|
end
|
64
62
|
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 8
|
9
|
+
version: 0.1.8
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Matthew Rudy Jacobs
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-04-13 00:00:00 +08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -41,6 +41,7 @@ files:
|
|
41
41
|
- MIT-LICENSE
|
42
42
|
- README
|
43
43
|
- lib/rcov_rails/railtie.rb
|
44
|
+
- lib/rcov_rails/rcovtask.rb
|
44
45
|
- lib/rcov_rails.rb
|
45
46
|
- lib/tasks/coverage.rake
|
46
47
|
has_rdoc: true
|