Responsible for utilizing externally provided configuration options, whether via the command line, `.rspec`, `~/.rspec`, `.rspec-local` or a custom options file.
@return [Hash] the final merged options, drawn from all external sources
@param args [Array<String>] command line arguments
# File lib/rspec/core/configuration_options.rb, line 11 def initialize(args) @args = args.dup organize_options end
Updates the provided {Configuration} instance based on the provided external configuration options.
@param config [Configuration] the configuration instance to update
# File lib/rspec/core/configuration_options.rb, line 20 def configure(config) process_options_into config configure_filter_manager config.filter_manager load_formatters_into config end
@api private Updates the provided {FilterManager} based on the filter options. @param filter_manager [FilterManager] instance to update
# File lib/rspec/core/configuration_options.rb, line 29 def configure_filter_manager(filter_manager) @filter_manager_options.each do |command, value| filter_manager.__send__ command, value end end
# File lib/rspec/core/configuration_options.rb, line 161 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
# File lib/rspec/core/configuration_options.rb, line 130 def command_line_options @command_line_options ||= Parser.parse(@args) end
# File lib/rspec/core/configuration_options.rb, line 134 def custom_options options_from(custom_options_file) end
# File lib/rspec/core/configuration_options.rb, line 171 def custom_options_file command_line_options[:custom_options_file] end
# File lib/rspec/core/configuration_options.rb, line 121 def env_options return {} unless ENV['SPEC_OPTS'] parse_args_ignoring_files_or_dirs_to_run( Shellwords.split(ENV["SPEC_OPTS"]), "ENV['SPEC_OPTS']" ) end
# File lib/rspec/core/configuration_options.rb, line 117 def file_options custom_options_file ? [custom_options] : [global_options, project_options, local_options] end
# File lib/rspec/core/configuration_options.rb, line 62 def force?(key) !UNFORCED_OPTIONS.include?(key) end
# File lib/rspec/core/configuration_options.rb, line 146 def global_options @global_options ||= options_from(global_options_file) end
# File lib/rspec/core/configuration_options.rb, line 183 def global_options_file File.join(File.expand_path("~"), ".rspec") rescue ArgumentError RSpec.warning "Unable to find ~/.rspec because the HOME environment variable is not set" nil end
# File lib/rspec/core/configuration_options.rb, line 113 def load_formatters_into(config) options[:formatters].each { |pair| config.add_formatter(*pair) } if options[:formatters] end
# File lib/rspec/core/configuration_options.rb, line 138 def local_options @local_options ||= options_from(local_options_file) end
# File lib/rspec/core/configuration_options.rb, line 179 def local_options_file "./.rspec-local" end
# File lib/rspec/core/configuration_options.rb, line 167 def options_file_as_erb_string(path) ERB.new(File.read(path), nil, '-').result(binding) end
# File lib/rspec/core/configuration_options.rb, line 150 def options_from(path) args = args_from_options_file(path) parse_args_ignoring_files_or_dirs_to_run(args, path) end
# File lib/rspec/core/configuration_options.rb, line 66 def order(keys) OPTIONS_ORDER.reverse_each do |key| keys.unshift(key) if keys.delete(key) end keys end
# File lib/rspec/core/configuration_options.rb, line 40 def organize_options @filter_manager_options = [] @options = (file_options << command_line_options << env_options).each do |opts| @filter_manager_options << [:include, opts.delete(:inclusion_filter)] if opts.key?(:inclusion_filter) @filter_manager_options << [:exclude, opts.delete(:exclusion_filter)] if opts.key?(:exclusion_filter) end @options = @options.inject(:libs => [], :requires => []) do |hash, opts| hash.merge(opts) do |key, oldval, newval| [:libs, :requires].include?(key) ? oldval + newval : newval end end end
# File lib/rspec/core/configuration_options.rb, line 155 def parse_args_ignoring_files_or_dirs_to_run(args, source) options = Parser.parse(args, source) options.delete(:files_or_directories_to_run) options end
# File lib/rspec/core/configuration_options.rb, line 105 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
# File lib/rspec/core/configuration_options.rb, line 142 def project_options @project_options ||= options_from(project_options_file) end
# File lib/rspec/core/configuration_options.rb, line 175 def project_options_file "./.rspec" end