Class: Rake::TestTask
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
TaskLib
|
|
Instance Chain:
|
|
Inherits: |
Rake::TaskLib
|
Defined in: | lib/rake/testtask.rb |
Overview
Create a task that runs a set of tests.
Example:
Rake::TestTask.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 “TESTOPTS=options” command line option, then the given options are passed to the test process after a '–'. This allows ::Test::Unit options to be passed to the test suite.
Examples:
rake test # run tests normally
rake test TEST=just_one_file.rb # run just one test file.
rake test TESTOPTS="-v" # run in verbose mode
rake test TESTOPTS="--runner=fox" # use the fox test runner
Constant Summary
Class Method Summary
-
.new(name = :test) {|_self| ... } ⇒ TestTask
constructor
Create a testing task.
Instance Attribute Summary
-
#description
rw
Description of the test task.
-
#libs
rw
List of directories to added to $LOAD_PATH before running the tests.
-
#loader
rw
Style of test loader to use.
-
#name
rw
Name of test task.
-
#options
rw
::Test options passed to the test suite.
-
#pattern
rw
Glob pattern to match test files.
-
#ruby_opts
rw
Array of commandline options to pass to ruby when running test loader.
-
#verbose
rw
True if verbose test output desired.
-
#warning
rw
Request that the tests be run with the warning flag set.
-
#test_files=(list)
writeonly
Explicitly define the list of test files to be included in a test.
Instance Method Summary
-
#define
Create the tasks defined by this task lib.
DSL - Included
#desc | Describes the next rake task. |
#directory | Declare a set of files tasks to create the given directories on demand. |
#file | Declare a file task. |
#file_create | Declare a file creation task. |
#import | Import the partial Rakefiles |
#multitask | Declare a task that performs its prerequisites in parallel. |
#namespace | Create a new rake namespace and use it for evaluating the given block. |
#rule | Declare a rule for auto-tasks. |
#task | Declare a basic task. |
FileUtilsExt - Included
#nowrite | Get/set the nowrite flag controlling output from the ::FileUtils utilities. |
#rake_check_options | Check that the options do not contain options not listed in |
#rake_merge_option | Merge the given options with the default values. |
#rake_output_message | Send the message to the default rake output (which is $stderr). |
#verbose | Get/set the verbose flag controlling output from the ::FileUtils utilities. |
#when_writing | Use this function to prevent potentially destructive ruby code from running when the |
::FileUtils - Included
#ruby | Run a Ruby interpreter with the given arguments. |
#safe_ln | Attempt to do a normal file link, but fall back to a copy if the link fails. |
#sh | Run the system command |
#split_all | Split a file path into individual directory names. |
Constructor Details
.new(name = :test) {|_self| ... } ⇒ TestTask
Create a testing task.
# File 'lib/rake/testtask.rb', line 80
def initialize(name=:test) @name = name @libs = ["lib"] @pattern = nil @options = nil @test_files = nil @verbose = false @warning = false @loader = :rake @ruby_opts = [] @description = "Run tests" + (@name == :test ? "" : " for #{@name}") yield self if block_given? @pattern = 'test/test*.rb' if @pattern.nil? && @test_files.nil? define end
Instance Attribute Details
#description (rw)
Description of the test task. (default is 'Run tests')
# File 'lib/rake/testtask.rb', line 69
attr_accessor :description
#libs (rw)
List of directories to added to $LOAD_PATH before running the tests. (default is 'lib')
# File 'lib/rake/testtask.rb', line 40
attr_accessor :libs
#loader (rw)
Style of test loader to use. Options are:
-
:rake
– ::Rake provided test loading script (default). -
:testrb
– Ruby provided test loading script. -
:direct
– Load tests using command line loader.
# File 'lib/rake/testtask.rb', line 63
attr_accessor :loader
#name (rw)
Name of test task. (default is :test
)
# File 'lib/rake/testtask.rb', line 36
attr_accessor :name
#options (rw)
::Test options passed to the test suite. An explicit TESTOPTS=opts on the command line will override this. (default is NONE)
# File 'lib/rake/testtask.rb', line 48
attr_accessor :
#pattern (rw)
Glob pattern to match test files. (default is 'test/test*.rb')
# File 'lib/rake/testtask.rb', line 55
attr_accessor :pattern
#ruby_opts (rw)
Array of commandline options to pass to ruby when running test loader.
# File 'lib/rake/testtask.rb', line 66
attr_accessor :ruby_opts
#test_files=(list) (writeonly)
# File 'lib/rake/testtask.rb', line 75
def test_files=(list) @test_files = list end
#verbose (rw)
True if verbose test output desired. (default is false)
# File 'lib/rake/testtask.rb', line 43
attr_accessor :verbose
#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.
# File 'lib/rake/testtask.rb', line 52
attr_accessor :warning
Instance Method Details
#define
Create the tasks defined by this task lib.
# File 'lib/rake/testtask.rb', line 97
def define desc @description task @name do FileUtilsExt.verbose(@verbose) do args = "#{ruby_opts_string} #{run_code} " + "#{file_list_string} #{option_list}" ruby args do |ok, status| if !ok && status.respond_to?(:signaled?) && status.signaled? raise SignalException.new(status.termsig) elsif !ok fail "Command failed with status (#{status.exitstatus}): " + "[ruby #{args}]" end end end end self end