Class: Test::Rake::TestTask

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/rubytest/rake.rb

Overview

Define a rake task that runs tests.

require 'rubytest/rake'

Test::Rake::TestTask.new do |run|
run.loadpath 'lib'
run.files << 'test/*_test.rb'
end

The block is given the task's Test::Config, the same object that Test.configure yields. Without any files, the task runs whichever of DEFAULT_TESTS match, and without a load path it adds lib.

The TEST environment variable selects the tests to run for one invocation, in place of the task's own: rake test TEST=test/foo_test.rb. Separate several files or globs with : or ;.

Where the platform can fork, tests run in a child process, so that what they load doesn't stay in Rake's. If the run is unsuccessful the task exits with status 1.

Constant Summary collapse

DEFAULT_TESTS =

Globs used to find test files when the task is given none.

[
  'test/**/case_*.rb',
  'test/**/*_case.rb',
  'test/**/test_*.rb',
  'test/**/*_test.rb'
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = 'test', desc = 'run tests', &block) ⇒ TestTask

Initialize new Rake::TestTask instance.



56
57
58
59
60
61
62
63
64
65
# File 'lib/rubytest/rake.rb', line 56

def initialize(name='test', desc='run tests', &block)
  @name = (name || 'test').to_s
  @desc = desc

  @config = Test::Config.new

  block.call(@config) if block

  define_task
end

Instance Attribute Details

#config ⇒ Config (readonly)

Test run configuration.

Returns:



52
53
54
# File 'lib/rubytest/rake.rb', line 52

def config
  @config
end

#name ⇒ String (readonly)

Name of the task.

Returns:



47
48
49
# File 'lib/rubytest/rake.rb', line 47

def name
  @name
end

Instance Method Details

#define_task ⇒ Object

Define rake task for testing.

Returns:

  • nothing



70
71
72
73
74
75
# File 'lib/rubytest/rake.rb', line 70

def define_task
  desc @desc
  task @name do
    run
  end
end

#run ⇒ Object

Run tests, in a child process if possible, otherwise in this one. Exits with status 1 if the run is unsuccessful.

Returns:

  • nothing



81
82
83
84
85
# File 'lib/rubytest/rake.rb', line 81

def run
  prepare
  success = Process.respond_to?(:fork) ? run_in_fork : run_here
  exit 1 unless success
end