Class: Cucumber::Rake::Task

Inherits:
Object show all
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 create a task named ‘features’ described as ‘Run Features with Cucumber’. 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.

Direct Known Subclasses

FeatureTask

Defined Under Namespace

Classes: ForkedCucumberRunner, InProcessCucumberRunner, RCovCucumberRunner

Constant Summary collapse

LIB =

:nodoc:

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(task_name = "features", desc = "Run Features with Cucumber") {|_self| ... } ⇒ Task

Define Cucumber Rake task

Yields:

  • (_self)

Yield Parameters:



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/cucumber/rake/task.rb', line 151

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

  yield self if block_given?

  @feature_pattern = "features/**/*.feature" if feature_pattern.nil? && feature_list.nil?
  @step_pattern    = "features/**/*.rb"      if step_pattern.nil? && step_list.nil?

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

  define_task
end

Instance Attribute Details

#binaryObject

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



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

def binary
  @binary
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 ‘ ’.



120
121
122
# File 'lib/cucumber/rake/task.rb', line 120

def cucumber_opts
  @cucumber_opts
end

#forkObject

Whether or not to fork a new ruby interpreter. Defaults to true.



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

def fork
  @fork
end

#libsObject

Directories to add to the Ruby $LOAD_PATH



99
100
101
# File 'lib/cucumber/rake/task.rb', line 99

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.



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

def profile
  @profile
end

#rcovObject

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



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

def rcov
  @rcov
end

#rcov_optsObject

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



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

def rcov_opts
  @rcov_opts
end

Class Method Details

.deprecate_accessor(attribute) ⇒ Object

TODO: remove depreated accessors for 0.4.0



88
89
90
91
92
93
94
95
96
# File 'lib/cucumber/rake/task.rb', line 88

def self.deprecate_accessor(attribute) # :nodoc:
  attr_reader attribute
  class_eval <<-EOF, __FILE__, __LINE__ + 1
    def #{attribute}=(value)
      @#{attribute} = value
      warn("\nWARNING: Cucumber::Rake::Task##{attribute} is deprecated and will be removed in 0.4.0.  Please use profiles for complex settings: http://wiki.github.com/aslakhellesoy/cucumber/using-rake#profiles\n")
    end
  EOF
end

Instance Method Details

#cucumber_opts_with_profileObject

:nodoc:



186
187
188
# File 'lib/cucumber/rake/task.rb', line 186

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

#define_taskObject

:nodoc:



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

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

#feature_files(task_args = nil) ⇒ Object

:nodoc:



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

def feature_files(task_args = nil) # :nodoc:
  if ENV['FEATURE']
    FileList[ ENV['FEATURE'] ]
  else
    result = []
    result += feature_list.to_a if feature_list
    result += FileList[feature_pattern].to_a if feature_pattern
    FileList[result]
  end
end

#runner(task_args = nil) ⇒ Object

:nodoc:



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

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, feature_files(task_args), rcov_opts)
  elsif(@fork)
    ForkedCucumberRunner.new(libs, binary, cucumber_opts, feature_files(task_args))
  else
    InProcessCucumberRunner.new(libs, cucumber_opts, feature_files(task_args))
  end
end

#step_files(task_args = nil) ⇒ Object

:nodoc:



201
202
203
204
205
206
207
208
209
210
# File 'lib/cucumber/rake/task.rb', line 201

def step_files(task_args = nil) # :nodoc:
  if ENV['STEPS']
    FileList[ ENV['STEPS'] ]
  else
    result = []
    result += Array(step_list) if step_list
    result += Array(FileList[step_pattern]) if step_pattern
    FileList[result]
  end
end