Class: Cucumber::Configuration
Overview
The base class for configuring settings for a Cucumber run.
Class Method Summary
collapse
Instance Method Summary
collapse
#constantize, #underscore
Constructor Details
#initialize(user_options = {}) ⇒ Configuration
Returns a new instance of Configuration.
30
31
32
|
# File 'lib/cucumber/configuration.rb', line 30
def initialize(user_options = {})
@options = default_options.merge(Cucumber::Hash(user_options))
end
|
Class Method Details
13
14
15
|
# File 'lib/cucumber/configuration.rb', line 13
def self.default
new
end
|
Instance Method Details
#all_files_to_load ⇒ Object
157
158
159
160
161
162
163
164
165
166
167
168
|
# File 'lib/cucumber/configuration.rb', line 157
def all_files_to_load
files = require_dirs.map do |path|
path = path.gsub(/\\/, '/') path = path.gsub(/\/$/, '') 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) == '.goal' }
files.reject! {|f| f =~ /^http/}
files.sort
end
|
#autoload_code_paths ⇒ Object
96
97
98
|
# File 'lib/cucumber/configuration.rb', line 96
def autoload_code_paths
@options[:autoload_code_paths]
end
|
#dry_run? ⇒ Boolean
60
61
62
|
# File 'lib/cucumber/configuration.rb', line 60
def dry_run?
@options[:dry_run]
end
|
#error_stream ⇒ Object
48
49
50
|
# File 'lib/cucumber/configuration.rb', line 48
def error_stream
@options[:error_stream]
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_dirs ⇒ Object
104
105
106
107
108
|
# File 'lib/cucumber/configuration.rb', line 104
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
# File 'lib/cucumber/configuration.rb', line 131
def feature_files
potential_feature_files = with_default_features_path(paths).map do |path|
path = path.gsub(/\\/, '/') path = path.chomp('/')
if File.directory?(path)
Dir["#{path}/**/*.goal"].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
|
127
128
129
|
# File 'lib/cucumber/configuration.rb', line 127
def filters
@options[:filters]
end
|
92
93
94
|
# File 'lib/cucumber/configuration.rb', line 92
def formats
@options[:formats]
end
|
188
189
190
191
192
193
194
|
# File 'lib/cucumber/configuration.rb', line 188
def formatter_class(format)
if(builtin = Cli::Options::BUILTIN_FORMATS[format])
constantize(builtin[0])
else
constantize(format)
end
end
|
174
175
176
177
178
179
180
181
182
183
184
185
186
|
# File 'lib/cucumber/configuration.rb', line 174
def formatter_factories
@options[:formats].map do |format_and_out|
format = format_and_out[0]
path_or_io = format_and_out[1]
begin
factory = formatter_class(format)
yield factory, path_or_io, Cli::Options.new(STDOUT, STDERR, @options)
rescue Exception => e
e.message << "\nError creating formatter: #{format}"
raise e
end
end
end
|
#guess? ⇒ Boolean
72
73
74
|
# File 'lib/cucumber/configuration.rb', line 72
def guess?
@options[:guess]
end
|
#name_regexps ⇒ Object
123
124
125
|
# File 'lib/cucumber/configuration.rb', line 123
def name_regexps
@options[:name_regexps]
end
|
#on_event {|Object| ... } ⇒ Object
Subscribe to an event.
See Events for the list of possible events.
25
|
# File 'lib/cucumber/configuration.rb', line 25
def_instance_delegator :event_bus, :register, :on_event
|
TODO: Actually Deprecate???
39
40
41
42
|
# File 'lib/cucumber/configuration.rb', line 39
def options
warn("Deprecated: Configuration#options will be removed from the next release of Cucumber. Please use the configuration object directly instead.")
Marshal.load(Marhal.dump(@options))
end
|
#out_stream ⇒ Object
44
45
46
|
# File 'lib/cucumber/configuration.rb', line 44
def out_stream
@options[:out_stream]
end
|
88
89
90
|
# File 'lib/cucumber/configuration.rb', line 88
def paths
@options[:paths]
end
|
#randomize? ⇒ Boolean
52
53
54
|
# File 'lib/cucumber/configuration.rb', line 52
def randomize?
@options[:order] == 'random'
end
|
#register_snippet_generator(generator) ⇒ Object
214
215
216
217
|
# File 'lib/cucumber/configuration.rb', line 214
def register_snippet_generator(generator)
snippet_generators << generator
self
end
|
#retry_attempts ⇒ Object
68
69
70
|
# File 'lib/cucumber/configuration.rb', line 68
def retry_attempts
@options[:retry]
end
|
56
57
58
|
# File 'lib/cucumber/configuration.rb', line 56
def seed
Integer(@options[:seed] || rand(0xFFFF))
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
210
211
212
|
# File 'lib/cucumber/configuration.rb', line 210
def snippet_generators
@options[:snippet_generators] ||= []
end
|
#snippet_type ⇒ Object
100
101
102
|
# File 'lib/cucumber/configuration.rb', line 100
def snippet_type
@options[:snippet_type]
end
|
#step_defs_to_load ⇒ Object
170
171
172
|
# File 'lib/cucumber/configuration.rb', line 170
def step_defs_to_load
all_files_to_load.reject {|f| f =~ %r{/support/} }
end
|
#strict? ⇒ Boolean
76
77
78
|
# File 'lib/cucumber/configuration.rb', line 76
def strict?
@options[:strict]
end
|
#support_to_load ⇒ Object
150
151
152
153
154
155
|
# File 'lib/cucumber/configuration.rb', line 150
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_expression ⇒ Object
111
112
113
|
# File 'lib/cucumber/configuration.rb', line 111
def tag_expression
Cucumber::Core::Gherkin::TagExpression.new(@options[:tag_expressions])
end
|
#tag_expressions ⇒ Object
119
120
121
|
# File 'lib/cucumber/configuration.rb', line 119
def tag_expressions
@options[:tag_expressions]
end
|
#tag_limits ⇒ Object
115
116
117
|
# File 'lib/cucumber/configuration.rb', line 115
def tag_limits
tag_expression.limits.to_hash
end
|
196
197
198
|
# File 'lib/cucumber/configuration.rb', line 196
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
34
35
36
|
# File 'lib/cucumber/configuration.rb', line 34
def with_options(new_options)
self.class.new(@options.merge(new_options))
end
|