Class: Cucumber::Rake::Task
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
Constant Summary collapse
- LIB =
:nodoc:
File.(File.dirname(__FILE__) + '/../..')
Instance Attribute Summary collapse
-
#binary ⇒ Object
Name of the cucumber binary to use for running features.
-
#cucumber_opts ⇒ Object
Extra options to pass to the cucumber binary.
-
#feature_list ⇒ Object
Array of paths to specific features to run.
-
#feature_pattern ⇒ Object
File pattern for finding features to run.
-
#libs ⇒ Object
Directories to add to the Ruby $LOAD_PATH.
-
#rcov ⇒ Object
Run cucumber with RCov?.
-
#rcov_opts ⇒ Object
Extra options to pass to rcov.
-
#step_list ⇒ Object
Array of paths to specific step definition files to use.
-
#step_pattern ⇒ Object
File pattern for finding step definitions.
Instance Method Summary collapse
-
#arguments_for_ruby_execution(task_args = nil) ⇒ Object
:nodoc:.
-
#define_task ⇒ Object
:nodoc:.
-
#feature_files(task_args = nil) ⇒ Object
:nodoc:.
-
#initialize(task_name = "features", desc = "Run Features with Cucumber") {|_self| ... } ⇒ Task
constructor
Define a Rake.
-
#step_files(task_args = nil) ⇒ Object
:nodoc:.
Constructor Details
#initialize(task_name = "features", desc = "Run Features with Cucumber") {|_self| ... } ⇒ Task
Define a Rake
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.(binary) @libs.insert(0, LIB) if binary == Cucumber::BINARY define_task end |
Instance Attribute Details
#binary ⇒ Object
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_opts ⇒ Object
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_list ⇒ Object
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_pattern ⇒ Object
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 |
#libs ⇒ Object
Directories to add to the Ruby $LOAD_PATH
31 32 33 |
# File 'lib/cucumber/rake/task.rb', line 31 def libs @libs end |
#rcov ⇒ Object
Run cucumber with RCov?
47 48 49 |
# File 'lib/cucumber/rake/task.rb', line 47 def rcov @rcov end |
#rcov_opts ⇒ Object
Extra options to pass to rcov
49 50 51 |
# File 'lib/cucumber/rake/task.rb', line 49 def rcov_opts @rcov_opts end |
#step_list ⇒ Object
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_pattern ⇒ Object
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_task ⇒ Object
: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 |