Class: Spec::Rake::SpecTask

Class | Spec::Rake::SpecTask
In: | lib/spec/rake/spectask.rb
Parent: | ::Rake::TaskLib

A Rake task that runs a set of specs.

Example:

      Spec::Rake::SpecTask.new do |t|
        t.warning = true
        t.rcov = true
      end

This will create a task that can be run with:

      rake spec

If rake is invoked with a "SPEC=filename" command line option, then the list of spec files will be overridden to include only the filename specified on the command line. This provides an easy way to run just one spec.

If rake is invoked with a "SPEC_OPTS=options" command line option, then the given options will override the value of the `spec_opts` attribute.

If rake is invoked with a "RCOV_OPTS=options" command line option, then the given options will override the value of the `rcov_opts` attribute.

Examples:

      rake spec                                      # run specs normally
      rake spec SPEC=just_one_file.rb                # run just one spec file.
      rake spec SPEC_OPTS="--diff"                   # enable diffing
      rake spec RCOV_OPTS="--aggregate myfile.txt"   # see rcov --help for details

Each attribute of this task may be a proc. This allows for lazy evaluation, which is sometimes handy if you want to defer the evaluation of an attribute value until the task is run (as opposed to when it is defined).

This task can also be used to run existing Test::Unit tests and get RSpec output, for example like this:

      require 'rubygems'
      require 'spec/rake/spectask'
      Spec::Rake::SpecTask.new do |t|
        t.ruby_opts = ['-rtest/unit']
        t.spec_files = FileList['test/**/*_test.rb']
      end

### Methods

attr_accessor new

### Attributes

fail_on_error | [RW] | Whether or not to fail Rake when an error occurs (typically when specs fail). Defaults to true.
failure_message | [RW] | A message to print to stderr when there are failures.
libs | [RW] | Array of directories to be added to $LOAD_PATH before running the specs. Defaults to [’<the absolute path to RSpec‘s lib directory>’]
name | [RW] | Name of spec task. (default is :spec)
out | [RW] | Where RSpec‘s output is written. Defaults to STDOUT. DEPRECATED. Use —format FORMAT:WHERE in spec_opts.
pattern | [RW] | Glob pattern to match spec files. (default is ‘spec/**/*_spec.rb’) Setting the SPEC environment variable overrides this.
rcov | [RW] | Whether or not to use RCov (default is false) See eigenclass.org/hiki.rb?rcov
rcov_dir | [RW] | Directory where the RCov report is written. Defaults to "coverage" Ignored if rcov=false
rcov_opts | [RW] | Array of commandline options to pass to RCov. Defaults to [’—exclude’, ‘lib\/spec,bin\/spec’]. Ignored if rcov=false Setting the RCOV_OPTS environment variable overrides this.
ruby_opts | [RW] | Array of commandline options to pass to ruby. Defaults to [].
spec_files | [RW] | Explicitly define the list of spec files to be included in a spec. `spec_files` is expected to be an array of file names (a FileList is acceptable). If both `pattern` and `spec_files` are used, then the list of spec files is the union of the two. Setting the SPEC environment variable overrides this.
spec_opts | [RW] | Array of commandline options to pass to RSpec. Defaults to []. Setting the SPEC_OPTS environment variable overrides this.
verbose | [RW] | Use verbose output. If this is set to true, the task will print the executed spec command to stdout. Defaults to false.
warning | [RW] | If true, requests that the specs be run with the warning flag set. E.g. warning=true implies "ruby -w" used to run the specs. Defaults to false.

### Public Class methods

attr_accessor(*names)

[Source]

        # File lib/spec/rake/spectask.rb, line 60
    60:         def attr_accessor(*names)
    61:           super(*names)
    62:           names.each do |name|
    63:             module_eval "def #{name}() evaluate(@#{name}) end" # Allows use of procs
    64:           end
    65:         end

new(name=:spec) {|self if block_given?| ...}

Defines a new task, using the name `name`.

[Source]

         # File lib/spec/rake/spectask.rb, line 126
    126:       def initialize(name=:spec)
    127:         @name = name
    128:         @libs = [File.expand_path(File.dirname(__FILE__) + '/../../../lib')]
    129:         @pattern = nil
    130:         @spec_files = nil
    131:         @spec_opts = []
    132:         @warning = false
    133:         @ruby_opts = []
    134:         @fail_on_error = true
    135:         @rcov = false
    136:         @rcov_opts = ['--exclude', 'lib\/spec,bin\/spec,config\/boot.rb']
    137:         @rcov_dir = "coverage"
    138:
    139:         yield self if block_given?
    140:         @pattern = 'spec/**/*_spec.rb' if pattern.nil? && spec_files.nil?
    141:         define
    142:       end

[Validate]