Class: RSpec::Core::ConfigurationOptions
Relationships & Source Files | |
Inherits: | Object |
Defined in: | rspec-core/lib/rspec/core/configuration_options.rb |
Overview
Responsible for utilizing externally provided configuration options, whether via the command line, .rspec
, ~/.rspec
, $XDG_CONFIG_HOME/rspec/options
, .rspec-local
or a custom options file.
Constant Summary
-
OPTIONS_ORDER =
# File 'rspec-core/lib/rspec/core/configuration_options.rb', line 77[ # It's important to set this before anything that might issue a # deprecation (or otherwise access the reporter). :deprecation_stream, # In order for `RSpec.configuration.dry_run?` to return `true` during # processing the `requires` option, it must be parsed before it. :dry_run, # load paths depend on nothing, but must be set before `requires` # to support load-path-relative requires. :libs, # `files_or_directories_to_run` uses `default_path` so it must be # set before it. :default_path, :only_failures, # These must be set before `requires` to support checking # `config.files_to_run` from within `spec_helper.rb` when a # `-rspec_helper` option is used. :files_or_directories_to_run, :pattern, :exclude_pattern, # Necessary so that the `--seed` option is applied before requires, # in case required files do something with the provided seed. # (such as seed global randomization with it). :order, # In general, we want to require the specified files as early as # possible. The `--require` option is specifically intended to allow # early requires. For later requires, they can just put the require in # their spec files, but `--require` provides a unique opportunity for # users to instruct RSpec to load an extension file early for maximum # flexibility. :requires ]
-
UNFORCED_OPTIONS =
# File 'rspec-core/lib/rspec/core/configuration_options.rb', line 59Set.new([ :requires, :profile, :drb, :libs, :files_or_directories_to_run, :full_description, :full_backtrace, :tty ])
-
UNPROCESSABLE_OPTIONS =
# File 'rspec-core/lib/rspec/core/configuration_options.rb', line 64Set.new([:formatters])
Class Method Summary
- .new(args) ⇒ ConfigurationOptions constructor
Instance Attribute Summary
- #args ⇒ Array<String> readonly
- #options ⇒ Hash readonly
Instance Method Summary
-
#configure(config)
Updates the provided
Configuration
instance based on the provided external configuration options. -
#configure_filter_manager(filter_manager)
Internal use only
Internal use only
Updates the provided
FilterManager
based on the filter options. - #args_from_options_file(path) private
- #command_line_options private
- #custom_options private
-
#custom_options_file
private
:nocov:
- #env_options private
- #file_options private
- #force?(key) ⇒ Boolean private
- #global_options private
- #global_options_file private
- #home_options_file_path private
- #load_formatters_into(config) private
- #local_options private
- #local_options_file private
-
#options_file_as_erb_string(path)
private
:nocov:
- #options_from(path) private
- #order(keys) private
- #organize_options private
- #parse_args_ignoring_files_or_dirs_to_run(args, source) private
- #process_options_into(config) private
- #project_options private
- #project_options_file private
- #resolve_xdg_config_home private
- #xdg_options_file_if_exists private
- #xdg_options_file_path private
Constructor Details
.new(args) ⇒ ConfigurationOptions
Instance Attribute Details
#args ⇒ Array
<String
> (readonly)
# File 'rspec-core/lib/rspec/core/configuration_options.rb', line 40
attr_reader :args
#options ⇒ Hash
(readonly)
# File 'rspec-core/lib/rspec/core/configuration_options.rb', line 37
attr_reader :
Instance Method Details
#args_from_options_file(path) (private)
[ GitHub ]#command_line_options (private)
[ GitHub ]#configure(config)
Updates the provided Configuration
instance based on the provided external configuration options.
# File 'rspec-core/lib/rspec/core/configuration_options.rb', line 21
def configure(config) config configure_filter_manager config.filter_manager load_formatters_into config end
#configure_filter_manager(filter_manager)
This method is for internal use only.
Updates the provided FilterManager
based on the filter options.
# File 'rspec-core/lib/rspec/core/configuration_options.rb', line 30
def configure_filter_manager(filter_manager) @filter_manager_options.each do |command, value| filter_manager.__send__ command, value end end
#custom_options (private)
[ GitHub ]# File 'rspec-core/lib/rspec/core/configuration_options.rb', line 146
def ( ) end
#custom_options_file (private)
:nocov:
# File 'rspec-core/lib/rspec/core/configuration_options.rb', line 190
def [: ] end
#env_options (private)
[ GitHub ]# File 'rspec-core/lib/rspec/core/configuration_options.rb', line 133
def return {} unless ENV['SPEC_OPTS'] parse_args_ignoring_files_or_dirs_to_run( Shellwords.split(ENV["SPEC_OPTS"]), "ENV['SPEC_OPTS']" ) end
#file_options (private)
[ GitHub ]# File 'rspec-core/lib/rspec/core/configuration_options.rb', line 125
def if [ ] else [, , ] end end
#force?(key) ⇒ Boolean
(private)
# File 'rspec-core/lib/rspec/core/configuration_options.rb', line 66
def force?(key) !UNFORCED_OPTIONS.include?(key) end
#global_options (private)
[ GitHub ]# File 'rspec-core/lib/rspec/core/configuration_options.rb', line 158
def @global_options ||= ( ) end
#global_options_file (private)
[ GitHub ]# File 'rspec-core/lib/rspec/core/configuration_options.rb', line 202
def || end
#home_options_file_path (private)
[ GitHub ]#load_formatters_into(config) (private)
[ GitHub ]# File 'rspec-core/lib/rspec/core/configuration_options.rb', line 121
def load_formatters_into(config) [:formatters].each { |pair| config.add_formatter(*pair) } if [:formatters] end
#local_options (private)
[ GitHub ]# File 'rspec-core/lib/rspec/core/configuration_options.rb', line 150
def @local_options ||= ( ) end
#local_options_file (private)
[ GitHub ]# File 'rspec-core/lib/rspec/core/configuration_options.rb', line 198
def "./.rspec-local" end
#options_file_as_erb_string(path) (private)
:nocov:
#options_from(path) (private)
[ GitHub ]# File 'rspec-core/lib/rspec/core/configuration_options.rb', line 162
def (path) args = (path) parse_args_ignoring_files_or_dirs_to_run(args, path) end
#order(keys) (private)
[ GitHub ]# File 'rspec-core/lib/rspec/core/configuration_options.rb', line 70
def order(keys) OPTIONS_ORDER.reverse_each do |key| keys.unshift(key) if keys.delete(key) end keys end
#organize_options (private)
[ GitHub ]# File 'rspec-core/lib/rspec/core/configuration_options.rb', line 44
def @filter_manager_options = [] @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
#parse_args_ignoring_files_or_dirs_to_run(args, source) (private)
[ GitHub ]#process_options_into(config) (private)
[ GitHub ]# File 'rspec-core/lib/rspec/core/configuration_options.rb', line 113
def (config) opts = .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
#project_options (private)
[ GitHub ]# File 'rspec-core/lib/rspec/core/configuration_options.rb', line 154
def @project_options ||= ( ) end
#project_options_file (private)
[ GitHub ]# File 'rspec-core/lib/rspec/core/configuration_options.rb', line 194
def "./.rspec" end
#resolve_xdg_config_home (private)
[ GitHub ]# File 'rspec-core/lib/rspec/core/configuration_options.rb', line 229
def resolve_xdg_config_home File. (ENV.fetch("XDG_CONFIG_HOME", "~/.config")) rescue ArgumentError # :nocov: # On Ruby 2.4, `File.expand("~")` works even if `ENV['HOME']` is not set. # But on earlier versions, it fails. nil # :nocov: end
#xdg_options_file_if_exists (private)
[ GitHub ]# File 'rspec-core/lib/rspec/core/configuration_options.rb', line 206
def path = if path && File.exist?(path) path end end
#xdg_options_file_path (private)
[ GitHub ]# File 'rspec-core/lib/rspec/core/configuration_options.rb', line 222
def xdg_config_home = resolve_xdg_config_home if xdg_config_home File.join(xdg_config_home, "rspec", "options") end end