class RSpec::Core::ConfigurationOptions
or a custom options file.
whether via the command line, ‘.rspec`, `~/.rspec`, `.rspec-local`
Responsible for utilizing externally provided configuration options,
def args_from_options_file(path)
def args_from_options_file(path) return [] unless path && File.exist?(path) config_string = options_file_as_erb_string(path) FlatMap.flat_map(config_string.split(/\n+/), &:shellsplit) end
def command_line_options
def command_line_options @command_line_options ||= Parser.parse(@args).merge :files_or_directories_to_run => @args end
def configure(config)
-
config
(Configuration
) -- the configuration instance to update
def configure(config) process_options_into config configure_filter_manager config.filter_manager load_formatters_into config end
def configure_filter_manager(filter_manager)
-
filter_manager
(FilterManager
) -- instance to update
Other tags:
- Api: - private
def configure_filter_manager(filter_manager) @filter_manager_inclusions.each { |val| filter_manager.include(val) } @filter_manager_exclusions.each { |val| filter_manager.exclude(val) } end
def custom_options
def custom_options options_from(custom_options_file) end
def custom_options_file
def custom_options_file command_line_options[:custom_options_file] end
def env_options
def env_options ENV["SPEC_OPTS"] ? Parser.parse(Shellwords.split(ENV["SPEC_OPTS"])) : {} end
def file_options
def file_options custom_options_file ? [custom_options] : [global_options, project_options, local_options] end
def force?(key)
def force?(key) !UNFORCED_OPTIONS.include?(key) end
def global_options
def global_options @global_options ||= options_from(global_options_file) end
def global_options_file
def global_options_file begin File.join(File.expand_path("~"), ".rspec") rescue ArgumentError RSpec.warning "Unable to find ~/.rspec because the HOME environment variable is not set" nil end end
def initialize(args)
-
args
(Array
) -- command line arguments
def initialize(args) @args = args.dup organize_options end
def load_formatters_into(config)
def load_formatters_into(config) options[:formatters].each { |pair| config.add_formatter(*pair) } if options[:formatters] end
def local_options
def local_options @local_options ||= options_from(local_options_file) end
def local_options_file
def local_options_file ".rspec-local" end
def options_file_as_erb_string(path)
def options_file_as_erb_string(path) ERB.new(File.read(path), nil, '-').result(binding) end
def options_from(path)
def options_from(path) Parser.parse(args_from_options_file(path)) end
def order(keys)
def order(keys) OPTIONS_ORDER.reverse.each do |key| keys.unshift(key) if keys.delete(key) end keys end
def organize_options
def organize_options @filter_manager_inclusions = [] @filter_manager_exclusions = [] @options = (file_options << command_line_options << env_options).each { |opts| @filter_manager_inclusions << opts.delete(:inclusion_filter) if opts.key?(:inclusion_filter) @filter_manager_exclusions << opts.delete(:exclusion_filter) if opts.key?(:exclusion_filter) }.inject(:libs => [], :requires => []) { |hash, opts| hash.merge(opts) { |key, oldval, newval| [:libs, :requires].include?(key) ? oldval + newval : newval } } end
def process_options_into(config)
def process_options_into(config) opts = options.reject { |k, _| UNPROCESSABLE_OPTIONS.include? k } order(opts.keys).each do |key| force?(key) ? config.force(key => opts[key]) : config.__send__("#{key}=", opts[key]) end end
def project_options
def project_options @project_options ||= options_from(project_options_file) end
def project_options_file
def project_options_file ".rspec" end