class Rake::TestTask
rake test TESTOPTS=“–runner=fox” # use the fox test runner
rake test TESTOPTS=“-v” # run in verbose mode
rake test TEST=just_one_file.rb # run just one test file.
rake test # run tests normally
Examples:
suite.
‘–’. This allows Test::Unit options to be passed to the test
then the given options are passed to the test process after a
If rake is invoked with a “TESTOPTS=options” command line option,
to run just one test.
filename specified on the command line. This provides an easy way
then the list of test files will be overridden to include only the
If rake is invoked with a “TEST=filename” command line option,
end
t.verbose = true
t.test_files = FileList[‘test/test*.rb’]
t.libs << “test”
Rake::TestTask.new do |t|
Example:
Create a task that runs a set of tests.
def define
def define lib_path = @libs.join(File::PATH_SEPARATOR) desc "Run tests" + (@name==:test ? "" : " for #{@name}") task @name do run_code = '' RakeFileUtils.verbose(@verbose) do run_code = case @loader when :direct "-e 'ARGV.each{|f| load f}'" when :testrb "-S testrb #{fix}" when :rake rake_loader end @ruby_opts.unshift( "-I#{lib_path}" ) @ruby_opts.unshift( "-w" ) if @warning ruby @ruby_opts.join(" ") + " \"#{run_code}\" " + file_list.collect { |fn| "\"#{fn}\"" }.join(' ') + " #{option_list}" end end self end
def file_list # :nodoc:
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
def find_file(fn) # :nodoc:
def find_file(fn) # :nodoc: $LOAD_PATH.each do |path| file_path = File.join(path, "#{fn}.rb") return file_path if File.exist? file_path end nil end
def fix # :nodoc:
def fix # :nodoc: case RUBY_VERSION when '1.8.2' find_file 'rake/ruby182_test_unit_fix' else nil end || '' end
def initialize(name=:test)
def initialize(name=:test) @name = name @libs = ["lib"] @pattern = nil @options = nil @test_files = nil @verbose = false @warning = false @loader = :rake @ruby_opts = [] yield self if block_given? @pattern = 'test/test*.rb' if @pattern.nil? && @test_files.nil? define end
def option_list # :nodoc:
def option_list # :nodoc: ENV['TESTOPTS'] || @options || "" end
def rake_loader # :nodoc:
def rake_loader # :nodoc: find_file('rake/rake_test_loader') or fail "unable to find rake test loader" end
def test_files=(list)
FileList is acceptable). If both +pattern+ and +test_files+ are
test. +list+ is expected to be an array of file names (a
Explicitly define the list of test files to be included in a
def test_files=(list) @test_files = list end