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

- (RakeTask) initialize(*args)

A new instance of RakeTask

140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/rspec/core/rake_task.rb', line 140
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

- (Object) fail_on_error

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

default: true

53
54
55
# File 'lib/rspec/core/rake_task.rb', line 53
def fail_on_error
  @fail_on_error
end

- (Object) failure_message

A message to print to stderr when there are failures.

56
57
58
# File 'lib/rspec/core/rake_task.rb', line 56
def failure_message
  @failure_message
end

- (Object) name

Name of task.

default: :spec

16
17
18
# File 'lib/rspec/core/rake_task.rb', line 16
def name
  @name
end

- (Object) pattern

Glob pattern to match files.

default: 'spec/*/_spec.rb'

22
23
24
# File 'lib/rspec/core/rake_task.rb', line 22
def pattern
  @pattern
end

- (Object) rspec_opts

Command line options to pass to rspec.

default: nil

126
127
128
# File 'lib/rspec/core/rake_task.rb', line 126
def rspec_opts
  @rspec_opts
end

- (Object) rspec_path

Path to rspec

default: 'rspec'

120
121
122
# File 'lib/rspec/core/rake_task.rb', line 120
def rspec_path
  @rspec_path
end

- (Object) ruby_opts

Command line options to pass to ruby.

default: nil

114
115
116
# File 'lib/rspec/core/rake_task.rb', line 114
def ruby_opts
  @ruby_opts
end

- (Object) verbose

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

default: true

63
64
65
# File 'lib/rspec/core/rake_task.rb', line 63
def verbose
  @verbose
end

Instance Method Details

- (Object) gemfile=

Deprecated.

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

32
33
34
# File 'lib/rspec/core/rake_task.rb', line 32
def gemfile=(*)
  deprecate("RSpec::Core::RakeTask#gemfile=", :replacement => 'ENV["BUNDLE_GEMFILE"]')
end

- (Object) rcov

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

72
73
74
75
# File 'lib/rspec/core/rake_task.rb', line 72
def rcov
  deprecate("RSpec::Core::RakeTask#rcov")
  @rcov
end

- (Object) rcov=(true_or_false)

77
78
79
80
# File 'lib/rspec/core/rake_task.rb', line 77
def rcov=(true_or_false)
  deprecate("RSpec::Core::RakeTask#rcov=")
  @rcov = true_or_false
end

- (Object) rcov_opts

Command line options to pass to rcov.

default: nil

100
101
102
103
# File 'lib/rspec/core/rake_task.rb', line 100
def rcov_opts
  deprecate("RSpec::Core::RakeTask#rcov_opts")
  @rcov_opts
end

- (Object) rcov_opts=(opts)

105
106
107
108
# File 'lib/rspec/core/rake_task.rb', line 105
def rcov_opts=(opts)
  deprecate("RSpec::Core::RakeTask#rcov_opts=")
  @rcov_opts = opts
end

- (Object) rcov_path

Path to rcov.

default: 'rcov'

86
87
88
89
# File 'lib/rspec/core/rake_task.rb', line 86
def rcov_path
  deprecate("RSpec::Core::RakeTask#rcov_path")
  @rcov_path
end

- (Object) rcov_path=(path)

91
92
93
94
# File 'lib/rspec/core/rake_task.rb', line 91
def rcov_path=(path)
  deprecate("RSpec::Core::RakeTask#rcov_path=")
  @rcov_path = path
end

- (Object) run_task(verbose)

164
165
166
167
168
169
170
171
172
173
174
# File 'lib/rspec/core/rake_task.rb', line 164
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

- (Object) setup_ivars(args)

153
154
155
156
157
158
159
160
161
162
# File 'lib/rspec/core/rake_task.rb', line 153
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

- (Object) shellescape(string)

1.8.6's shellwords doesn't provide shellescape :(.

183
184
185
# File 'lib/rspec/core/rake_task.rb', line 183
def shellescape(string)
  string.shellescape
end

- (Object) skip_bundler=

Deprecated.

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

26
27
28
# File 'lib/rspec/core/rake_task.rb', line 26
def skip_bundler=(*)
  deprecate("RSpec::Core::RakeTask#skip_bundler=")
end

- (Object) spec_opts=(opts)

Deprecated.

Use rspec_opts instead.

Command line options to pass to rspec.

default: nil

135
136
137
138
# File 'lib/rspec/core/rake_task.rb', line 135
def spec_opts=(opts)
  deprecate('RSpec::Core::RakeTask#spec_opts=', :replacement => 'rspec_opts=')
  @rspec_opts = opts
end

- (Object) warning=(true_or_false)

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

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