C0 code coverage information
Generated on Mon Aug 13 01:18:55 -0400 2007 with rcov 0.8.0
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 module Spec
2 module Runner
3 class Options
4 BUILT_IN_FORMATTERS = {
5 'specdoc' => Formatter::SpecdocFormatter,
6 's' => Formatter::SpecdocFormatter,
7 'html' => Formatter::HtmlFormatter,
8 'h' => Formatter::HtmlFormatter,
9 'rdoc' => Formatter::RdocFormatter,
10 'r' => Formatter::RdocFormatter,
11 'progress' => Formatter::ProgressBarFormatter,
12 'p' => Formatter::ProgressBarFormatter,
13 'failing_examples' => Formatter::FailingExamplesFormatter,
14 'e' => Formatter::FailingExamplesFormatter,
15 'failing_behaviours' => Formatter::FailingBehavioursFormatter,
16 'b' => Formatter::FailingBehavioursFormatter
17 }
18
19 attr_accessor(
20 :backtrace_tweaker,
21 :colour,
22 :context_lines,
23 :diff_format,
24 :differ_class,
25 :dry_run,
26 :examples,
27 :failure_file,
28 :formatters,
29 :generate,
30 :heckle_runner,
31 :line_number,
32 :loadby,
33 :reporter,
34 :reverse,
35 :timeout,
36 :verbose,
37 :runner_arg,
38 :behaviour_runner
39 )
40
41 def initialize(err, out)
42 @err, @out = err, out
43 @backtrace_tweaker = QuietBacktraceTweaker.new
44 @examples = []
45 @formatters = []
46 @colour = false
47 @dry_run = false
48 end
49
50 def configure
51 configure_formatters
52 create_reporter
53 configure_differ
54 create_behaviour_runner
55 end
56
57 def create_behaviour_runner
58 return nil if @generate
59 @behaviour_runner = if @runner_arg
60 klass_name, arg = split_at_colon(@runner_arg)
61 runner_type = load_class(klass_name, 'behaviour runner', '--runner')
62 runner_type.new(self, arg)
63 else
64 BehaviourRunner.new(self)
65 end
66 end
67
68 def configure_formatters
69 @formatters.each do |formatter|
70 formatter.colour = @colour if formatter.respond_to?(:colour=)
71 formatter.dry_run = @dry_run if formatter.respond_to?(:dry_run=)
72 end
73 end
74
75 def create_reporter
76 @reporter = Reporter.new(@formatters, @backtrace_tweaker)
77 end
78
79 def configure_differ
80 if @differ_class
81 Spec::Expectations.differ = @differ_class.new(@diff_format, @context_lines, @colour)
82 end
83 end
84
85 def parse_diff(format)
86 @context_lines = 3
87 case format
88 when :context, 'context', 'c'
89 @diff_format = :context
90 when :unified, 'unified', 'u', '', nil
91 @diff_format = :unified
92 end
93
94 if [:context,:unified].include? @diff_format
95 require 'spec/expectations/differs/default'
96 @differ_class = Spec::Expectations::Differs::Default
97 else
98 @diff_format = :custom
99 @differ_class = load_class(format, 'differ', '--diff')
100 end
101 end
102
103 def parse_example(example)
104 if(File.file?(example))
105 @examples = File.open(example).read.split("\n")
106 else
107 @examples = [example]
108 end
109 end
110
111 def parse_format(format_arg)
112 format, where = split_at_colon(format_arg)
113 # This funky regexp checks whether we have a FILE_NAME or not
114 if where.nil?
115 raise "When using several --format options only one of them can be without a file" if @out_used
116 where = @out
117 @out_used = true
118 end
119
120 formatter_type = BUILT_IN_FORMATTERS[format] || load_class(format, 'formatter', '--format')
121 @formatters << formatter_type.new(where)
122 end
123
124 def parse_require(req)
125 req.split(",").each{|file| require file}
126 end
127
128 def parse_heckle(heckle)
129 heckle_require = [/mswin/, /java/].detect{|p| p =~ RUBY_PLATFORM} ? 'spec/runner/heckle_runner_unsupported' : 'spec/runner/heckle_runner'
130 require heckle_require
131 @heckle_runner = HeckleRunner.new(heckle)
132 end
133
134 def parse_generate_options(options_file, args_copy, out_stream)
135 # Remove the --generate-options option and the argument before writing to file
136 index = args_copy.index("-G") || args_copy.index("--generate-options")
137 args_copy.delete_at(index)
138 args_copy.delete_at(index)
139 File.open(options_file, 'w') do |io|
140 io.puts args_copy.join("\n")
141 end
142 out_stream.puts "\nOptions written to #{options_file}. You can now use these options with:"
143 out_stream.puts "spec --options #{options_file}"
144 @generate = true
145 end
146
147 def split_at_colon(s)
148 if s =~ /([a-zA-Z_]+(?:::[a-zA-Z_]+)*):?(.*)/
149 arg = $2 == "" ? nil : $2
150 [$1, arg]
151 else
152 raise "Couldn't parse #{s.inspect}"
153 end
154 end
155
156 def load_class(name, kind, option)
157 if name =~ /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/
158 arg = $2 == "" ? nil : $2
159 [$1, arg]
160 else
161 m = "#{name.inspect} is not a valid class name"
162 @err.puts m
163 raise m
164 end
165 begin
166 eval(name, binding, __FILE__, __LINE__)
167 rescue NameError => e
168 @err.puts "Couldn't find #{kind} class #{name}"
169 @err.puts "Make sure the --require option is specified *before* #{option}"
170 if $_spec_spec ; raise e ; else exit(1) ; end
171 end
172 end
173 end
174 end
175 end
Generated using the rcov code coverage analysis tool for Ruby version 0.8.0.