Name | Total Lines | Lines of Code | Total Coverage | Code Coverage |
---|---|---|---|---|
rcov/ruby/1.8/gems/rspec-core-2.5.1/lib/rspec/core/configuration_options.rb | 126 | 107 | 74.60%
|
70.09%
|
Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.
1 # http://www.ruby-doc.org/stdlib/libdoc/optparse/rdoc/classes/OptionParser.html |
2 require 'optparse' |
3 |
4 module RSpec |
5 module Core |
6 |
7 class ConfigurationOptions |
8 LOCAL_OPTIONS_FILE = ".rspec" |
9 GLOBAL_OPTIONS_FILE = File.join(File.expand_path("~"), ".rspec") |
10 |
11 attr_reader :options |
12 |
13 def initialize(args) |
14 @args = args |
15 end |
16 |
17 def configure(config) |
18 keys = options.keys |
19 keys.unshift(:requires) if keys.delete(:requires) |
20 keys.unshift(:libs) if keys.delete(:libs) |
21 formatters = options[:formatters] if keys.delete(:formatters) |
22 keys.each do |key| |
23 config.send("#{key}=", options[key]) if config.respond_to?("#{key}=") |
24 end |
25 if formatters |
26 formatters.each do |pair| |
27 config.add_formatter(*pair) |
28 end |
29 end |
30 end |
31 |
32 def drb_argv |
33 argv = [] |
34 argv << "--color" if options[:color_enabled] |
35 argv << "--profile" if options[:profile_examples] |
36 argv << "--backtrace" if options[:full_backtrace] |
37 argv << "--tty" if options[:tty] |
38 argv << "--fail-fast" if options[:fail_fast] |
39 argv << "--line_number" << options[:line_number] if options[:line_number] |
40 argv << "--options" << options[:custom_options_file] if options[:custom_options_file] |
41 argv << "--example" << options[:full_description].source if options[:full_description] |
42 if options[:filter] |
43 options[:filter].each_pair do |k, v| |
44 argv << "--tag" << k.to_s |
45 end |
46 end |
47 if options[:formatters] |
48 options[:formatters].each do |pair| |
49 argv << "--format" << pair[0] |
50 argv << "--out" << pair[1] if pair[1] |
51 end |
52 end |
53 (options[:libs] || []).each do |path| |
54 argv << "-I" << path |
55 end |
56 (options[:requires] || []).each do |path| |
57 argv << "--require" << path |
58 end |
59 argv + options[:files_or_directories_to_run] |
60 end |
61 |
62 def parse_options |
63 @options = begin |
64 options_to_merge = [] |
65 if custom_options_file |
66 options_to_merge << custom_options |
67 else |
68 options_to_merge << global_options |
69 options_to_merge << local_options |
70 end |
71 options_to_merge << command_line_options |
72 options_to_merge << env_options |
73 |
74 options_to_merge.inject do |merged, options| |
75 merged.merge(options) |
76 end |
77 end |
78 end |
79 |
80 private |
81 |
82 def env_options |
83 ENV["SPEC_OPTS"] ? Parser.parse!(ENV["SPEC_OPTS"].split) : {} |
84 end |
85 |
86 def command_line_options |
87 @command_line_options ||= begin |
88 options = Parser.parse!(@args) |
89 options[:files_or_directories_to_run] = @args |
90 options |
91 end |
92 end |
93 |
94 def custom_options |
95 options_from(custom_options_file) |
96 end |
97 |
98 def local_options |
99 @local_options ||= options_from(LOCAL_OPTIONS_FILE) |
100 end |
101 |
102 def global_options |
103 @global_options ||= options_from(GLOBAL_OPTIONS_FILE) |
104 end |
105 |
106 def options_from(path) |
107 Parser.parse(args_from_options_file(path)) |
108 end |
109 |
110 def args_from_options_file(path) |
111 return [] unless File.exist?(path) |
112 config_string = options_file_as_erb_string(path) |
113 config_string.split(/\n+/).map {|l| l.split}.flatten |
114 end |
115 |
116 def options_file_as_erb_string(path) |
117 require 'erb' |
118 ERB.new(IO.read(path)).result(binding) |
119 end |
120 |
121 def custom_options_file |
122 command_line_options[:custom_options_file] |
123 end |
124 end |
125 end |
126 end |
Generated on Fri Apr 22 17:22:42 -0700 2011 with rcov 0.9.8