Rspec Steps C0 Coverage Information - RCov

rcov/ruby/1.8/gems/rspec-expectations-2.5.0/lib/rspec/matchers/throw_symbol.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
rcov/ruby/1.8/gems/rspec-expectations-2.5.0/lib/rspec/matchers/throw_symbol.rb 121 80
38.84%
16.25%

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 RSpec
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 
23             if @caught_arg == :nothing_thrown
24               @caught_arg = nil
25             else
26               @caught_symbol = @expected_symbol
27             end
28           end
29 
30         # Ruby 1.8 uses NameError with `symbol'
31         # Ruby 1.9 uses ArgumentError with :symbol
32         rescue NameError, ArgumentError => e
33           unless e.message =~ /uncaught throw (`|\:)([a-zA-Z0-9_]*)(')?/
34             other_exception = e
35             raise
36           end
37           @caught_symbol = $2.to_sym
38         rescue => other_exception
39           raise
40         ensure
41           unless other_exception
42             if @expected_symbol.nil?
43               return !@caught_symbol.nil?
44             else
45               if @expected_arg.nil?
46                 return @caught_symbol == @expected_symbol
47               else
48                 return (@caught_symbol == @expected_symbol) & (@caught_arg == @expected_arg)
49               end
50             end
51           end
52         end
53       end
54 
55       def failure_message_for_should
56         "expected #{expected} to be thrown, got #{caught}"
57       end
58       
59       def failure_message_for_should_not
60         "expected #{expected('no Symbol')}#{' not' if @expected_symbol} to be thrown, got #{caught}"
61       end
62       
63       def description
64         "throw #{expected}"
65       end
66       
67       private
68 
69         def expected(symbol_desc = 'a Symbol')
70           throw_description(@expected_symbol || symbol_desc, @expected_arg)
71         end
72 
73         def caught
74           throw_description(@caught_symbol || 'nothing', @caught_arg)
75         end
76 
77         def throw_description(symbol, arg)
78           symbol_description = symbol.is_a?(String) ? symbol : symbol.inspect
79 
80           arg_description = if arg
81             " with #{arg.inspect}"
82           elsif @expected_arg && @caught_symbol == @expected_symbol
83             " with no argument"
84           else
85             ""
86           end
87 
88           symbol_description + arg_description
89         end
90 
91     end
92  
93     # :call-seq:
94     #   should throw_symbol()
95     #   should throw_symbol(:sym)
96     #   should throw_symbol(:sym, arg)
97     #   should_not throw_symbol()
98     #   should_not throw_symbol(:sym)
99     #   should_not throw_symbol(:sym, arg)
100     #
101     # Given no argument, matches if a proc throws any Symbol.
102     #
103     # Given a Symbol, matches if the given proc throws the specified Symbol.
104     #
105     # Given a Symbol and an arg, matches if the given proc throws the
106     # specified Symbol with the specified arg.
107     #
108     # == Examples
109     #
110     #   lambda { do_something_risky }.should throw_symbol
111     #   lambda { do_something_risky }.should throw_symbol(:that_was_risky)
112     #   lambda { do_something_risky }.should throw_symbol(:that_was_risky, culprit)
113     #
114     #   lambda { do_something_risky }.should_not throw_symbol
115     #   lambda { do_something_risky }.should_not throw_symbol(:that_was_risky)
116     #   lambda { do_something_risky }.should_not throw_symbol(:that_was_risky, culprit)
117     def throw_symbol(expected_symbol = nil, expected_arg=nil)
118       Matchers::ThrowSymbol.new(expected_symbol, expected_arg)
119     end
120   end
121 end

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