Class: Cucumber::Rake::Task
- Inherits:
-
Object
- Object
- Cucumber::Rake::Task
- 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.
Constant Summary
Constants included from Gherkin::Formatter::AnsiEscapes
Gherkin::Formatter::AnsiEscapes::ALIASES, Gherkin::Formatter::AnsiEscapes::COLORS
Instance Attribute Summary collapse
-
#binary ⇒ Object
Name of the cucumber binary to use for running features.
-
#bundler ⇒ Object
Whether or not to run with bundler (bundle exec).
-
#cucumber_opts ⇒ Object
Extra options to pass to the cucumber binary.
-
#fork ⇒ Object
Whether or not to fork a new ruby interpreter.
-
#libs ⇒ Object
Directories to add to the Ruby $LOAD_PATH.
-
#profile ⇒ Object
Define what profile to be used.
-
#task_name ⇒ Object
readonly
Name of the running task.
Instance Method Summary collapse
-
#cucumber_opts_with_profile ⇒ Object
:nodoc:.
-
#define_task ⇒ Object
:nodoc:.
-
#feature_files ⇒ Object
:nodoc:.
-
#initialize(task_name = 'cucumber', desc = 'Run Cucumber features') {|_self| ... } ⇒ Task
constructor
A new instance of Task.
- #make_command_line_safe(list) ⇒ Object
-
#runner(_task_args = nil) ⇒ Object
:nodoc:.
Methods included from Gherkin::Formatter::AnsiEscapes
Constructor Details
#initialize(task_name = 'cucumber', desc = 'Run Cucumber features') {|_self| ... } ⇒ Task
Returns a new instance of Task.
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/cucumber/rake/task.rb', line 61 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.(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 |
#bundler ⇒ Object
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.
40 41 42 |
# File 'lib/cucumber/rake/task.rb', line 40 def bundler @bundler end |
#cucumber_opts ⇒ Object
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 ‘ ’.
44 45 46 |
# File 'lib/cucumber/rake/task.rb', line 44 def cucumber_opts @cucumber_opts end |
#fork ⇒ Object
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.
49 50 51 |
# File 'lib/cucumber/rake/task.rb', line 49 def fork @fork end |
#libs ⇒ Object
Directories to add to the Ruby $LOAD_PATH
52 53 54 |
# File 'lib/cucumber/rake/task.rb', line 52 def libs @libs end |
#profile ⇒ Object
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.
56 57 58 |
# File 'lib/cucumber/rake/task.rb', line 56 def profile @profile end |
#task_name ⇒ Object (readonly)
Name of the running task
59 60 61 |
# File 'lib/cucumber/rake/task.rb', line 59 def task_name @task_name end |
Instance Method Details
#cucumber_opts_with_profile ⇒ Object
:nodoc:
84 85 86 |
# File 'lib/cucumber/rake/task.rb', line 84 def cucumber_opts_with_profile # :nodoc: Array(cucumber_opts).concat(Array(@profile).flat_map { |p| ['--profile', p] }) end |
#define_task ⇒ Object
:nodoc:
88 89 90 91 92 93 |
# File 'lib/cucumber/rake/task.rb', line 88 def define_task # :nodoc: desc @desc task @task_name do runner.run end end |
#feature_files ⇒ Object
:nodoc:
95 96 97 |
# File 'lib/cucumber/rake/task.rb', line 95 def feature_files # :nodoc: make_command_line_safe(FileList[ENV['FEATURE'] || []]) end |
#make_command_line_safe(list) ⇒ Object
99 100 101 |
# File 'lib/cucumber/rake/task.rb', line 99 def make_command_line_safe(list) list.map { |string| string.gsub(' ', '\ ') } end |
#runner(_task_args = nil) ⇒ Object
:nodoc:
103 104 105 106 107 108 |
# File 'lib/cucumber/rake/task.rb', line 103 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 |