class Rote::RCovTask

Rake task library that allows code-coverage reports to be generated using RCov (eigenclass.org/hiki.rb?rcov).

Attributes

excludes[RW]

Set of glob patterns that should be excluded from the test run. [none]

failonerror[RW]

If false, the task will emit a warning rather than failing when Rcov command fails. [true]

load_paths[RW]

Extra load-paths that should be appended to $: when running the test cases. [none]

no_color[RW]

If true, RCov will generate colorblind-safe output. [false]

output_dir[RW]

The path to which RCov should generate output [./coverage]

profile[RW]

Determines whether bogo-profiling is enabled [false]

range[RW]

The color scale range for profiling output (dB) [not used]

rcov_cmd[RW]

The command that runs RCov [‘rcov’]

source_files[RW]

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.

taskname[R]

The base name for the generated task [:rcov]

test_files[RW]

A Rake::FileList holding unit-test filenames and globs. RCov will execute these to generate the report.

Public Class Methods

new(name = :rcov, failonerror = true) { |self| ... } click to toggle source

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

define(name) click to toggle source
    # 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