class RSpec::Core::ConfigurationOptions

@private

Constants

MERGED_OPTIONS
NON_FORCED_OPTIONS
UNPROCESSABLE_OPTIONS

Attributes

options[R]

Public Class Methods

new(args) click to toggle source
# File lib/rspec/core/configuration_options.rb, line 10
def initialize(args)
  @args = args.dup
  if @args.include?("--default_path")
    @args[@args.index("--default_path")] = "--default-path"
  end

  if @args.include?("--line_number")
    @args[@args.index("--line_number")] = "--line-number"
  end
end

Public Instance Methods

configure(config) click to toggle source
# File lib/rspec/core/configuration_options.rb, line 21
def configure(config)
  config.filter_manager = filter_manager

  config.libs = options[:libs] || []
  config.setup_load_path_and_require(options[:requires] || [])

  process_options_into config
  load_formatters_into config
end
drb_argv() click to toggle source
# File lib/rspec/core/configuration_options.rb, line 39
def drb_argv
  DrbOptions.new(options, filter_manager).options
end
filter_manager() click to toggle source
# File lib/rspec/core/configuration_options.rb, line 43
def filter_manager
  @filter_manager ||= RSpec::configuration.filter_manager
end
parse_options() click to toggle source
# File lib/rspec/core/configuration_options.rb, line 31
def parse_options
  @options ||= extract_filters_from(*all_configs).inject do |merged, pending|
    merged.merge(pending) { |key, oldval, newval|
      MERGED_OPTIONS.include?(key) ? oldval + newval : newval
    }
  end
end

Private Instance Methods

all_configs() click to toggle source
# File lib/rspec/core/configuration_options.rb, line 88
def all_configs
  @all_configs ||= file_options << command_line_options << env_options
end
args_from_options_file(path) click to toggle source
# File lib/rspec/core/configuration_options.rb, line 124
def args_from_options_file(path)
  return [] unless path && File.exist?(path)
  config_string = options_file_as_erb_string(path)
  config_string.split(/\n+/).map {|l| Shellwords.shellwords(l) }.flatten
end
command_line_options() click to toggle source
# File lib/rspec/core/configuration_options.rb, line 100
def command_line_options
  @command_line_options ||= Parser.parse!(@args).merge :files_or_directories_to_run => @args
end
custom_options() click to toggle source
# File lib/rspec/core/configuration_options.rb, line 104
def custom_options
  options_from(custom_options_file)
end
custom_options_file() click to toggle source
# File lib/rspec/core/configuration_options.rb, line 134
def custom_options_file
  command_line_options[:custom_options_file]
end
env_options() click to toggle source
# File lib/rspec/core/configuration_options.rb, line 96
def env_options
  ENV["SPEC_OPTS"] ? Parser.parse!(Shellwords.split(ENV["SPEC_OPTS"])) : {}
end
extract_filters_from(*configs) click to toggle source
# File lib/rspec/core/configuration_options.rb, line 81
def extract_filters_from(*configs)
  configs.compact.each do |config|
    filter_manager.include config.delete(:inclusion_filter) if config.has_key?(:inclusion_filter)
    filter_manager.exclude config.delete(:exclusion_filter) if config.has_key?(:exclusion_filter)
  end
end
file_options() click to toggle source
# File lib/rspec/core/configuration_options.rb, line 92
def file_options
  custom_options_file ? [custom_options] : [global_options, project_options, local_options]
end
force?(key) click to toggle source
# File lib/rspec/core/configuration_options.rb, line 58
def force?(key)
  !NON_FORCED_OPTIONS.include?(key)
end
global_options() click to toggle source
# File lib/rspec/core/configuration_options.rb, line 116
def global_options
  @global_options ||= options_from(global_options_file)
end
global_options_file() click to toggle source
# File lib/rspec/core/configuration_options.rb, line 146
def global_options_file
  begin
    File.join(File.expand_path("~"), ".rspec")
  rescue ArgumentError
    warn "Unable to find ~/.rspec because the HOME environment variable is not set"
    nil
  end
end
load_formatters_into(config) click to toggle source
# File lib/rspec/core/configuration_options.rb, line 77
def load_formatters_into(config)
  options[:formatters].each { |pair| config.add_formatter(*pair) } if options[:formatters]
end
local_options() click to toggle source
# File lib/rspec/core/configuration_options.rb, line 108
def local_options
  @local_options ||= options_from(local_options_file)
end
local_options_file() click to toggle source
# File lib/rspec/core/configuration_options.rb, line 142
def local_options_file
  ".rspec-local"
end
options_file_as_erb_string(path) click to toggle source
# File lib/rspec/core/configuration_options.rb, line 130
def options_file_as_erb_string(path)
  ERB.new(File.read(path), nil, '-').result(binding)
end
options_from(path) click to toggle source
# File lib/rspec/core/configuration_options.rb, line 120
def options_from(path)
  Parser.parse(args_from_options_file(path))
end
order(keys, *ordered) click to toggle source
# File lib/rspec/core/configuration_options.rb, line 62
def order(keys, *ordered)
  ordered.reverse.each do |key|
    keys.unshift(key) if keys.delete(key)
  end
  keys
end
process_options_into(config) click to toggle source
# File lib/rspec/core/configuration_options.rb, line 69
def process_options_into(config)
  opts = options.reject { |k, _| UNPROCESSABLE_OPTIONS.include? k }

  order(opts.keys, :default_path, :pattern).each do |key|
    force?(key) ? config.force(key => opts[key]) : config.send("#{key}=", opts[key])
  end
end
project_options() click to toggle source
# File lib/rspec/core/configuration_options.rb, line 112
def project_options
  @project_options ||= options_from(project_options_file)
end
project_options_file() click to toggle source
# File lib/rspec/core/configuration_options.rb, line 138
def project_options_file
  ".rspec"
end