Class: Rake::TestTask

Inherits:
Object
  • Object
show all
Defined in:
lib/knut_tools/rake/testtask.rb

Overview

Modify Rake::TestTask to allow tests in different directories.

This may be necessary, if you have to test, if files are created correct.

Example:

Rake::TestTask.new(:test_ok) do |t|
    t.dir = $testdir
    t.test_files = $testfile
    t.verbose = true
end

$testfile must be located relative to $testdir.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dirObject

Directory to find and start the tests.



30
31
32
# File 'lib/knut_tools/rake/testtask.rb', line 30

def dir
  @dir
end

Instance Method Details

#defineObject

Create the tasks defined by this task lib.

Redefined to run the tests from another directory. The original definition was rake version 0.8.7.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/knut_tools/rake/testtask.rb', line 38

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
      #Change to directory if requested.
      Dir.chdir(@dir ? @dir : '.'){  # ##add knut##
        ruby @ruby_opts.join(" ") +
          " \"#{run_code}\" " +
          file_list.collect { |fn| "\"#{fn}\"" }.join(' ') +
          " #{option_list}"
        } # ##add knut##
      end
  end
  self
end