Class: Cucumber::Rake::Task

Inherits:
Object show all
Includes:
Gherkin::Formatter::AnsiEscapes, Rake::DSL
Defined in:
lib/cucumber/rake/task.rb

Overview

Defines a Rake task for running features.

The simplest use of it goes something like:

Cucumber::Rake::Task.new

This will define a task named cucumber described as 'Run Cucumber features'. It will use steps from 'features/*/.rb' and features in 'features/*/.feature'.

To further configure the task, you can pass a block:

Cucumber::Rake::Task.new do |t|
  t.cucumber_opts = %w{--format progress}
end

This task can also be configured to be run with RCov:

Cucumber::Rake::Task.new do |t|
  t.rcov = true
end

See the attributes for additional configuration possibilities.

Defined Under Namespace

Classes: ForkedCucumberRunner, InProcessCucumberRunner, RCovCucumberRunner

Constant Summary

LIB =

:nodoc:

File.expand_path(File.dirname(__FILE__) + '/../..')

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Task) initialize(task_name = "cucumber", desc = "Run Cucumber features") {|_self| ... }

Define Cucumber Rake task

Yields:

  • (_self)

Yield Parameters:



176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/cucumber/rake/task.rb', line 176

def initialize(task_name = "cucumber", desc = "Run Cucumber features")
  @task_name, @desc = task_name, desc
  @fork = true
  @libs = ['lib']
  @rcov_opts = %w{--rails --exclude osx\/objc,gems\/}

  yield self if block_given?

  @binary = binary.nil? ? Cucumber::BINARY : File.expand_path(binary)
  @libs.insert(0, LIB) if binary == Cucumber::BINARY

  define_task
end

Instance Attribute Details

- (Object) binary

Name of the cucumber binary to use for running features. Defaults to Cucumber::BINARY



133
134
135
# File 'lib/cucumber/rake/task.rb', line 133

def binary
  @binary
end

- (Object) bundler

Whether or not to run with bundler (bundle exec). Setting this to false may speed up the execution. The default value is true if Bundler is installed and you have a Gemfile, false otherwise.

Note that this attribute has no effect if you don't run in forked mode.



173
174
175
# File 'lib/cucumber/rake/task.rb', line 173

def bundler
  @bundler
end

- (Object) cucumber_opts

Extra options to pass to the cucumber binary. Can be overridden by the CUCUMBER_OPTS environment variable. It's recommended to pass an Array, but if it's a String it will be #split by ' '.



137
138
139
# File 'lib/cucumber/rake/task.rb', line 137

def cucumber_opts
  @cucumber_opts
end

- (Object) fork

Whether or not to fork a new ruby interpreter. Defaults to true. You may gain some startup speed if you set it to false, but this may also cause issues with your load path and gems.



162
163
164
# File 'lib/cucumber/rake/task.rb', line 162

def fork
  @fork
end

- (Object) libs

Directories to add to the Ruby $LOAD_PATH



130
131
132
# File 'lib/cucumber/rake/task.rb', line 130

def libs
  @libs
end

- (Object) profile

Define what profile to be used. When used with cucumber_opts it is simply appended to it. Will be ignored when CUCUMBER_OPTS is used.



166
167
168
# File 'lib/cucumber/rake/task.rb', line 166

def profile
  @profile
end

- (Object) rcov

Run cucumber with RCov? Defaults to false. If you set this to true, fork is implicit.



144
145
146
# File 'lib/cucumber/rake/task.rb', line 144

def rcov
  @rcov
end

- (Object) rcov_opts

Extra options to pass to rcov. It's recommended to pass an Array, but if it's a String it will be #split by ' '.



154
155
156
# File 'lib/cucumber/rake/task.rb', line 154

def rcov_opts
  @rcov_opts
end

Instance Method Details

- (Object) cucumber_opts_with_profile

:nodoc:



208
209
210
# File 'lib/cucumber/rake/task.rb', line 208

def cucumber_opts_with_profile #:nodoc:
  @profile ? [cucumber_opts, '--profile', @profile] : cucumber_opts
end

- (Object) define_task

:nodoc:



190
191
192
193
194
195
# File 'lib/cucumber/rake/task.rb', line 190

def define_task #:nodoc:
  desc @desc
  task @task_name do
    runner.run
  end
end

- (Object) feature_files

:nodoc:



212
213
214
# File 'lib/cucumber/rake/task.rb', line 212

def feature_files #:nodoc:
  make_command_line_safe(FileList[ ENV['FEATURE'] || [] ])
end

- (Object) make_command_line_safe(list)



216
217
218
# File 'lib/cucumber/rake/task.rb', line 216

def make_command_line_safe(list)
  list.map{|string| string.gsub(' ', '\ ')}
end

- (Object) runner(task_args = nil)

:nodoc:



197
198
199
200
201
202
203
204
205
206
# File 'lib/cucumber/rake/task.rb', line 197

def runner(task_args = nil) #:nodoc:
  cucumber_opts = [(ENV['CUCUMBER_OPTS'] ? ENV['CUCUMBER_OPTS'].split(/\s+/) : nil) || cucumber_opts_with_profile]
  if(@rcov)
    RCovCucumberRunner.new(libs, binary, cucumber_opts, bundler, feature_files, rcov_opts)
  elsif(@fork)
    ForkedCucumberRunner.new(libs, binary, cucumber_opts, bundler, feature_files)
  else
    InProcessCucumberRunner.new(libs, cucumber_opts, feature_files)
  end
end