Geminstaller C0 Coverage Information - RCov

/Users/woolley/.rvm/gems/ruby-1.8.7-p174@geminstaller/gems/rspec-1.3.0/lib/spec/runner/option_parser.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
/Users/woolley/.rvm/gems/ruby-1.8.7-p174@geminstaller/gems/rspec-1.3.0/lib/spec/runner/option_parser.rb 225 199
79.11%
76.38%

Key

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.

Coverage Details

1 require 'optparse'
2 require 'stringio'
3 
4 module Spec
5   module Runner
6     class OptionParser < ::OptionParser
7       class << self
8         def parse(args, err, out)
9           parser = new(err, out)
10           parser.parse(args)
11           parser.options
12         end
13 
14         def spec_command?
15           $0.split('/').last == 'spec'
16         end
17       end
18 
19       attr_reader :options
20 
21       OPTIONS = {
22         :pattern => ["-p", "--pattern [PATTERN]","Limit files loaded to those matching this pattern. Defaults to '**/*_spec.rb'",
23                                                  "Separate multiple patterns with commas.",
24                                                  "Applies only to directories named on the command line (files",
25                                                  "named explicitly on the command line will be loaded regardless)."],
26         :diff =>    ["-D", "--diff [FORMAT]","Show diff of objects that are expected to be equal when they are not",
27                                              "Builtin formats: unified|u|context|c",
28                                              "You can also specify a custom differ class",
29                                              "(in which case you should also specify --require)"],
30         :colour =>  ["-c", "--colour", "--color", "Show coloured (red/green) output"],
31         :example => ["-e", "--example [NAME|FILE_NAME]",  "Execute example(s) with matching name(s). If the argument is",
32                                                           "the path to an existing file (typically generated by a previous",
33                                                           "run using --format failing_examples:file.txt), then the examples",
34                                                           "on each line of that file will be executed. If the file is empty,",
35                                                           "all examples will be run (as if --example was not specified).",
36                                                           " ",
37                                                           "If the argument is not an existing file, then it is treated as",
38                                                           "an example name directly, causing RSpec to run just the example",
39                                                           "matching that name"],
40         :specification => ["-s", "--specification [NAME]", "DEPRECATED - use -e instead", "(This will be removed when autotest works with -e)"],
41         :line => ["-l", "--line LINE_NUMBER", Integer, "Execute example group or example at given line.",
42                                                        "(does not work for dynamically generated examples)"],
43         :format => ["-f", "--format FORMAT[:WHERE]","Specifies what format to use for output. Specify WHERE to tell",
44                                                     "the formatter where to write the output. All built-in formats",
45                                                     "expect WHERE to be a file name, and will write to $stdout if it's",
46                                                     "not specified. The --format option may be specified several times",
47                                                     "if you want several outputs",
48                                                     " ",
49                                                     "Builtin formats:",
50                                                     "silent|l                 : No output",                                                    "progress|p               : Text-based progress bar",
51                                                     "profile|o                : Text-based progress bar with profiling of 10 slowest examples",
52                                                     "specdoc|s                : Code example doc strings",
53                                                     "nested|n                 : Code example doc strings with nested groups indented",
54                                                     "html|h                   : A nice HTML report",
55                                                     "failing_examples|e       : Write all failing examples - input for --example",
56                                                     "failing_example_groups|g : Write all failing example groups - input for --example",
57                                                     " ",
58                                                     "FORMAT can also be the name of a custom formatter class",
59                                                     "(in which case you should also specify --require to load it)"],
60         :require => ["-r", "--require FILE", "Require FILE before running specs",
61                                              "Useful for loading custom formatters or other extensions.",
62                                              "If this option is used it must come before the others"],
63         :backtrace => ["-b", "--backtrace", "Output full backtrace"],
64         :loadby => ["-L", "--loadby STRATEGY", "Specify the strategy by which spec files should be loaded.",
65                                                "STRATEGY can currently only be 'mtime' (File modification time)",
66                                                "By default, spec files are loaded in alphabetical order if --loadby",
67                                                "is not specified."],
68         :reverse => ["-R", "--reverse", "Run examples in reverse order"],
69         :timeout => ["-t", "--timeout FLOAT", "Interrupt and fail each example that doesn't complete in the",
70                                               "specified time"],
71         :heckle => ["-H", "--heckle CODE", "If all examples pass, this will mutate the classes and methods",
72                                            "identified by CODE little by little and run all the examples again",
73                                            "for each mutation. The intent is that for each mutation, at least",
74                                            "one example *should* fail, and RSpec will tell you if this is not the",
75                                            "case. CODE should be either Some::Module, Some::Class or",
76                                            "Some::Fabulous#method}"],
77         :dry_run => ["-d", "--dry-run", "Invokes formatters without executing the examples."],
78         :options_file => ["-O", "--options PATH", "Read options from a file"],
79         :generate_options => ["-G", "--generate-options PATH", "Generate an options file for --options"],
80         :runner => ["-U", "--runner RUNNER", "Use a custom Runner."],
81         :debug => ["-u", "--debugger", "Enable ruby-debugging."],
82         :drb => ["-X", "--drb", "Run examples via DRb. (For example against script/spec_server)"],
83         :drb_port => ["--port PORT", "Port for DRb server. (Ignored without --drb)"],
84         :version => ["-v", "--version", "Show version"],
85         :help => ["-h", "--help", "You're looking at it"]
86       }
87 
88       def initialize(err, out)
89         super()
90         @error_stream = err
91         @out_stream = out
92         @options = Options.new(@error_stream, @out_stream)
93 
94         @file_factory = File
95 
96         self.banner = "Usage: spec (FILE(:LINE)?|DIRECTORY|GLOB)+ [options]"
97         self.separator ""
98         on(*OPTIONS[:pattern])          {|pattern| @options.filename_pattern = pattern}
99         on(*OPTIONS[:diff])             {|diff| @options.parse_diff(diff)}
100         on(*OPTIONS[:colour])           {@options.colour = true}
101         on(*OPTIONS[:example])          {|example| @options.parse_example(example)}
102         on(*OPTIONS[:specification])    {|example| @options.parse_example(example)}
103         on(*OPTIONS[:line])             {|line_number| @options.line_number = line_number.to_i}
104         on(*OPTIONS[:format])           {|format| @options.parse_format(format)}
105         on(*OPTIONS[:require])          {|requires| invoke_requires(requires)}
106         on(*OPTIONS[:backtrace])        {@options.backtrace_tweaker = NoisyBacktraceTweaker.new}
107         on(*OPTIONS[:loadby])           {|loadby| @options.loadby = loadby}
108         on(*OPTIONS[:reverse])          {@options.reverse = true}
109         on(*OPTIONS[:timeout])          {|timeout| @options.timeout = timeout.to_f}
110         on(*OPTIONS[:heckle])           {|heckle| @options.load_heckle_runner(heckle)}
111         on(*OPTIONS[:dry_run])          {@options.dry_run = true}
112         on(*OPTIONS[:options_file])     {|options_file|}
113         on(*OPTIONS[:generate_options]) {|options_file|}
114         on(*OPTIONS[:runner])           {|runner|  @options.user_input_for_runner = runner}
115         on(*OPTIONS[:debug])            {@options.debug = true}
116         on(*OPTIONS[:drb])              {}
117         on(*OPTIONS[:drb_port])         {|port| @options.drb_port = port}
118         on(*OPTIONS[:version])          {parse_version}
119         on("--autospec")                {@options.autospec = true}
120         on_tail(*OPTIONS[:help])        {parse_help}
121       end
122 
123       def order!(argv, &blk)
124         @argv = argv.dup
125         @argv = (@argv.empty? & self.class.spec_command?) ? ['--help'] : @argv
126 
127         # Parse options file first
128         parse_file_options(:options_file, :parse_options_file)
129 
130         @options.argv = @argv.dup
131         return if parse_file_options(:generate_options, :write_options_file)
132         return if parse_drb
133 
134         super(@argv) do |file|
135           if file =~ /^(.+):(\d+)$/
136             file = $1
137             @options.line_number = $2.to_i
138           end
139 
140           @options.files << file
141           blk.call(file) if blk
142         end
143 
144         @options
145       end
146 
147     protected
148 
149       def invoke_requires(requires)
150         requires.split(",").each do |file|
151           require file
152         end
153       end
154 
155       def parse_file_options(option_name, action)
156         # Remove the file option and the argument before handling the file
157         options_file = nil
158         options_list = OPTIONS[option_name][0..1]
159         options_list[1].gsub!(" PATH", "")
160         options_list.each do |option|
161           if index = @argv.index(option)
162             @argv.delete_at(index)
163             options_file = @argv.delete_at(index)
164           end
165         end
166         
167         if options_file.nil? &&
168            File.exist?('spec/spec.opts') &&
169            !@argv.any?{|a| a =~ /^\-/ }
170              options_file = 'spec/spec.opts'
171         end
172 
173         if options_file
174           send(action, options_file)
175           return true
176         else
177           return false
178         end
179       end
180 
181       def parse_options_file(options_file)
182         option_file_args = File.readlines(options_file).map {|l| l.chomp.split " "}.flatten
183         @argv.push(*option_file_args)
184       end
185 
186       def write_options_file(options_file)
187         File.open(options_file, 'w') do |io|
188           io.puts @argv.join("\n")
189         end
190         @out_stream.puts "\nOptions written to #{options_file}. You can now use these options with:"
191         @out_stream.puts "spec --options #{options_file}"
192         @options.examples_should_not_be_run
193       end
194 
195       def parse_drb
196         argv = @options.argv
197         is_drb = false
198         is_drb ||= argv.delete(OPTIONS[:drb][0])
199         is_drb ||= argv.delete(OPTIONS[:drb][1])
200         return false unless is_drb
201         if DrbCommandLine.run(self.class.parse(argv, @error_stream, @out_stream))
202           @options.examples_should_not_be_run
203           true
204         else
205           @error_stream.puts "Running specs locally:"
206           false
207         end
208       end
209 
210       def parse_version
211         @out_stream.puts ::Spec::VERSION::SUMMARY
212         exit if stdout?
213       end
214 
215       def parse_help
216         @out_stream.puts self
217         exit if stdout?
218       end
219 
220       def stdout?
221         @out_stream == $stdout
222       end
223     end
224   end
225 end

Generated on Mon May 10 23:40:28 -0700 2010 with rcov 0.9.8