class Rote::RCovTask
Rake
task library that allows code-coverage reports to be generated using RCov (eigenclass.org/hiki.rb?rcov).
Attributes
Set of glob patterns that should be excluded from the test run. [none]
If false
, the task will emit a warning rather than failing when Rcov command fails. [true]
Extra load-paths that should be appended to $: when running the test cases. [none]
If true, RCov will generate colorblind-safe output. [false]
The path to which RCov should generate output [./coverage]
Determines whether bogo-profiling is enabled [false]
The color scale range for profiling output (dB) [not used]
The command that runs RCov ['rcov']
A Rake::FileList
holding Ruby source filenames that are included in the coverage report. This is optional - RCov finds sources by running them. However, if you do specify your files here then the coverage report will only be generated when they change.
The base name for the generated task [:rcov]
A Rake::FileList
holding unit-test filenames and globs. RCov will execute these to generate the report.
Public Class Methods
Create a new RCovTask
, using the supplied block for configuration, and define tasks with the specified base-name within Rake
.
Note that the named task just invokes a file task for the output directory, which is dependent on test (and source, if specified) file changes.
# File lib/rote/extratasks.rb 61 def initialize(name = :rcov, failonerror = true) # :yield: self if block_given? 62 @taskname = name 63 @rcov_cmd = 'rcov' 64 @test_files = Rake::FileList.new 65 @source_files = Rake::FileList.new 66 @load_paths = [] 67 @excludes = [] 68 @output_dir = './coverage' 69 @failonerror = true 70 71 yield self if block_given? 72 73 define(name) 74 end
Private Instance Methods
# File lib/rote/extratasks.rb 78 def define(name) 79 unless @test_files.empty? 80 if defined? CLOBBER 81 CLOBBER.include @output_dir 82 elsif defined? CLEAN 83 CLEAN.include @output_dir 84 end 85 86 (@test_files + @source_files).each { |fn| file fn } 87 88 file @output_dir => (@test_files + @source_files) do 89 cmd = "#{rcov_cmd}" << 90 "#{" -o #{@output_dir}" if @output_dir}" << 91 "#{" -I #{@load_paths.join(':')}" unless @load_paths.empty?}" << 92 "#{" -n" if @no_color}" << 93 "#{" -x #{@excludes.join(':')}" unless @excludes.empty?}" << 94 "#{" -p" if @profile}" << 95 "#{" -r #{@range}" if @range}" << 96 " " << @test_files.join(' ') 97 98 puts cmd 99 unless system(cmd) 100 if failonerror 101 fail "RCov command '#{rcov_cmd}' failed (status #{$?.exitstatus})" 102 else 103 warn "RCov command '#{rcov_cmd}' failed (status #{$?.exitstatus})" 104 end 105 end 106 end 107 108 task name => @output_dir 109 end 110 end