Class: RSpec::Core::RakeTask

Inherits:
Rake::TaskLib
  • Object
show all
Includes:
Rake::DSL
Defined in:
lib/rspec/core/rake_task.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, &task_block) ⇒ RakeTask

Returns a new instance of RakeTask.



139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/rspec/core/rake_task.rb', line 139

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

Instance Attribute Details

#fail_on_errorObject

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

default: true



52
53
54
# File 'lib/rspec/core/rake_task.rb', line 52

def fail_on_error
  @fail_on_error
end

#failure_messageObject

A message to print to stderr when there are failures.



55
56
57
# File 'lib/rspec/core/rake_task.rb', line 55

def failure_message
  @failure_message
end

#nameObject

Name of task.

default: :spec



15
16
17
# File 'lib/rspec/core/rake_task.rb', line 15

def name
  @name
end

#patternObject

Glob pattern to match files.

default: 'spec/*/_spec.rb'



21
22
23
# File 'lib/rspec/core/rake_task.rb', line 21

def pattern
  @pattern
end

#rspec_optsObject

Command line options to pass to rspec.

default: nil



125
126
127
# File 'lib/rspec/core/rake_task.rb', line 125

def rspec_opts
  @rspec_opts
end

#rspec_pathObject

Path to rspec

default: 'rspec'



119
120
121
# File 'lib/rspec/core/rake_task.rb', line 119

def rspec_path
  @rspec_path
end

#ruby_optsObject

Command line options to pass to ruby.

default: nil



113
114
115
# File 'lib/rspec/core/rake_task.rb', line 113

def ruby_opts
  @ruby_opts
end

#verboseObject

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

default: true



62
63
64
# File 'lib/rspec/core/rake_task.rb', line 62

def verbose
  @verbose
end

Instance Method Details

#gemfile=Object

Deprecated.

Has no effect. The rake task now checks ENV['BUNDLE_GEMFILE'] instead.



31
32
33
# File 'lib/rspec/core/rake_task.rb', line 31

def gemfile=(*)
  deprecate("RSpec::Core::RakeTask#gemfile=", :replacement => 'ENV["BUNDLE_GEMFILE"]')
end

#rcovObject

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



71
72
73
74
# File 'lib/rspec/core/rake_task.rb', line 71

def rcov
  deprecate("RSpec::Core::RakeTask#rcov")
  @rcov
end

#rcov=(true_or_false) ⇒ Object



76
77
78
79
# File 'lib/rspec/core/rake_task.rb', line 76

def rcov=(true_or_false)
  deprecate("RSpec::Core::RakeTask#rcov=")
  @rcov = true_or_false
end

#rcov_optsObject

Command line options to pass to rcov.

default: nil



99
100
101
102
# File 'lib/rspec/core/rake_task.rb', line 99

def rcov_opts
  deprecate("RSpec::Core::RakeTask#rcov_opts")
  @rcov_opts
end

#rcov_opts=(opts) ⇒ Object



104
105
106
107
# File 'lib/rspec/core/rake_task.rb', line 104

def rcov_opts=(opts)
  deprecate("RSpec::Core::RakeTask#rcov_opts=")
  @rcov_opts = opts
end

#rcov_pathObject

Path to rcov.

default: 'rcov'



85
86
87
88
# File 'lib/rspec/core/rake_task.rb', line 85

def rcov_path
  deprecate("RSpec::Core::RakeTask#rcov_path")
  @rcov_path
end

#rcov_path=(path) ⇒ Object



90
91
92
93
# File 'lib/rspec/core/rake_task.rb', line 90

def rcov_path=(path)
  deprecate("RSpec::Core::RakeTask#rcov_path=")
  @rcov_path = path
end

#run_task(verbose) ⇒ Object



163
164
165
166
167
168
169
170
171
172
173
# File 'lib/rspec/core/rake_task.rb', line 163

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) ⇒ Object



152
153
154
155
156
157
158
159
160
161
# File 'lib/rspec/core/rake_task.rb', line 152

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=Object

Deprecated.

Has no effect. The rake task now checks ENV['BUNDLE_GEMFILE'] instead.



25
26
27
# File 'lib/rspec/core/rake_task.rb', line 25

def skip_bundler=(*)
  deprecate("RSpec::Core::RakeTask#skip_bundler=")
end

#spec_opts=(opts) ⇒ Object

Deprecated.

Use rspec_opts instead.

Command line options to pass to rspec.

default: nil



134
135
136
137
# File 'lib/rspec/core/rake_task.rb', line 134

def spec_opts=(opts)
  deprecate('RSpec::Core::RakeTask#spec_opts=', :replacement => 'rspec_opts=')
  @rspec_opts = opts
end

#warning=(true_or_false) ⇒ Object

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



43
44
45
46
# 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