Class: Rcov::RcovTask
- Defined in:
- lib/gems/rcov-0.8.1.2.0/lib/rcov/rcovtask.rb
Overview
Create a task that runs a set of tests through rcov, generating code coverage reports.
Example:
require 'rcov/rcovtask'
Rcov::RcovTask.new do |t|
t.libs << "test"
t.test_files = FileList['test/test*.rb']
t.verbose = true
end
If rake is invoked with a “TEST=filename” command line option, then the list of test files will be overridden to include only the filename specified on the command line. This provides an easy way to run just one test.
If rake is invoked with a “RCOVOPTS=options” command line option, then the given options are passed to rcov.
If rake is invoked with a “RCOVPATH=path/to/rcov” command line option, then the given rcov executable will be used; otherwise the one in your PATH will be used.
Examples:
rake rcov # run tests normally
rake rcov TEST=just_one_file.rb # run just one test file.
rake rcov RCOVOPTS="-p" # run in profile mode
rake rcov RCOVOPTS="-T" # generate text report
Instance Attribute Summary collapse
-
#libs ⇒ Object
List of directories to added to $LOAD_PATH before running the tests.
-
#name ⇒ Object
Name of test task.
-
#output_dir ⇒ Object
Output directory for the XHTML report.
-
#pattern ⇒ Object
Glob pattern to match test files.
-
#rcov_opts ⇒ Object
Array of commandline options to pass to rcov.
-
#ruby_opts ⇒ Object
Array of commandline options to pass to ruby when running the rcov loader.
-
#verbose ⇒ Object
True if verbose test output desired.
-
#warning ⇒ Object
Request that the tests be run with the warning flag set.
Instance Method Summary collapse
-
#define ⇒ Object
Create the tasks defined by this task lib.
-
#file_list ⇒ Object
:nodoc:.
-
#initialize(name = :rcov) {|_self| ... } ⇒ RcovTask
constructor
Create a testing task.
-
#option_list ⇒ Object
:nodoc:.
-
#rcov_path ⇒ Object
:nodoc:.
-
#test_files=(list) ⇒ Object
Explicitly define the list of test files to be included in a test.
Constructor Details
#initialize(name = :rcov) {|_self| ... } ⇒ RcovTask
Create a testing task.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/gems/rcov-0.8.1.2.0/lib/rcov/rcovtask.rb', line 82 def initialize(name=:rcov) @name = name @libs = ["lib"] @pattern = nil @test_files = nil @verbose = false @warning = false @rcov_opts = ["--text-report"] @ruby_opts = [] @output_dir = "coverage" yield self if block_given? @pattern = 'test/test*.rb' if @pattern.nil? && @test_files.nil? define end |
Instance Attribute Details
#libs ⇒ Object
List of directories to added to $LOAD_PATH before running the tests. (default is ‘lib’)
50 51 52 |
# File 'lib/gems/rcov-0.8.1.2.0/lib/rcov/rcovtask.rb', line 50 def libs @libs end |
#name ⇒ Object
Name of test task. (default is :rcov)
46 47 48 |
# File 'lib/gems/rcov-0.8.1.2.0/lib/rcov/rcovtask.rb', line 46 def name @name end |
#output_dir ⇒ Object
Output directory for the XHTML report.
71 72 73 |
# File 'lib/gems/rcov-0.8.1.2.0/lib/rcov/rcovtask.rb', line 71 def output_dir @output_dir end |
#pattern ⇒ Object
Glob pattern to match test files. (default is ‘test/test*.rb’)
60 61 62 |
# File 'lib/gems/rcov-0.8.1.2.0/lib/rcov/rcovtask.rb', line 60 def pattern @pattern end |
#rcov_opts ⇒ Object
Array of commandline options to pass to rcov. An explicit RCOVOPTS=opts on the command line will override this. (default is ["--text-report"]
)
68 69 70 |
# File 'lib/gems/rcov-0.8.1.2.0/lib/rcov/rcovtask.rb', line 68 def rcov_opts @rcov_opts end |
#ruby_opts ⇒ Object
Array of commandline options to pass to ruby when running the rcov loader.
63 64 65 |
# File 'lib/gems/rcov-0.8.1.2.0/lib/rcov/rcovtask.rb', line 63 def ruby_opts @ruby_opts end |
#verbose ⇒ Object
True if verbose test output desired. (default is false)
53 54 55 |
# File 'lib/gems/rcov-0.8.1.2.0/lib/rcov/rcovtask.rb', line 53 def verbose @verbose end |
#warning ⇒ Object
Request that the tests be run with the warning flag set. E.g. warning=true implies “ruby -w” used to run the tests.
57 58 59 |
# File 'lib/gems/rcov-0.8.1.2.0/lib/rcov/rcovtask.rb', line 57 def warning @warning end |
Instance Method Details
#define ⇒ Object
Create the tasks defined by this task lib.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/gems/rcov-0.8.1.2.0/lib/rcov/rcovtask.rb', line 98 def define lib_path = @libs.join(File::PATH_SEPARATOR) actual_name = Hash === name ? name.keys.first : name unless Rake.application.last_comment desc "Analyze code coverage with tests" + (@name==:rcov ? "" : " for #{actual_name}") end task @name do run_code = '' RakeFileUtils.verbose(@verbose) do run_code = case rcov_path when nil, '' "-S rcov" else %!"#{rcov_path}"! end ruby_opts = @ruby_opts.clone ruby_opts.push( "-I#{lib_path}" ) ruby_opts.push run_code ruby_opts.push( "-w" ) if @warning ruby ruby_opts.join(" ") + " " + option_list + %[ -o "#{@output_dir}" ] + file_list.collect { |fn| %["#{fn}"] }.join(' ') end end desc "Remove rcov products for #{actual_name}" task paste("clobber_", actual_name) do rm_r @output_dir rescue nil end clobber_task = paste("clobber_", actual_name) task :clobber => [clobber_task] task actual_name => clobber_task self end |
#file_list ⇒ Object
:nodoc:
144 145 146 147 148 149 150 151 152 153 |
# File 'lib/gems/rcov-0.8.1.2.0/lib/rcov/rcovtask.rb', line 144 def file_list # :nodoc: if ENV['TEST'] FileList[ ENV['TEST'] ] else result = [] result += @test_files.to_a if @test_files result += FileList[ @pattern ].to_a if @pattern FileList[result] end end |
#option_list ⇒ Object
:nodoc:
140 141 142 |
# File 'lib/gems/rcov-0.8.1.2.0/lib/rcov/rcovtask.rb', line 140 def option_list # :nodoc: ENV['RCOVOPTS'] || @rcov_opts.join(" ") || "" end |
#rcov_path ⇒ Object
:nodoc:
136 137 138 |
# File 'lib/gems/rcov-0.8.1.2.0/lib/rcov/rcovtask.rb', line 136 def rcov_path # :nodoc: ENV['RCOVPATH'] end |
#test_files=(list) ⇒ Object
Explicitly define the list of test files to be included in a test. list
is expected to be an array of file names (a FileList is acceptable). If both pattern
and test_files
are used, then the list of test files is the union of the two.
77 78 79 |
# File 'lib/gems/rcov-0.8.1.2.0/lib/rcov/rcovtask.rb', line 77 def test_files=(list) @test_files = list end |