Class: RSpec::Core::ConfigurationOptions

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ ConfigurationOptions

Returns a new instance of ConfigurationOptions.



7
8
9
# File 'lib/rspec/core/configuration_options.rb', line 7

def initialize(args)
  @args = args
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/rspec/core/configuration_options.rb', line 5

def options
  @options
end

Instance Method Details

#configure(config) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rspec/core/configuration_options.rb', line 11

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)

  config.exclusion_filter.merge! options[:exclusion_filter] if keys.delete(:exclusion_filter)

  keys.each do |key|
    config.send("#{key}=", options[key]) if config.respond_to?("#{key}=")
  end

  formatters.each {|pair| config.add_formatter(*pair) } if formatters
end

#drb_argvObject



27
28
29
30
31
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
58
59
60
61
62
63
64
65
66
# File 'lib/rspec/core/configuration_options.rb', line 27

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]
  if options[:full_description]
    # The argument to --example is regexp-escaped before being stuffed
    # into a regexp when received for the first time (see OptionParser).
    # Hence, merely grabbing the source of this regexp will retain the
    # backslashes, so we must remove them.
    argv << "--example" << options[:full_description].source.delete('\\')
  end
  if options[:filter]
    options[:filter].each_pair do |k, v|
      argv << "--tag" << k.to_s
    end
  end
  if options[:exclusion_filter]
    options[:exclusion_filter].each_pair do |k, v|
      argv << "--tag" << "~#{k.to_s}"
    end
  end
  if options[:formatters]
    options[:formatters].each do |pair|
      argv << "--format" << pair[0]
      argv << "--out" << pair[1] if pair[1]
    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



68
69
70
# File 'lib/rspec/core/configuration_options.rb', line 68

def parse_options
  @options ||= [file_options, command_line_options, env_options].inject {|merged, o| merged.merge o}
end