Class: RSpec::Core::ConfigurationOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/core/configuration_options.rb

Constant Summary collapse

LOCAL_OPTIONS_FILE =
".rspec"
GLOBAL_OPTIONS_FILE =
File.join(File.expand_path("~"), ".rspec")

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ ConfigurationOptions

Returns a new instance of ConfigurationOptions.



13
14
15
# File 'lib/rspec/core/configuration_options.rb', line 13

def initialize(args)
  @args = args
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



11
12
13
# File 'lib/rspec/core/configuration_options.rb', line 11

def options
  @options
end

Instance Method Details

#configure(config) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rspec/core/configuration_options.rb', line 17

def configure(config)
  keys = options.keys
  keys.unshift(:requires) if keys.delete(:requires)
  keys.unshift(:libs)     if keys.delete(:libs)
  formatters = options[:formatters] if keys.delete(:formatters)
  keys.each do |key|
    config.send("#{key}=", options[key]) if config.respond_to?("#{key}=")
  end
  if formatters
    formatters.each do |pair|
      config.add_formatter(*pair)
    end
  end
end

#drb_argvObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rspec/core/configuration_options.rb', line 32

def drb_argv
  argv = []
  argv << "--color"     if options[:color_enabled]
  argv << "--profile"   if options[:profile_examples]
  argv << "--backtrace" if options[:full_backtrace]
  argv << "--tty"       if options[:tty]
  argv << "--fail-fast"  if options[:fail_fast]
  argv << "--line_number"  << options[:line_number]             if options[:line_number]
  argv << "--options"      << options[:custom_options_file]            if options[:custom_options_file]
  argv << "--example"      << options[:full_description].source if options[:full_description]
  if options[:formatters]
    options[:formatters].each do |pair|
      argv << "--format" << pair.shift
      unless pair.empty?
        argv << "--out" << pair.shift
      end
    end
  end
  (options[:libs] || []).each do |path|
    argv << "-I" << path
  end
  (options[:requires] || []).each do |path|
    argv << "--require" << path
  end
  argv + options[:files_or_directories_to_run]
end

#parse_optionsObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/rspec/core/configuration_options.rb', line 59

def parse_options
  @options = begin
               options_to_merge = []
               if custom_options_file
                 options_to_merge << custom_options
               else
                 options_to_merge << global_options
                 options_to_merge << local_options
               end
               options_to_merge << env_options
               options_to_merge << command_line_options

               options_to_merge.inject do |merged, options|
                 merged.merge(options)
               end
             end
end