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.libs << 'lib'
  t.cucumber_opts = "--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

Constant Summary collapse

LIB =

:nodoc:

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Define a Rake

Yields:

  • (_self)

Yield Parameters:



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/cucumber/rake/task.rb', line 53

def initialize(task_name = "features", desc = "Run Features with Cucumber")
  @task_name, @desc = task_name, desc
  @libs = []
  @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



34
35
36
# File 'lib/cucumber/rake/task.rb', line 34

def binary
  @binary
end

#cucumber_optsObject

Extra options to pass to the cucumber binary. Can be overridden by the CUCUMBER_OPTS environment variable.



46
47
48
# File 'lib/cucumber/rake/task.rb', line 46

def cucumber_opts
  @cucumber_opts
end

#feature_listObject

Array of paths to specific features to run.



41
42
43
# File 'lib/cucumber/rake/task.rb', line 41

def feature_list
  @feature_list
end

#feature_patternObject

File pattern for finding features to run. Defaults to ‘features/*/.feature’. Can be overriden by the FEATURE environment variable.



44
45
46
# File 'lib/cucumber/rake/task.rb', line 44

def feature_pattern
  @feature_pattern
end

#libsObject

Directories to add to the Ruby $LOAD_PATH



32
33
34
# File 'lib/cucumber/rake/task.rb', line 32

def libs
  @libs
end

#rcovObject

Run cucumber with RCov?



48
49
50
# File 'lib/cucumber/rake/task.rb', line 48

def rcov
  @rcov
end

#rcov_optsObject

Extra options to pass to rcov



50
51
52
# File 'lib/cucumber/rake/task.rb', line 50

def rcov_opts
  @rcov_opts
end

#step_listObject

Array of paths to specific step definition files to use



36
37
38
# File 'lib/cucumber/rake/task.rb', line 36

def step_list
  @step_list
end

#step_patternObject

File pattern for finding step definitions. Defaults to ‘features/*/.rb’.



39
40
41
# File 'lib/cucumber/rake/task.rb', line 39

def step_pattern
  @step_pattern
end

Instance Method Details

#arguments_for_ruby_execution(task_args = nil) ⇒ Object

:nodoc:



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/cucumber/rake/task.rb', line 76

def arguments_for_ruby_execution(task_args = nil) # :nodoc:
  lib_args     = ['"%s"' % libs.join(File::PATH_SEPARATOR)]
  cucumber_bin = ['"%s"' % binary]
  cuc_opts     = [(ENV['CUCUMBER_OPTS'] || cucumber_opts)]

  step_files(task_args).each do |step_file|
    cuc_opts << '--require'
    cuc_opts << step_file
  end

  if rcov
    args = (['-I'] + lib_args + ['-S', 'rcov'] + rcov_opts +
      cucumber_bin + ['--'] + cuc_opts + feature_files(task_args)).flatten
  else
    args = (['-I'] + lib_args + cucumber_bin + cuc_opts + feature_files(task_args)).flatten
  end

  args
end

#define_taskObject

:nodoc:



69
70
71
72
73
74
# File 'lib/cucumber/rake/task.rb', line 69

def define_task # :nodoc:
  desc @desc
  task @task_name do
    ruby(arguments_for_ruby_execution.join(" ")) # ruby(*args) is broken on Windows
  end
end

#feature_files(task_args = nil) ⇒ Object

:nodoc:



96
97
98
99
100
101
102
103
104
105
# File 'lib/cucumber/rake/task.rb', line 96

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

#step_files(task_args = nil) ⇒ Object

:nodoc:



107
108
109
110
111
112
113
114
115
116
# File 'lib/cucumber/rake/task.rb', line 107

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