class Spec::Rake::SpecTask


end
t.spec_files = FileList[‘test/*/_test.rb’]
t.ruby_opts = [‘-rtest/unit’]
Spec::Rake::SpecTask.new do |t|
require ‘spec/rake/spectask’
require ‘rubygems’
output, for example like this:
This task can also be used to run existing Test::Unit tests and get RSpec
until the task is run (as opposed to when it is defined).
which is sometimes handy if you want to defer the evaluation of an attribute value
Each attribute of this task may be a proc. This allows for lazy evaluation,
rake spec RCOV_OPTS=“–aggregate myfile.txt” # see rcov –help for details
rake spec SPEC_OPTS=“–diff” # enable diffing
rake spec SPEC=just_one_file.rb # run just one spec file.
rake spec # run specs normally
Examples:
attribute.
then the given options will override the value of the rcov_opts
If rake is invoked with a “RCOV_OPTS=options” command line option,
attribute.
then the given options will override the value of the spec_opts
If rake is invoked with a “SPEC_OPTS=options” command line option,
to run just one spec.
filename specified on the command line. This provides an easy way
then the list of spec files will be overridden to include only the
If rake is invoked with a “SPEC=filename” command line option,
rake spec
This will create a task that can be run with:
end
t.rcov = true
t.warning = true
Spec::Rake::SpecTask.new do |t|
Example:
A Rake task that runs a set of specs.

def attr_accessor(*names)

def attr_accessor(*names)
  super(*names)
  names.each do |name|
    module_eval "def #{name}() evaluate(@#{name}) end" # Allows use of procs
  end
end

def define # :nodoc:

:nodoc:
def define # :nodoc:
  spec_script = File.expand_path(File.dirname(__FILE__) + '/../../../bin/spec')
  lib_path = libs.join(File::PATH_SEPARATOR)
  actual_name = Hash === name ? name.keys.first : name
  unless ::Rake.application.last_comment
    desc "Run specs" + (rcov ? " using RCov" : "")
  end
  task name do
    RakeFileUtils.verbose(verbose) do
      unless spec_file_list.empty?
        # ruby [ruby_opts] -Ilib -S rcov [rcov_opts] bin/spec -- examples [spec_opts]
        # or
        # ruby [ruby_opts] -Ilib bin/spec examples [spec_opts]
        cmd_parts = [RUBY]
        cmd_parts += ruby_opts
        cmd_parts << %[-I"#{lib_path}"]
        cmd_parts << "-S rcov" if rcov
        cmd_parts << "-w" if warning
        cmd_parts << rcov_option_list
        cmd_parts << %[-o "#{rcov_dir}"] if rcov
        cmd_parts << %["#{spec_script}"]
        cmd_parts << "--" if rcov
        cmd_parts += spec_file_list.collect { |fn| %["#{fn}"] }
        cmd_parts << spec_option_list
        if out
          cmd_parts << %[> "#{out}"]
          STDERR.puts "The Spec::Rake::SpecTask#out attribute is DEPRECATED and will be removed in a future version. Use --format FORMAT:WHERE instead."
        end
        cmd = cmd_parts.join(" ")
        puts cmd if verbose
        unless system(cmd)
          STDERR.puts failure_message if failure_message
          raise("Command #{cmd} failed") if fail_on_error
        end
      end
    end
  end
  if rcov
    desc "Remove rcov products for #{actual_name}"
    task paste("clobber_", actual_name) do
      rm_r rcov_dir rescue nil
    end
    clobber_task = paste("clobber_", actual_name)
    task :clobber => [clobber_task]
    task actual_name => clobber_task
  end
  self
end

def evaluate(o) # :nodoc:

:nodoc:
def evaluate(o) # :nodoc:
  case o
    when Proc then o.call
    else o
  end
end

def initialize(name=:spec)

Defines a new task, using the name +name+.
def initialize(name=:spec)
  @name = name
  @libs = [File.expand_path(File.dirname(__FILE__) + '/../../../lib')]
  @pattern = nil
  @spec_files = nil
  @spec_opts = []
  @warning = false
  @ruby_opts = []
  @fail_on_error = true
  @rcov = false
  @rcov_opts = ['--exclude', 'lib\/spec,bin\/spec,config\/boot.rb']
  @rcov_dir = "coverage"
  yield self if block_given?
  @pattern = 'spec/**/*_spec.rb' if pattern.nil? && spec_files.nil?
  define
end

def rcov_option_list # :nodoc:

:nodoc:
def rcov_option_list # :nodoc:
  return "" unless rcov
  ENV['RCOV_OPTS'] || rcov_opts.join(" ") || ""
end

def spec_file_list # :nodoc:

:nodoc:
def spec_file_list # :nodoc:
  if ENV['SPEC']
    FileList[ ENV['SPEC'] ]
  else
    result = []
    result += spec_files.to_a if spec_files
    result += FileList[ pattern ].to_a if pattern
    FileList[result]
  end
end

def spec_option_list # :nodoc:

:nodoc:
def spec_option_list # :nodoc:
  STDERR.puts "RSPECOPTS is DEPRECATED and will be removed in a future version. Use SPEC_OPTS instead." if ENV['RSPECOPTS']
  ENV['SPEC_OPTS'] || ENV['RSPECOPTS'] || spec_opts.join(" ") || ""
end