class RSpec::Core::RakeTask

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'
rcov[RW]

Use rcov for code coverage?

Due to the many ways `rcov` can run, if this option is enabled, it is required that `require 'rspec/autorun'` appears in `spec_helper`.rb

default:

false
rcov_opts[RW]

Command line options to pass to rcov.

default:

nil
rcov_path[RW]

Path to rcov.

default:

'rcov'
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 115
def initialize(*args, &task_block)
  setup_ivars(args)

  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

Public Instance Methods

gemfile=(*) click to toggle source

@deprecated Has no effect. The rake task now checks ENV instead.

# File lib/rspec/core/rake_task.rb, line 31
def gemfile=(*)
  deprecate("RSpec::Core::RakeTask#gemfile=", :replacement => 'ENV["BUNDLE_GEMFILE"]')
end
run_task(verbose) click to toggle source
# File lib/rspec/core/rake_task.rb, line 139
def run_task(verbose)
  command = spec_command

  begin
    puts command if verbose
    success = system(command)
  rescue
    puts failure_message if failure_message
  end
  abort("#{command} failed") if fail_on_error unless success
end
setup_ivars(args) click to toggle source
# File lib/rspec/core/rake_task.rb, line 128
def setup_ivars(args)
  @name = args.shift || :spec
  @rcov_opts, @ruby_opts, @rspec_opts = nil, nil, nil
  @warning, @rcov = false, false
  @verbose, @fail_on_error = true, true

  @rcov_path  = 'rcov'
  @rspec_path = 'rspec'
  @pattern    = './spec{,/*/**}/*_spec.rb'
end
skip_bundler=(*) click to toggle source

@deprecated Has no effect. The rake task now checks ENV instead.

# File lib/rspec/core/rake_task.rb, line 25
def skip_bundler=(*)
  deprecate("RSpec::Core::RakeTask#skip_bundler=")
end
spec_opts=(opts) click to toggle source

@deprecated Use #rspec_opts instead.

Command line options to pass to rspec.

default:

nil
# File lib/rspec/core/rake_task.rb, line 110
def spec_opts=(opts)
  deprecate('RSpec::Core::RakeTask#spec_opts=', :replacement => 'rspec_opts=')
  @rspec_opts = opts
end
warning=(true_or_false) click to toggle source

@deprecated Use #ruby_opts=“-w” instead.

When true, requests that the specs be run with the warning flag set. e.g. “ruby -w”

default:

false
# File lib/rspec/core/rake_task.rb, line 43
def warning=(true_or_false)
  deprecate("RSpec::Core::RakeTask#warning=", :replacement => 'ruby_opts="-w"')
  @warning = true_or_false
end

Private Instance Methods

blank() click to toggle source
# File lib/rspec/core/rake_task.rb, line 188
def blank
  lambda {|s| s.nil? || s == ""}
end
deprecate(deprecated, opts = {}) click to toggle source
# File lib/rspec/core/rake_task.rb, line 192
def deprecate deprecated, opts = {}
  # unless RSpec is loaded, deprecate won't work (simply requiring the
  # deprecate file isn't enough) so this is a check for "is rspec already
  # loaded?" "ok use the main deprecate hook" otherwise "simple fallback"
  # Note that we don't need rspec to be loaded for the rake task to work
  if RSpec.respond_to?(:deprecate)
    RSpec.deprecate deprecated, opts
  else
    warn "DEPRECATION: #{deprecated} is deprecated."
  end
end
files_to_run() click to toggle source
# File lib/rspec/core/rake_task.rb, line 163
def files_to_run
  if ENV['SPEC']
    FileList[ ENV['SPEC'] ].sort
  else
    FileList[ pattern ].sort.map { |f| shellescape(f) }
  end
end
runner() click to toggle source
# File lib/rspec/core/rake_task.rb, line 184
def runner
  rcov ? rcov_path : rspec_path
end
shellescape(string) click to toggle source
# File lib/rspec/core/rake_task.rb, line 154
def shellescape(string)
  string.shellescape
end
spec_command() click to toggle source
# File lib/rspec/core/rake_task.rb, line 171
def spec_command
  cmd_parts = []
  cmd_parts << RUBY
  cmd_parts << ruby_opts
  cmd_parts << "-w" if @warning
  cmd_parts << "-S" << runner
  cmd_parts << "-Ispec:lib" << rcov_opts if rcov
  cmd_parts << files_to_run
  cmd_parts << "--" if rcov && rspec_opts
  cmd_parts << rspec_opts
  cmd_parts.flatten.reject(&blank).join(" ")
end