Class: Cucumber::Configuration
- Inherits:
-
Object
- Object
- Cucumber::Configuration
- Extended by:
- Forwardable
- Includes:
- Constantize
- Defined in:
- lib/cucumber/configuration.rb
Overview
The base class for configuring settings for a Cucumber run.
Class Method Summary collapse
Instance Method Summary collapse
- #all_files_to_load ⇒ Object
- #autoload_code_paths ⇒ Object
- #custom_profiles ⇒ Object
- #dry_run? ⇒ Boolean
- #duration? ⇒ Boolean
- #error_stream ⇒ Object
- #event_bus ⇒ Object
- #expand? ⇒ Boolean
- #fail_fast? ⇒ Boolean
- #feature_dirs ⇒ Object
- #feature_files ⇒ Object
- #filters ⇒ Object
- #formats ⇒ Object
- #formatter_class(format) ⇒ Object
- #formatter_factories ⇒ Object
- #guess? ⇒ Boolean
- #id_generator ⇒ Object
-
#initialize(user_options = {}) ⇒ Configuration
constructor
A new instance of Configuration.
- #name_regexps ⇒ Object
- #notify(message, *args) ⇒ Object
-
#on_event {|Object| ... } ⇒ Object
Subscribe to an event.
- #out_stream ⇒ Object
- #paths ⇒ Object
- #profiles ⇒ Object
- #publish_enabled? ⇒ Boolean
- #publish_quiet? ⇒ Boolean
- #randomize? ⇒ Boolean
- #register_snippet_generator(generator) ⇒ Object
- #retry_attempts ⇒ Object
- #retry_total_tests ⇒ Object
- #reverse_order? ⇒ Boolean
- #seed ⇒ Object
- #skip_profile_information? ⇒ Boolean
-
#snippet_generators ⇒ Object
An array of procs that can generate snippets for undefined steps.
- #snippet_type ⇒ Object
- #snippets? ⇒ Boolean
- #source? ⇒ Boolean
- #step_defs_to_load ⇒ Object
- #strict ⇒ Object
- #support_to_load ⇒ Object
- #tag_expressions ⇒ Object
- #tag_limits ⇒ Object
- #to_hash ⇒ Object
- #wip? ⇒ Boolean
- #with_options(new_options) ⇒ Object
Methods included from Constantize
Constructor Details
#initialize(user_options = {}) ⇒ Configuration
Returns a new instance of Configuration.
61 62 63 |
# File 'lib/cucumber/configuration.rb', line 61 def initialize( = {}) @options = self.class..merge(Hash()) end |
Class Method Details
.default ⇒ Object
18 19 20 |
# File 'lib/cucumber/configuration.rb', line 18 def self.default new end |
.default_options ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/cucumber/configuration.rb', line 22 def self. { autoload_code_paths: %w[features/support features/step_definitions], filters: [], strict: Cucumber::Core::Test::Result::StrictConfiguration.new, require: [], dry_run: false, fail_fast: false, formats: [], excludes: [], tag_expressions: [], name_regexps: [], env_vars: {}, diff_enabled: true, snippets: true, source: true, duration: true, event_bus: Cucumber::Events.make_event_bus, retry_total: Float::INFINITY, tag_limits: {}, retry: 0 } end |
Instance Method Details
#all_files_to_load ⇒ Object
221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/cucumber/configuration.rb', line 221 def all_files_to_load files = require_dirs.map do |path| path = path.tr('\\', '/') # In case we're on windows. Globs don't work with backslashes. path = path.gsub(/\/$/, '') # Strip trailing slash. File.directory?(path) ? Dir["#{path}/**/*"] : path end.flatten.uniq remove_excluded_files_from(files) files.select! { |f| File.file?(f) } files.reject! { |f| File.extname(f) == '.feature' } files.reject! { |f| f =~ /^http/ } files.sort end |
#autoload_code_paths ⇒ Object
161 162 163 |
# File 'lib/cucumber/configuration.rb', line 161 def autoload_code_paths @options[:autoload_code_paths] end |
#custom_profiles ⇒ Object
149 150 151 |
# File 'lib/cucumber/configuration.rb', line 149 def custom_profiles profiles - [@options[:default_profile]] end |
#dry_run? ⇒ Boolean
89 90 91 |
# File 'lib/cucumber/configuration.rb', line 89 def dry_run? @options[:dry_run] end |
#duration? ⇒ Boolean
133 134 135 |
# File 'lib/cucumber/configuration.rb', line 133 def duration? @options[:duration] end |
#error_stream ⇒ Object
73 74 75 |
# File 'lib/cucumber/configuration.rb', line 73 def error_stream @options[:error_stream] end |
#event_bus ⇒ Object
280 281 282 |
# File 'lib/cucumber/configuration.rb', line 280 def event_bus @options[:event_bus] end |
#expand? ⇒ Boolean
125 126 127 |
# File 'lib/cucumber/configuration.rb', line 125 def @options[:expand] end |
#fail_fast? ⇒ Boolean
101 102 103 |
# File 'lib/cucumber/configuration.rb', line 101 def fail_fast? @options[:fail_fast] end |
#feature_dirs ⇒ Object
169 170 171 172 173 |
# File 'lib/cucumber/configuration.rb', line 169 def feature_dirs dirs = paths.map { |f| File.directory?(f) ? f : File.dirname(f) }.uniq dirs.delete('.') unless paths.include?('.') with_default_features_path(dirs) end |
#feature_files ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/cucumber/configuration.rb', line 191 def feature_files potential_feature_files = with_default_features_path(paths).map do |path| path = path.tr('\\', '/') # In case we're on windows. Globs don't work with backslashes. path = path.chomp('/') # TODO: Move to using feature loading strategies stored in # options[:feature_loaders] if File.directory?(path) Dir["#{path}/**/*.feature"].sort elsif Cli::RerunFile.can_read?(path) Cli::RerunFile.new(path).features else path end end.flatten.uniq remove_excluded_files_from(potential_feature_files) potential_feature_files end |
#filters ⇒ Object
187 188 189 |
# File 'lib/cucumber/configuration.rb', line 187 def filters @options[:filters] end |
#formats ⇒ Object
157 158 159 |
# File 'lib/cucumber/configuration.rb', line 157 def formats @options[:formats] end |
#formatter_class(format) ⇒ Object
249 250 251 252 253 254 255 |
# File 'lib/cucumber/configuration.rb', line 249 def formatter_class(format) if (builtin = Cli::Options::BUILTIN_FORMATS[format]) constantize(builtin[0]) else constantize(format) end end |
#formatter_factories ⇒ Object
238 239 240 241 242 243 244 245 246 247 |
# File 'lib/cucumber/configuration.rb', line 238 def formatter_factories formats.map do |format, , path_or_io| factory = formatter_class(format) yield factory, , path_or_io rescue Exception => e raise e, "#{e.}\nError creating formatter: #{format}", e.backtrace end end |
#guess? ⇒ Boolean
113 114 115 |
# File 'lib/cucumber/configuration.rb', line 113 def guess? @options[:guess] end |
#id_generator ⇒ Object
284 285 286 |
# File 'lib/cucumber/configuration.rb', line 284 def id_generator @id_generator ||= Cucumber::Messages::Helpers::IdGenerator::UUID.new end |
#name_regexps ⇒ Object
183 184 185 |
# File 'lib/cucumber/configuration.rb', line 183 def name_regexps @options[:name_regexps] end |
#notify(message, *args) ⇒ Object
57 58 59 |
# File 'lib/cucumber/configuration.rb', line 57 def notify(, *args) event_bus.send(, *args) end |
#on_event {|Object| ... } ⇒ Object
Subscribe to an event.
See Events for the list of possible events.
54 |
# File 'lib/cucumber/configuration.rb', line 54 def_instance_delegator :event_bus, :on, :on_event |
#out_stream ⇒ Object
69 70 71 |
# File 'lib/cucumber/configuration.rb', line 69 def out_stream @options[:out_stream] end |
#paths ⇒ Object
153 154 155 |
# File 'lib/cucumber/configuration.rb', line 153 def paths @options[:paths] end |
#profiles ⇒ Object
145 146 147 |
# File 'lib/cucumber/configuration.rb', line 145 def profiles @options[:profiles] || [] end |
#publish_enabled? ⇒ Boolean
93 94 95 |
# File 'lib/cucumber/configuration.rb', line 93 def publish_enabled? @options[:publish_enabled] end |
#publish_quiet? ⇒ Boolean
97 98 99 |
# File 'lib/cucumber/configuration.rb', line 97 def publish_quiet? @options[:publish_quiet] end |
#randomize? ⇒ Boolean
77 78 79 |
# File 'lib/cucumber/configuration.rb', line 77 def randomize? @options[:order] == 'random' end |
#register_snippet_generator(generator) ⇒ Object
275 276 277 278 |
# File 'lib/cucumber/configuration.rb', line 275 def register_snippet_generator(generator) snippet_generators << generator self end |
#retry_attempts ⇒ Object
105 106 107 |
# File 'lib/cucumber/configuration.rb', line 105 def retry_attempts @options[:retry] end |
#retry_total_tests ⇒ Object
109 110 111 |
# File 'lib/cucumber/configuration.rb', line 109 def retry_total_tests @options[:retry_total] end |
#reverse_order? ⇒ Boolean
81 82 83 |
# File 'lib/cucumber/configuration.rb', line 81 def reverse_order? @options[:order] == 'reverse' end |
#seed ⇒ Object
85 86 87 |
# File 'lib/cucumber/configuration.rb', line 85 def seed @options[:seed] end |
#skip_profile_information? ⇒ Boolean
141 142 143 |
# File 'lib/cucumber/configuration.rb', line 141 def skip_profile_information? @options[:skip_profile_information] end |
#snippet_generators ⇒ Object
An array of procs that can generate snippets for undefined steps. These procs may be called if a formatter wants to display snippets to the user.
Each proc should take the following arguments:
- keyword
- step text
- multiline argument
- snippet type
271 272 273 |
# File 'lib/cucumber/configuration.rb', line 271 def snippet_generators @options[:snippet_generators] ||= [] end |
#snippet_type ⇒ Object
165 166 167 |
# File 'lib/cucumber/configuration.rb', line 165 def snippet_type @options[:snippet_type] end |
#snippets? ⇒ Boolean
137 138 139 |
# File 'lib/cucumber/configuration.rb', line 137 def snippets? @options[:snippets] end |
#source? ⇒ Boolean
129 130 131 |
# File 'lib/cucumber/configuration.rb', line 129 def source? @options[:source] end |
#step_defs_to_load ⇒ Object
234 235 236 |
# File 'lib/cucumber/configuration.rb', line 234 def step_defs_to_load all_files_to_load.reject { |f| f =~ /\/support\// } end |
#strict ⇒ Object
117 118 119 |
# File 'lib/cucumber/configuration.rb', line 117 def strict @options[:strict] end |
#support_to_load ⇒ Object
210 211 212 213 214 215 216 217 218 219 |
# File 'lib/cucumber/configuration.rb', line 210 def support_to_load support_files = all_files_to_load.select { |f| f =~ /\/support\// } # env_files are separated from other_files so we can ensure env files # load first. # env_files = support_files.select { |f| f =~ /\/support\/env\..*/ } other_files = support_files - env_files env_files.reverse + other_files.reverse end |
#tag_expressions ⇒ Object
179 180 181 |
# File 'lib/cucumber/configuration.rb', line 179 def tag_expressions @options[:tag_expressions] end |
#tag_limits ⇒ Object
175 176 177 |
# File 'lib/cucumber/configuration.rb', line 175 def tag_limits @options[:tag_limits] end |
#to_hash ⇒ Object
257 258 259 |
# File 'lib/cucumber/configuration.rb', line 257 def to_hash @options end |
#wip? ⇒ Boolean
121 122 123 |
# File 'lib/cucumber/configuration.rb', line 121 def wip? @options[:wip] end |
#with_options(new_options) ⇒ Object
65 66 67 |
# File 'lib/cucumber/configuration.rb', line 65 def () self.class.new(@options.merge()) end |