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 = "--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:



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

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



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

def binary
  @binary
end

#cucumber_optsObject

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



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

def cucumber_opts
  @cucumber_opts
end

#feature_listObject

Array of paths to specific features to run.



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

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.



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

def feature_pattern
  @feature_pattern
end

#libsObject

Directories to add to the Ruby $LOAD_PATH



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

def libs
  @libs
end

#rcovObject

Run cucumber with RCov?



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

def rcov
  @rcov
end

#rcov_optsObject

Extra options to pass to rcov



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

def rcov_opts
  @rcov_opts
end

#step_listObject

Array of paths to specific step definition files to use



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

def step_list
  @step_list
end

#step_patternObject

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



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

def step_pattern
  @step_pattern
end

Instance Method Details

#arguments_for_ruby_execution(task_args = nil) ⇒ Object

:nodoc:



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

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:



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

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:



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

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:



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

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