class Cucumber::Configuration

The base class for configuring settings for a Cucumber run.

Public Class Methods

default() click to toggle source
# File lib/cucumber/configuration.rb, line 18
def self.default
  new
end
new(user_options = {}) click to toggle source
# File lib/cucumber/configuration.rb, line 37
def initialize(user_options = {})
  @options = default_options.merge(Hash(user_options))
end

Public Instance Methods

all_files_to_load() click to toggle source
# File lib/cucumber/configuration.rb, line 189
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. # rubocop:disable Style/RegexpLiteral
    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() click to toggle source
# File lib/cucumber/configuration.rb, line 129
def autoload_code_paths
  @options[:autoload_code_paths]
end
custom_profiles() click to toggle source
# File lib/cucumber/configuration.rb, line 117
def custom_profiles
  profiles - [@options[:default_profile]]
end
dry_run?() click to toggle source
# File lib/cucumber/configuration.rb, line 61
def dry_run?
  @options[:dry_run]
end
duration?() click to toggle source
# File lib/cucumber/configuration.rb, line 101
def duration?
  @options[:duration]
end
error_stream() click to toggle source
# File lib/cucumber/configuration.rb, line 49
def error_stream
  @options[:error_stream]
end
event_bus() click to toggle source
# File lib/cucumber/configuration.rb, line 248
def event_bus
  @options[:event_bus]
end
expand?() click to toggle source
# File lib/cucumber/configuration.rb, line 93
def expand?
  @options[:expand]
end
fail_fast?() click to toggle source
# File lib/cucumber/configuration.rb, line 73
def fail_fast?
  @options[:fail_fast]
end
feature_dirs() click to toggle source
# File lib/cucumber/configuration.rb, line 137
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() click to toggle source
# File lib/cucumber/configuration.rb, line 159
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() click to toggle source
# File lib/cucumber/configuration.rb, line 155
def filters
  @options[:filters]
end
formats() click to toggle source
# File lib/cucumber/configuration.rb, line 125
def formats
  @options[:formats]
end
formatter_class(format) click to toggle source
# File lib/cucumber/configuration.rb, line 217
def formatter_class(format)
  if (builtin = Cli::Options::BUILTIN_FORMATS[format])
    constantize(builtin[0])
  else
    constantize(format)
  end
end
formatter_factories() { |factory, formatter_options, path_or_io| ... } click to toggle source
# File lib/cucumber/configuration.rb, line 206
def formatter_factories
  formats.map do |format, formatter_options, path_or_io|
    factory = formatter_class(format)
    yield factory,
          formatter_options,
          path_or_io
  rescue Exception => e # rubocop:disable Lint/RescueException
    raise e, "#{e.message}\nError creating formatter: #{format}", e.backtrace
  end
end
guess?() click to toggle source
# File lib/cucumber/configuration.rb, line 81
def guess?
  @options[:guess]
end
id_generator() click to toggle source
# File lib/cucumber/configuration.rb, line 252
def id_generator
  @id_generator ||= Cucumber::Messages::IdGenerator::UUID.new
end
name_regexps() click to toggle source
# File lib/cucumber/configuration.rb, line 151
def name_regexps
  @options[:name_regexps]
end
notify(message, *args) click to toggle source

@private

# File lib/cucumber/configuration.rb, line 33
def notify(message, *args)
  event_bus.send(message, *args)
end
out_stream() click to toggle source
# File lib/cucumber/configuration.rb, line 45
def out_stream
  @options[:out_stream]
end
paths() click to toggle source
# File lib/cucumber/configuration.rb, line 121
def paths
  @options[:paths]
end
profiles() click to toggle source
# File lib/cucumber/configuration.rb, line 113
def profiles
  @options[:profiles] || []
end
publish_enabled?() click to toggle source
# File lib/cucumber/configuration.rb, line 65
def publish_enabled?
  @options[:publish_enabled]
end
publish_quiet?() click to toggle source
# File lib/cucumber/configuration.rb, line 69
def publish_quiet?
  @options[:publish_quiet]
end
randomize?() click to toggle source
# File lib/cucumber/configuration.rb, line 53
def randomize?
  @options[:order] == 'random'
end
register_snippet_generator(generator) click to toggle source
# File lib/cucumber/configuration.rb, line 243
def register_snippet_generator(generator)
  snippet_generators << generator
  self
end
retry_attempts() click to toggle source
# File lib/cucumber/configuration.rb, line 77
def retry_attempts
  @options[:retry]
end
seed() click to toggle source
# File lib/cucumber/configuration.rb, line 57
def seed
  @options[:seed]
end
skip_profile_information?() click to toggle source
# File lib/cucumber/configuration.rb, line 109
def skip_profile_information?
  @options[:skip_profile_information]
end
snippet_generators() click to toggle source

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
# File lib/cucumber/configuration.rb, line 239
def snippet_generators
  @options[:snippet_generators] ||= []
end
snippet_type() click to toggle source
# File lib/cucumber/configuration.rb, line 133
def snippet_type
  @options[:snippet_type]
end
snippets?() click to toggle source
# File lib/cucumber/configuration.rb, line 105
def snippets?
  @options[:snippets]
end
source?() click to toggle source
# File lib/cucumber/configuration.rb, line 97
def source?
  @options[:source]
end
step_defs_to_load() click to toggle source
# File lib/cucumber/configuration.rb, line 202
def step_defs_to_load
  all_files_to_load.reject { |f| f =~ %r{/support/} }
end
strict() click to toggle source
# File lib/cucumber/configuration.rb, line 85
def strict
  @options[:strict]
end
support_to_load() click to toggle source
# File lib/cucumber/configuration.rb, line 178
def support_to_load
  support_files = all_files_to_load.select { |f| f =~ %r{/support/} }

  # env_files are separated from other_files so we can ensure env files
  # load first.
  #
  env_files = support_files.select { |f| f =~ %r{/support/env\..*} }
  other_files = support_files - env_files
  env_files.reverse + other_files.reverse
end
tag_expressions() click to toggle source
# File lib/cucumber/configuration.rb, line 147
def tag_expressions
  @options[:tag_expressions]
end
tag_limits() click to toggle source
# File lib/cucumber/configuration.rb, line 143
def tag_limits
  @options[:tag_limits]
end
to_hash() click to toggle source
# File lib/cucumber/configuration.rb, line 225
def to_hash
  @options
end
wip?() click to toggle source
# File lib/cucumber/configuration.rb, line 89
def wip?
  @options[:wip]
end
with_options(new_options) click to toggle source
# File lib/cucumber/configuration.rb, line 41
def with_options(new_options)
  self.class.new(@options.merge(new_options))
end

Private Instance Methods

default_features_paths() click to toggle source
# File lib/cucumber/configuration.rb, line 280
def default_features_paths
  ['features']
end
default_options() click to toggle source
# File lib/cucumber/configuration.rb, line 258
def default_options
  {
    autoload_code_paths: ['features/support', 'features/step_definitions'],
    filters: [],
    strict: Cucumber::Core::Test::Result::StrictConfiguration.new,
    require: [],
    dry_run: false,
    publish_quiet: 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
  }
end
remove_excluded_files_from(files) click to toggle source
# File lib/cucumber/configuration.rb, line 289
def remove_excluded_files_from(files)
  files.reject! { |path| @options[:excludes].detect { |pattern| path =~ pattern } }
end
require_dirs() click to toggle source
# File lib/cucumber/configuration.rb, line 293
def require_dirs
  if @options[:require].empty?
    default_features_paths + Dir['vendor/{gems,plugins}/*/cucumber']
  else
    @options[:require]
  end
end
with_default_features_path(paths) click to toggle source
# File lib/cucumber/configuration.rb, line 284
def with_default_features_path(paths)
  return default_features_paths if paths.empty?
  paths
end