Geminstaller C0 Coverage Information - RCov

/Users/woolley/.rvm/gems/ruby-1.8.7-p174@geminstaller/gems/rspec-1.3.0/lib/spec/matchers/raise_exception.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/matchers/raise_exception.rb 131 83
73.28%
60.24%

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 module Spec
2   module Matchers
3     class RaiseException #:nodoc:
4       def initialize(expected_exception_or_message=Exception, expected_message=nil, &block)
5         @block = block
6         @actual_exception = nil
7         case expected_exception_or_message
8         when String, Regexp
9           @expected_exception, @expected_message = Exception, expected_exception_or_message
10         else
11           @expected_exception, @expected_message = expected_exception_or_message, expected_message
12         end
13       end
14 
15       def matches?(given_proc)
16         @raised_expected_exception = false
17         @with_expected_message = false
18         @eval_block = false
19         @eval_block_passed = false
20         begin
21           given_proc.call
22         rescue @expected_exception => @actual_exception
23           @raised_expected_exception = true
24           @with_expected_message = verify_message
25         rescue Exception => @actual_exception
26           # This clause should be empty, but rcov will not report it as covered
27           # unless something (anything) is executed within the clause
28           rcov_exception_report = "http://eigenclass.org/hiki.rb?rcov-0.8.0"
29         end
30 
31         unless negative_expectation?
32           eval_block if @raised_expected_exception && @with_expected_message && @block
33         end
34 
35         (@raised_expected_exception & @with_expected_message) ? (@eval_block ? @eval_block_passed : true) : false
36       end
37 
38       def eval_block
39         @eval_block = true
40         begin
41           @block[@actual_exception]
42           @eval_block_passed = true
43         rescue Exception => err
44           @actual_exception = err
45         end
46       end
47 
48       def verify_message
49         case @expected_message
50         when nil
51           true
52         when Regexp
53           @expected_message =~ @actual_exception.message
54         else
55           @expected_message == @actual_exception.message
56         end
57       end
58 
59       def failure_message_for_should
60         @eval_block ? @actual_exception.message : "expected #{expected_exception}#{given_exception}"
61       end
62 
63       def failure_message_for_should_not
64         "expected no #{expected_exception}#{given_exception}"
65       end
66 
67       def description
68         "raise #{expected_exception}"
69       end
70 
71       private
72         def expected_exception
73           case @expected_message
74           when nil
75             @expected_exception
76           when Regexp
77             "#{@expected_exception} with message matching #{@expected_message.inspect}"
78           else
79             "#{@expected_exception} with #{@expected_message.inspect}"
80           end
81         end
82 
83         def given_exception
84           @actual_exception.nil? ? " but nothing was raised" : ", got #{@actual_exception.inspect}"
85         end
86 
87         def negative_expectation?
88           # YES - I'm a bad person... help me find a better way - ryand
89           caller.first(3).find { |s| s =~ /should_not/ }
90         end
91     end
92 
93     # :call-seq:
94     #   should raise_exception()
95     #   should raise_exception(NamedError)
96     #   should raise_exception(NamedError, String)
97     #   should raise_exception(NamedError, Regexp)
98     #   should raise_exception() { |exception| ... }
99     #   should raise_exception(NamedError) { |exception| ... }
100     #   should raise_exception(NamedError, String) { |exception| ... }
101     #   should raise_exception(NamedError, Regexp) { |exception| ... }
102     #   should_not raise_exception()
103     #   should_not raise_exception(NamedError)
104     #   should_not raise_exception(NamedError, String)
105     #   should_not raise_exception(NamedError, Regexp)
106     #
107     # With no args, matches if any exception is raised.
108     # With a named exception, matches only if that specific exception is raised.
109     # With a named exception and messsage specified as a String, matches only if both match.
110     # With a named exception and messsage specified as a Regexp, matches only if both match.
111     # Pass an optional block to perform extra verifications on the exception matched
112     #
113     # == Examples
114     #
115     #   lambda { do_something_risky }.should raise_exception
116     #   lambda { do_something_risky }.should raise_exception(PoorRiskDecisionError)
117     #   lambda { do_something_risky }.should raise_exception(PoorRiskDecisionError) { |exception| exception.data.should == 42 }
118     #   lambda { do_something_risky }.should raise_exception(PoorRiskDecisionError, "that was too risky")
119     #   lambda { do_something_risky }.should raise_exception(PoorRiskDecisionError, /oo ri/)
120     #
121     #   lambda { do_something_risky }.should_not raise_exception
122     #   lambda { do_something_risky }.should_not raise_exception(PoorRiskDecisionError)
123     #   lambda { do_something_risky }.should_not raise_exception(PoorRiskDecisionError, "that was too risky")
124     #   lambda { do_something_risky }.should_not raise_exception(PoorRiskDecisionError, /oo ri/)
125     def raise_exception(exception=Exception, message=nil, &block)
126       Matchers::RaiseException.new(exception, message, &block)
127     end
128 
129     alias_method :raise_error, :raise_exception
130   end
131 end

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