Class: Cucumber::Configuration

Inherits:
Object
  • Object
show all
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

Methods included from Constantize

#constantize, #underscore

Constructor Details

#initialize(user_options = {}) ⇒ Configuration



36
37
38
# File 'lib/cucumber/configuration.rb', line 36

def initialize(user_options = {})
  @options = default_options.merge(Hash(user_options))
end

Class Method Details

.defaultObject



17
18
19
# File 'lib/cucumber/configuration.rb', line 17

def self.default
  new
end

Instance Method Details

#all_files_to_loadObject



176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/cucumber/configuration.rb', line 176

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.reject! { |f| !File.file?(f) }
  files.reject! { |f| File.extname(f) == '.feature' }
  files.reject! { |f| f =~ /^http/ }
  files.sort
end

#autoload_code_pathsObject



120
121
122
# File 'lib/cucumber/configuration.rb', line 120

def autoload_code_paths
  @options[:autoload_code_paths]
end

#custom_profilesObject



108
109
110
# File 'lib/cucumber/configuration.rb', line 108

def custom_profiles
  profiles - [@options[:default_profile]]
end

#dry_run?Boolean



60
61
62
# File 'lib/cucumber/configuration.rb', line 60

def dry_run?
  @options[:dry_run]
end

#duration?Boolean



92
93
94
# File 'lib/cucumber/configuration.rb', line 92

def duration?
  @options[:duration]
end

#error_streamObject



48
49
50
# File 'lib/cucumber/configuration.rb', line 48

def error_stream
  @options[:error_stream]
end

#event_busObject



238
239
240
# File 'lib/cucumber/configuration.rb', line 238

def event_bus
  @options[:event_bus]
end

#expand?Boolean



84
85
86
# File 'lib/cucumber/configuration.rb', line 84

def expand?
  @options[:expand]
end

#fail_fast?Boolean



64
65
66
# File 'lib/cucumber/configuration.rb', line 64

def fail_fast?
  @options[:fail_fast]
end

#feature_dirsObject



128
129
130
131
132
# File 'lib/cucumber/configuration.rb', line 128

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_filesObject



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/cucumber/configuration.rb', line 150

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

#filtersObject



146
147
148
# File 'lib/cucumber/configuration.rb', line 146

def filters
  @options[:filters]
end

#formatsObject



116
117
118
# File 'lib/cucumber/configuration.rb', line 116

def formats
  @options[:formats]
end

#formatter_class(format) ⇒ Object



207
208
209
210
211
212
213
# File 'lib/cucumber/configuration.rb', line 207

def formatter_class(format)
  if (builtin = Cli::Options::BUILTIN_FORMATS[format])
    constantize(builtin[0])
  else
    constantize(format)
  end
end

#formatter_factoriesObject



193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/cucumber/configuration.rb', line 193

def formatter_factories
  formats.map do |format, formatter_options, path_or_io|
    begin
      factory = formatter_class(format)
      yield factory,
            formatter_options,
            path_or_io,
            Cli::Options.new(STDOUT, STDERR, @options)
    rescue Exception => e
      raise e, "#{e.message}\nError creating formatter: #{format}", e.backtrace
    end
  end
end

#guess?Boolean



72
73
74
# File 'lib/cucumber/configuration.rb', line 72

def guess?
  @options[:guess]
end

#name_regexpsObject



142
143
144
# File 'lib/cucumber/configuration.rb', line 142

def name_regexps
  @options[:name_regexps]
end

#notify(message, *args) ⇒ Object



32
33
34
# File 'lib/cucumber/configuration.rb', line 32

def notify(message, *args)
  event_bus.send(message, *args)
end

#on_event {|Object| ... } ⇒ Object

Subscribe to an event.

See Events for the list of possible events.

Yields:

  • (Object)

    Block to be called when the event occurs



29
# File 'lib/cucumber/configuration.rb', line 29

def_instance_delegator :event_bus, :on, :on_event

#out_streamObject



44
45
46
# File 'lib/cucumber/configuration.rb', line 44

def out_stream
  @options[:out_stream]
end

#pathsObject



112
113
114
# File 'lib/cucumber/configuration.rb', line 112

def paths
  @options[:paths]
end

#profilesObject



104
105
106
# File 'lib/cucumber/configuration.rb', line 104

def profiles
  @options[:profiles] || []
end

#randomize?Boolean



52
53
54
# File 'lib/cucumber/configuration.rb', line 52

def randomize?
  @options[:order] == 'random'
end

#register_snippet_generator(generator) ⇒ Object



233
234
235
236
# File 'lib/cucumber/configuration.rb', line 233

def register_snippet_generator(generator)
  snippet_generators << generator
  self
end

#retry_attemptsObject



68
69
70
# File 'lib/cucumber/configuration.rb', line 68

def retry_attempts
  @options[:retry]
end

#seedObject



56
57
58
# File 'lib/cucumber/configuration.rb', line 56

def seed
  Integer(@options[:seed] || rand(0xFFFF))
end

#skip_profile_information?Boolean



100
101
102
# File 'lib/cucumber/configuration.rb', line 100

def skip_profile_information?
  @options[:skip_profile_information]
end

#snippet_generatorsObject

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


229
230
231
# File 'lib/cucumber/configuration.rb', line 229

def snippet_generators
  @options[:snippet_generators] ||= []
end

#snippet_typeObject



124
125
126
# File 'lib/cucumber/configuration.rb', line 124

def snippet_type
  @options[:snippet_type]
end

#snippets?Boolean



96
97
98
# File 'lib/cucumber/configuration.rb', line 96

def snippets?
  @options[:snippets]
end

#source?Boolean



88
89
90
# File 'lib/cucumber/configuration.rb', line 88

def source?
  @options[:source]
end

#step_defs_to_loadObject



189
190
191
# File 'lib/cucumber/configuration.rb', line 189

def step_defs_to_load
  all_files_to_load.reject { |f| f =~ %r{/support/} }
end

#strictObject



76
77
78
# File 'lib/cucumber/configuration.rb', line 76

def strict
  @options[:strict]
end

#support_to_loadObject



169
170
171
172
173
174
# File 'lib/cucumber/configuration.rb', line 169

def support_to_load
  support_files = all_files_to_load.select { |f| f =~ %r{/support/} }
  env_files = support_files.select { |f| f =~ %r{/support/env\..*} }
  other_files = support_files - env_files
  @options[:dry_run] ? other_files : env_files + other_files
end

#tag_expressionsObject



138
139
140
# File 'lib/cucumber/configuration.rb', line 138

def tag_expressions
  @options[:tag_expressions]
end

#tag_limitsObject



134
135
136
# File 'lib/cucumber/configuration.rb', line 134

def tag_limits
  @options[:tag_limits]
end

#to_hashObject



215
216
217
# File 'lib/cucumber/configuration.rb', line 215

def to_hash
  @options
end

#wip?Boolean



80
81
82
# File 'lib/cucumber/configuration.rb', line 80

def wip?
  @options[:wip]
end

#with_options(new_options) ⇒ Object



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

def with_options(new_options)
  self.class.new(@options.merge(new_options))
end