Parent

Rcov::RcovTask

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

Attributes

name[RW]

Name of test task. (default is :rcov)

libs[RW]

List of directories to added to $LOAD_PATH before running the tests. (default is ‘lib’)

verbose[RW]

True if verbose test output desired. (default is false)

warning[RW]

Request that the tests be run with the warning flag set. E.g. warning=true implies “ruby -w” used to run the tests.

pattern[RW]

Glob pattern to match test files. (default is ‘test/test*.rb’)

ruby_opts[RW]

Array of commandline options to pass to ruby when running the rcov loader.

rcov_opts[RW]

Array of commandline options to pass to rcov. An explicit RCOVOPTS=opts on the command line will override this. (default is ["--text-report"])

output_dir[RW]

Output directory for the XHTML report.

Public Class Methods

new(name=:rcov) click to toggle source

Create a testing task.

    # File lib/rcov/rcovtask.rb, line 82
82:     def initialize(name=:rcov)
83:       @name = name
84:       @libs = ["lib"]
85:       @pattern = nil
86:       @test_files = nil
87:       @verbose = false
88:       @warning = false
89:       @rcov_opts = ["--text-report"]
90:       @ruby_opts = []
91:       @output_dir = "coverage"
92:       yield self if block_given?
93:       @pattern = 'test/test*.rb' if @pattern.nil? && @test_files.nil?
94:       define
95:     end

Public Instance Methods

define() click to toggle source

Create the tasks defined by this task lib.

     # File lib/rcov/rcovtask.rb, line 98
 98:     def define
 99:       lib_path = @libs.join(File::PATH_SEPARATOR)
100:       actual_name = Hash === name ? name.keys.first : name
101:       unless Rake.application.last_comment
102:         desc "Analyze code coverage with tests" + 
103:           (@name==:rcov ? "" : " for #{actual_name}")
104:       end
105:       task @name do
106:         run_code = ''
107:         RakeFileUtils.verbose(@verbose) do
108:           run_code =
109:           case rcov_path
110:           when nil, ''
111:             "-S rcov"
112:           else %"#{rcov_path}"!
113:           end
114:           ruby_opts = @ruby_opts.clone
115:           ruby_opts.push( "-I#{lib_path}" )
116:           ruby_opts.push run_code
117:           ruby_opts.push( "-w" ) if @warning
118:           ruby ruby_opts.join(" ") + " " + option_list +
119:           %[ -o "#{@output_dir}" ] +
120:           file_list.collect { |fn| %["#{fn}"] }.join(' ')
121:         end
122:       end
123: 
124:       desc "Remove rcov products for #{actual_name}"
125:       task paste("clobber_", actual_name) do
126:         rm_r @output_dir rescue nil
127:       end
128: 
129:       clobber_task = paste("clobber_", actual_name)
130:       task :clobber => [clobber_task]
131: 
132:       task actual_name => clobber_task
133:       self
134:     end
test_files=(list) click to toggle source

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.

    # File lib/rcov/rcovtask.rb, line 77
77:     def test_files=(list)
78:       @test_files = list
79:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.