C0 code coverage information
Generated on Mon Aug 13 01:18:53 -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 DSL
3 class ExampleShouldRaiseHandler
4 def initialize(file_and_line_number, opts)
5 @file_and_line_number = file_and_line_number
6 @options = opts
7 @expected_error_class = determine_error_class(opts)
8 @expected_error_message = determine_error_message(opts)
9 end
10
11 def determine_error_class(opts)
12 if candidate = opts[:should_raise]
13 if candidate.is_a?(Class)
14 return candidate
15 elsif candidate.is_a?(Array)
16 return candidate[0]
17 else
18 return Exception
19 end
20 end
21 end
22
23 def determine_error_message(opts)
24 if candidate = opts[:should_raise]
25 if candidate.is_a?(Array)
26 return candidate[1]
27 end
28 end
29 return nil
30 end
31
32 def build_message(exception=nil)
33 if @expected_error_message.nil?
34 message = "example block expected #{@expected_error_class.to_s}"
35 else
36 message = "example block expected #{@expected_error_class.new(@expected_error_message.to_s).inspect}"
37 end
38 message << " but raised #{exception.inspect}" if exception
39 message << " but nothing was raised" unless exception
40 message << "\n"
41 message << @file_and_line_number
42 end
43
44 def error_matches?(error)
45 return false unless error.kind_of?(@expected_error_class)
46 unless @expected_error_message.nil?
47 if @expected_error_message.is_a?(Regexp)
48 return false unless error.message =~ @expected_error_message
49 else
50 return false unless error.message == @expected_error_message
51 end
52 end
53 return true
54 end
55
56 def handle(errors)
57 if @expected_error_class
58 if errors.empty?
59 errors << Spec::Expectations::ExpectationNotMetError.new(build_message)
60 else
61 error_to_remove = errors.detect do |error|
62 error_matches?(error)
63 end
64 if error_to_remove.nil?
65 errors.insert(0,Spec::Expectations::ExpectationNotMetError.new(build_message(errors[0])))
66 else
67 errors.delete(error_to_remove)
68 end
69 end
70 end
71 end
72 end
73 end
74 end
Generated using the rcov code coverage analysis tool for Ruby version 0.8.0.