Class: Cucumber::Rake::Task

Inherits:
Object
  • 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

See the attributes for additional configuration possibilities.

Defined Under Namespace

Classes: ForkedCucumberRunner, InProcessCucumberRunner

Constant Summary

Constants included from Gherkin::Formatter::AnsiEscapes

Gherkin::Formatter::AnsiEscapes::ALIASES, Gherkin::Formatter::AnsiEscapes::COLORS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Gherkin::Formatter::AnsiEscapes

#reset, #up

Constructor Details

#initialize(task_name = 'cucumber', desc = 'Run Cucumber features') {|_self| ... } ⇒ Task

Define Cucumber Rake task

Yields:

  • (_self)

Yield Parameters:



143
144
145
146
147
148
149
150
151
152
# File 'lib/cucumber/rake/task.rb', line 143

def initialize(task_name = 'cucumber', desc = 'Run Cucumber features')
  @task_name = task_name
  @desc = 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)
  define_task
end

Instance Attribute Details

#binaryObject

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



105
106
107
# File 'lib/cucumber/rake/task.rb', line 105

def binary
  @binary
end

#bundlerObject

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.



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

def bundler
  @bundler
end

#cucumber_optsObject

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 ‘ ’.



109
110
111
# File 'lib/cucumber/rake/task.rb', line 109

def cucumber_opts
  @cucumber_opts
end

#forkObject

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.



126
127
128
# File 'lib/cucumber/rake/task.rb', line 126

def fork
  @fork
end

#libsObject

Directories to add to the Ruby $LOAD_PATH



102
103
104
# File 'lib/cucumber/rake/task.rb', line 102

def libs
  @libs
end

#profileObject

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.



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

def profile
  @profile
end

#task_nameObject (readonly)

Name of the running task



140
141
142
# File 'lib/cucumber/rake/task.rb', line 140

def task_name
  @task_name
end

Instance Method Details

#cucumber_opts_with_profileObject

:nodoc:



168
169
170
# File 'lib/cucumber/rake/task.rb', line 168

def cucumber_opts_with_profile # :nodoc:
  Array(cucumber_opts).concat(Array(@profile).flat_map { |p| ['--profile', p] })
end

#define_taskObject

:nodoc:



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

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

#feature_filesObject

:nodoc:



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

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

#make_command_line_safe(list) ⇒ Object



176
177
178
# File 'lib/cucumber/rake/task.rb', line 176

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

#runner(_task_args = nil) ⇒ Object

:nodoc:



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

def runner(_task_args = nil) # :nodoc:
  cucumber_opts = [ENV['CUCUMBER_OPTS']&.split(/\s+/) || cucumber_opts_with_profile]
  return ForkedCucumberRunner.new(libs, binary, cucumber_opts, bundler, feature_files) if fork

  InProcessCucumberRunner.new(libs, cucumber_opts, feature_files)
end