Rspec Steps C0 Coverage Information - RCov

rcov/ruby/1.8/gems/rspec-core-2.5.1/lib/rspec/core/formatters/base_formatter.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
rcov/ruby/1.8/gems/rspec-core-2.5.1/lib/rspec/core/formatters/base_formatter.rb 162 110
82.10%
76.36%

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 'rspec/core/formatters/helpers'
2 
3 module RSpec
4   module Core
5     module Formatters
6 
7       class BaseFormatter
8         include Helpers
9         attr_accessor :example_group
10         attr_reader :duration, :examples, :output
11         attr_reader :example_count, :pending_count, :failure_count
12         attr_reader :failed_examples, :pending_examples
13 
14         def initialize(output)
15           @output = output || StringIO.new
16           @example_count = @pending_count = @failure_count = 0
17           @examples = []
18           @failed_examples = []
19           @pending_examples = []
20           @example_group = nil
21         end
22 
23         # This method is invoked before any examples are run, right after
24         # they have all been collected. This can be useful for special
25         # formatters that need to provide progress on feedback (graphical ones)
26         #
27         # This will only be invoked once, and the next one to be invoked
28         # is #example_group_started
29         def start(example_count)
30           start_sync_output
31           @example_count = example_count
32         end
33 
34         # This method is invoked at the beginning of the execution of each example group.
35         # +example_group+ is the example_group.
36         #
37         # The next method to be invoked after this is +example_passed+,
38         # +example_pending+, or +example_finished+
39         def example_group_started(example_group)
40           @example_group = example_group
41         end
42 
43         # This method is invoked at the end of the execution of each example group.
44         # +example_group+ is the example_group.
45         def example_group_finished(example_group)
46         end
47 
48         def example_started(example)
49           examples << example
50         end
51 
52         def example_passed(example)
53         end
54 
55         def example_pending(example)
56           @pending_examples << example
57         end
58 
59         def example_failed(example)
60           @failed_examples << example
61         end
62 
63         def message(message)
64         end
65 
66         def stop
67         end
68 
69         # This method is invoked after all of the examples have executed. The next method
70         # to be invoked after this one is #dump_failure (once for each failed example),
71         def start_dump
72         end
73 
74         # Dumps detailed information about each example failure.
75         def dump_failures
76         end
77 
78         # This method is invoked after the dumping of examples and failures.
79         def dump_summary(duration, example_count, failure_count, pending_count)
80           @duration = duration
81           @example_count = example_count
82           @failure_count = failure_count
83           @pending_count = pending_count
84         end
85 
86         # This gets invoked after the summary if option is set to do so.
87         def dump_pending
88         end
89 
90         # This method is invoked at the very end. Allows the formatter to clean up, like closing open streams.
91         def close
92           restore_sync_output
93         end
94 
95         def format_backtrace(backtrace, example)
96           return "" unless backtrace
97           return backtrace if example.metadata[:full_backtrace] == true
98           cleansed = backtrace.map { |line| backtrace_line(line) }.compact
99           cleansed.empty? ? backtrace : cleansed
100         end
101 
102       protected
103 
104         def configuration
105           RSpec.configuration
106         end
107 
108         def backtrace_line(line)
109           return nil if configuration.cleaned_from_backtrace?(line)
110           line = line.sub(File.expand_path("."), ".")
111           line = line.sub(/\A([^:]+:\d+)$/, '\\1')
112           return nil if line == '-e:1'
113           line
114         end
115 
116         def read_failed_line(exception, example)
117           unless matching_line = find_failed_line(exception.backtrace, example.file_path)
118             return "Unable to find matching line from backtrace"
119           end
120 
121           file_path, line_number = matching_line.match(/(.+?):(\d+)(|:\d+)/)[1..2]
122 
123           if File.exist?(file_path)
124             File.readlines(file_path)[line_number.to_i - 1]
125           else
126             "Unable to find #{file_path} to read failed line"
127           end
128         end
129 
130         def find_failed_line(backtrace, path)
131           backtrace.detect { |line|
132             match = line.match(/(.+?):(\d+)(|:\d+)/)
133             match && match[1].downcase == path.downcase
134           }
135 
136         end
137 
138         def start_sync_output
139           @old_sync, output.sync = output.sync, true if output_supports_sync
140         end
141 
142         def restore_sync_output
143           output.sync = @old_sync if output_supports_sync and !output.closed?
144         end
145 
146         def output_supports_sync
147           output.respond_to?(:sync=)
148         end
149 
150         def profile_examples?
151           configuration.profile_examples
152         end
153 
154         def color_enabled?
155           configuration.color_enabled?
156         end
157 
158       end
159 
160     end
161   end
162 end

Generated on Fri Apr 22 17:22:42 -0700 2011 with rcov 0.9.8