Geminstaller C0 Coverage Information - RCov

/Users/woolley/.rvm/gems/ruby-1.8.7-p174@geminstaller/gems/rspec-1.3.0/lib/spec/matchers/throw_symbol.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/throw_symbol.rb 100 63
45.00%
19.05%

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 
4     class ThrowSymbol #:nodoc:
5       def initialize(expected_symbol = nil, expected_arg=nil)
6         @expected_symbol = expected_symbol
7         @expected_arg = expected_arg
8         @caught_symbol = @caught_arg = nil
9       end
10 
11       def matches?(given_proc)
12         begin
13           if @expected_symbol.nil?
14             given_proc.call
15           else
16             @caught_arg = catch :proc_did_not_throw_anything do
17               catch @expected_symbol do
18                 given_proc.call
19                 throw :proc_did_not_throw_anything, :nothing_thrown
20               end
21             end
22             @caught_symbol = @expected_symbol unless @caught_arg == :nothing_thrown
23           end
24 
25         # Ruby 1.8 uses NameError with `symbol'
26         # Ruby 1.9 uses ArgumentError with :symbol
27         rescue NameError, ArgumentError => e
28           raise e unless e.message =~ /uncaught throw (`|\:)([a-zA-Z0-9_]*)(')?/
29           @caught_symbol = $2.to_sym
30         end
31         if @expected_symbol.nil?
32           !@caught_symbol.nil?
33         elsif @expected_arg.nil?
34           @caught_symbol == @expected_symbol
35         else
36           (@caught_symbol == @expected_symbol) & (@caught_arg == @expected_arg)
37         end
38       end
39 
40       def failure_message_for_should
41         if @caught_symbol
42           "expected #{expected}, got #{@caught_symbol.inspect}"
43         else
44           "expected #{expected} but nothing was thrown"
45         end
46       end
47 
48       def failure_message_for_should_not
49         if @expected_symbol
50           "expected #{expected} not to be thrown"
51         else
52           "expected no Symbol, got :#{@caught_symbol}"
53         end
54       end
55 
56       def description
57         "throw #{expected}"
58       end
59 
60       private
61 
62         def expected
63           @expected_symbol.nil? ? "a Symbol" : "#{@expected_symbol.inspect}#{args}"
64         end
65 
66         def args
67           @expected_arg.nil? ? "" : " with #{@expected_arg.inspect}"
68         end
69 
70     end
71 
72     # :call-seq:
73     #   should throw_symbol()
74     #   should throw_symbol(:sym)
75     #   should throw_symbol(:sym, arg)
76     #   should_not throw_symbol()
77     #   should_not throw_symbol(:sym)
78     #   should_not throw_symbol(:sym, arg)
79     #
80     # Given no argument, matches if a proc throws any Symbol.
81     #
82     # Given a Symbol, matches if the given proc throws the specified Symbol.
83     #
84     # Given a Symbol and an arg, matches if the given proc throws the
85     # specified Symbol with the specified arg.
86     #
87     # == Examples
88     #
89     #   lambda { do_something_risky }.should throw_symbol
90     #   lambda { do_something_risky }.should throw_symbol(:that_was_risky)
91     #   lambda { do_something_risky }.should throw_symbol(:that_was_risky, culprit)
92     #
93     #   lambda { do_something_risky }.should_not throw_symbol
94     #   lambda { do_something_risky }.should_not throw_symbol(:that_was_risky)
95     #   lambda { do_something_risky }.should_not throw_symbol(:that_was_risky, culprit)
96     def throw_symbol(sym=nil)
97       Matchers::ThrowSymbol.new(sym)
98     end
99   end
100 end

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