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 module Formatter
4 # Baseclass for text-based formatters. Can in fact be used for
5 # non-text based ones too - just ignore the +output+ constructor
6 # argument.
7 class BaseTextFormatter < BaseFormatter
8 attr_writer :dry_run
9
10 # Creates a new instance that will write to +where+. If +where+ is a
11 # String, output will be written to the File with that name, otherwise
12 # +where+ is exected to be an IO (or an object that responds to #puts and #write).
13 def initialize(where)
14 super(where)
15 if where.is_a?(String)
16 @output = File.open(where, 'w')
17 elsif where == STDOUT
18 @output = Kernel
19 def @output.flush
20 STDOUT.flush
21 end
22 else
23 @output = where
24 end
25 @colour = false
26 @dry_run = false
27 @snippet_extractor = SnippetExtractor.new
28 @pending_examples = []
29 end
30
31 def example_pending(behaviour_name, example_name, message)
32 @pending_examples << ["#{behaviour_name} #{example_name}", message]
33 end
34
35 def colour=(colour)
36 @colour = colour
37 begin ; require 'Win32/Console/ANSI' if @colour && PLATFORM =~ /win32/ ; rescue LoadError ; raise "You must gem install win32console to use colour on Windows" ; end
38 end
39
40 def dump_failure(counter, failure)
41 @output.puts
42 @output.puts "#{counter.to_s})"
43 @output.puts colourise("#{failure.header}\n#{failure.exception.message}", failure)
44 @output.puts format_backtrace(failure.exception.backtrace)
45 @output.flush
46 end
47
48 def colourise(s, failure)
49 if(failure.expectation_not_met?)
50 red(s)
51 elsif(failure.pending_fixed?)
52 blue(s)
53 else
54 magenta(s)
55 end
56 end
57
58 def dump_summary(duration, example_count, failure_count, pending_count)
59 return if @dry_run
60 @output.puts
61 @output.puts "Finished in #{duration} seconds"
62 @output.puts
63
64 summary = "#{example_count} example#{'s' unless example_count == 1}, #{failure_count} failure#{'s' unless failure_count == 1}"
65 summary << ", #{pending_count} pending" if pending_count > 0
66
67 if failure_count == 0
68 if pending_count > 0
69 @output.puts yellow(summary)
70 else
71 @output.puts green(summary)
72 end
73 else
74 @output.puts red(summary)
75 end
76 @output.flush
77 dump_pending
78 end
79
80 def dump_pending
81 unless @pending_examples.empty?
82 @output.puts
83 @output.puts "Pending:"
84 @pending_examples.each do |pending_example|
85 @output.puts "#{pending_example[0]} (#{pending_example[1]})"
86 end
87 end
88 @output.flush
89 end
90
91 def close
92 if IO === @output
93 @output.close
94 end
95 end
96
97 def format_backtrace(backtrace)
98 return "" if backtrace.nil?
99 backtrace.map { |line| backtrace_line(line) }.join("\n")
100 end
101
102 protected
103
104 def backtrace_line(line)
105 line.sub(/\A([^:]+:\d+)$/, '\\1:')
106 end
107
108 def colour(text, colour_code)
109 return text unless @colour && output_to_tty?
110 "#{colour_code}#{text}\e[0m"
111 end
112
113 def output_to_tty?
114 begin
115 @output == Kernel || @output.tty?
116 rescue NoMethodError
117 false
118 end
119 end
120
121 def green(text); colour(text, "\e[32m"); end
122 def red(text); colour(text, "\e[31m"); end
123 def magenta(text); colour(text, "\e[35m"); end
124 def yellow(text); colour(text, "\e[33m"); end
125 def blue(text); colour(text, "\e[34m"); end
126
127 end
128 end
129 end
130 end
Generated using the rcov code coverage analysis tool for Ruby version 0.8.0.