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) {|_self| ... } ⇒ RakeTask

Returns a new instance of RakeTask.

Yields:

  • (_self)

Yield Parameters:



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/rspec/core/rake_task.rb', line 124

def initialize(*args)
  @name = args.shift || :spec
  @pattern, @rcov_path, @rcov_opts, @ruby_opts, @rspec_opts = nil, nil, nil, nil, nil
  @warning, @rcov = false, false
  @verbose, @fail_on_error = true, true

  yield self if block_given?

  @rcov_path  ||= 'rcov'
  @rspec_path ||= 'rspec'
  @pattern    ||= './spec{,/*/**}/*_spec.rb'

  desc("Run RSpec code examples") unless ::Rake.application.last_comment

  task name do
    RakeFileUtils.send(:verbose, verbose) do
      if files_to_run.empty?
        puts "No examples matching #{pattern} could be found"
      else
        begin
          puts spec_command if verbose
          success = system(spec_command)
        rescue
          puts failure_message if failure_message
        end
        raise("ruby #{spec_command} failed") if fail_on_error unless success
      end
    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


65
66
67
# File 'lib/rspec/core/rake_task.rb', line 65

def fail_on_error
  @fail_on_error
end

#failure_messageObject

A message to print to stderr when there are failures.



68
69
70
# File 'lib/rspec/core/rake_task.rb', line 68

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

#rcovObject

Use rcov for code coverage?

default:

false


81
82
83
# File 'lib/rspec/core/rake_task.rb', line 81

def rcov
  @rcov
end

#rcov_optsObject

Command line options to pass to rcov.

default:

nil


93
94
95
# File 'lib/rspec/core/rake_task.rb', line 93

def rcov_opts
  @rcov_opts
end

#rcov_pathObject

Path to rcov.

default:

'rcov'


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

def rcov_path
  @rcov_path
end

#rspec_optsObject

Command line options to pass to rspec.

default:

nil


111
112
113
# File 'lib/rspec/core/rake_task.rb', line 111

def rspec_opts
  @rspec_opts
end

#rspec_pathObject

Path to rspec

default:

'rspec'


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

def rspec_path
  @rspec_path
end

#ruby_optsObject

Command line options to pass to ruby.

default:

nil


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

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


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

def verbose
  @verbose
end

#warningObject

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


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

def warning
  @warning
end

Instance Method Details

#gemfile=Object

Deprecated and has no effect. The rake task now checks ENV instead.

Name of Gemfile to use.

default:

Gemfile


43
44
45
# File 'lib/rspec/core/rake_task.rb', line 43

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

#skip_bundler=Object

Deprecated and has no effect. The rake task now checks ENV instead.

By default, if there is a Gemfile, the generated command will include ‘bundle exec’. Set this to true to ignore the presence of a Gemfile, and not add ‘bundle exec’ to the command.

default:

false


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

def skip_bundler=(*)
  RSpec.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


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

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