class RSpec::Core::RakeTask

Rspec rake task

@see Rakefile

Constants

DEFAULT_PATTERN

Default pattern for spec files.

DEFAULT_RSPEC_PATH

Default path to the rspec executable

Attributes

fail_on_error[RW]

Whether or not to fail Rake when an error occurs (typically when examples fail).

default:

true
failure_message[RW]

A message to print to stderr when there are failures.

name[RW]

Name of task.

default:

:spec
pattern[RW]

Glob pattern to match files.

default:

'spec   /*_spec.rb'
rspec_opts[RW]

Command line options to pass to rspec.

default:

nil
rspec_path[RW]

Path to rspec

default:

'rspec'
ruby_opts[RW]

Command line options to pass to ruby.

default:

nil
verbose[RW]

Use verbose output. If this is set to true, the task will print the executed spec command to stdout.

default:

true

Public Class Methods

new(*args, &task_block) click to toggle source
# File lib/rspec/core/rake_task.rb, line 69
def initialize(*args, &task_block)
  @name          = args.shift || :spec
  @ruby_opts     = nil
  @rspec_opts    = nil
  @verbose       = true
  @fail_on_error = true
  @rspec_path    = DEFAULT_RSPEC_PATH
  @pattern       = DEFAULT_PATTERN

  define(args, &task_block)
end

Public Instance Methods

run_task(verbose) click to toggle source

@private

# File lib/rspec/core/rake_task.rb, line 82
def run_task(verbose)
  command = spec_command

  begin
    puts command if verbose
    success = system(command)
  rescue
    puts failure_message if failure_message
  end
  if fail_on_error && !success
    $stderr.puts "#{command} failed"
    exit $?.exitstatus
  end
end

Private Instance Methods

blank() click to toggle source
# File lib/rspec/core/rake_task.rb, line 130
def blank
  lambda {|s| s.nil? || s == ""}
end
define(args, &task_block) click to toggle source

@private

# File lib/rspec/core/rake_task.rb, line 100
def define(args, &task_block)
  desc "Run RSpec code examples" unless ::Rake.application.last_comment

  task name, *args do |_, task_args|
    RakeFileUtils.__send__(:verbose, verbose) do
      task_block.call(*[self, task_args].slice(0, task_block.arity)) if task_block
      run_task verbose
    end
  end
end
files_to_run() click to toggle source
# File lib/rspec/core/rake_task.rb, line 111
def files_to_run
  if ENV['SPEC']
    FileList[ ENV['SPEC'] ].sort
  else
    FileList[ pattern ].sort.map(&:shellescape)
  end
end
rspec_load_path() click to toggle source
# File lib/rspec/core/rake_task.rb, line 134
def rspec_load_path
  @rspec_load_path ||= begin
    core_and_support = $LOAD_PATH.grep              %r{#{File::SEPARATOR}rspec-(core|support)[^#{File::SEPARATOR}]*#{File::SEPARATOR}lib}

    "-I#{core_and_support.map(&:shellescape).join(File::PATH_SEPARATOR)}"
  end
end
spec_command() click to toggle source
# File lib/rspec/core/rake_task.rb, line 119
def spec_command
  cmd_parts = []
  cmd_parts << RUBY
  cmd_parts << ruby_opts
  cmd_parts << rspec_load_path
  cmd_parts << "-S" << rspec_path
  cmd_parts << files_to_run
  cmd_parts << rspec_opts
  cmd_parts.flatten.reject(&blank).join(" ")
end