C0 code coverage information
Generated on Mon Aug 13 01:18:54 -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 Matchers
3
4 class ThrowSymbol #:nodoc:
5 def initialize(expected=nil)
6 @expected = expected
7 end
8
9 def matches?(proc)
10 begin
11 proc.call
12 rescue NameError => e
13 @actual = e.name.to_sym
14 ensure
15 if @expected.nil?
16 return @actual.nil? ? false : true
17 else
18 return @actual == @expected
19 end
20 end
21 end
22
23 def failure_message
24 if @actual
25 "expected #{expected}, got #{@actual.inspect}"
26 else
27 "expected #{expected} but nothing was thrown"
28 end
29 end
30
31 def negative_failure_message
32 if @expected
33 "expected #{expected} not to be thrown"
34 else
35 "expected no Symbol, got :#{@actual}"
36 end
37 end
38
39 def description
40 "throw #{expected}"
41 end
42
43 private
44
45 def expected
46 @expected.nil? ? "a Symbol" : @expected.inspect
47 end
48
49 end
50
51 # :call-seq:
52 # should throw_symbol()
53 # should throw_symbol(:sym)
54 # should_not throw_symbol()
55 # should_not throw_symbol(:sym)
56 #
57 # Given a Symbol argument, matches if a proc throws the specified Symbol.
58 #
59 # Given no argument, matches if a proc throws any Symbol.
60 #
61 # == Examples
62 #
63 # lambda { do_something_risky }.should throw_symbol
64 # lambda { do_something_risky }.should throw_symbol(:that_was_risky)
65 #
66 # lambda { do_something_risky }.should_not throw_symbol
67 # lambda { do_something_risky }.should_not throw_symbol(:that_was_risky)
68 def throw_symbol(sym=nil)
69 Matchers::ThrowSymbol.new(sym)
70 end
71 end
72 end
Generated using the rcov code coverage analysis tool for Ruby version 0.8.0.