Rspec Steps C0 Coverage Information - RCov

rcov/ruby/1.8/gems/rspec-mocks-2.5.0/lib/rspec/mocks/proxy.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
rcov/ruby/1.8/gems/rspec-mocks-2.5.0/lib/rspec/mocks/proxy.rb 158 124
38.61%
25.81%

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 Mocks
3     class Proxy
4       class << self
5         def warn_about_expectations_on_nil
6           defined?(@warn_about_expectations_on_nil) ? @warn_about_expectations_on_nil : true
7         end
8       
9         def warn_about_expectations_on_nil=(new_value)
10           @warn_about_expectations_on_nil = new_value
11         end
12       
13         def allow_message_expectations_on_nil
14           @warn_about_expectations_on_nil = false
15           
16           # ensure nil.rspec_verify is called even if an expectation is not set in the example
17           # otherwise the allowance would effect subsequent examples
18           RSpec::Mocks::space.add(nil) unless RSpec::Mocks::space.nil?
19         end
20 
21         def allow_message_expectations_on_nil?
22           !warn_about_expectations_on_nil
23         end
24       end
25 
26       def initialize(object, name=nil, options={})
27         @object = object
28         @name = name
29         @error_generator = ErrorGenerator.new object, name, options
30         @expectation_ordering = OrderGroup.new @error_generator
31         @messages_received = []
32         @options = options
33         @already_proxied_respond_to = false
34         @null_object = false
35       end
36 
37       def null_object?
38         @null_object
39       end
40 
41       # Tells the object to ignore any messages that aren't explicitly set as
42       # stubs or message expectations.
43       def as_null_object
44         @null_object = true
45         @object
46       end
47 
48       def already_proxied_respond_to # :nodoc:
49         @already_proxied_respond_to = true
50       end
51 
52       def already_proxied_respond_to? # :nodoc:
53         @already_proxied_respond_to
54       end
55 
56       def add_message_expectation(location, method_name, opts={}, &block)        
57         method_double[method_name].add_expectation @error_generator, @expectation_ordering, location, opts, &block
58       end
59 
60       def add_negative_message_expectation(location, method_name, &implementation)
61         method_double[method_name].add_negative_expectation @error_generator, @expectation_ordering, location, &implementation
62       end
63 
64       def add_stub(location, method_name, opts={}, &implementation)
65         method_double[method_name].add_stub @error_generator, @expectation_ordering, location, opts, &implementation
66       end
67       
68       def remove_stub(method_name)
69         method_double[method_name].remove_stub
70       end
71       
72       def verify #:nodoc:
73         method_doubles.each {|d| d.verify}
74       ensure
75         reset
76       end
77 
78       def reset
79         method_doubles.each {|d| d.reset}
80       end
81 
82       def received_message?(method_name, *args, &block)
83         @messages_received.any? {|array| array == [method_name, args, block]}
84       end
85 
86       def has_negative_expectation?(method_name)
87         method_double[method_name].expectations.detect {|expectation| expectation.negative_expectation_for?(method_name)}
88       end
89       
90       def record_message_received(method_name, *args, &block)
91         @messages_received << [method_name, args, block]
92       end
93 
94       def message_received(method_name, *args, &block)
95         expectation = find_matching_expectation(method_name, *args)
96         stub = find_matching_method_stub(method_name, *args)
97 
98         if (stub && expectation && expectation.called_max_times?) || (stub && !expectation)
99           expectation.increase_actual_received_count! if expectation && expectation.actual_received_count_matters?
100           if expectation = find_almost_matching_expectation(method_name, *args)
101             expectation.advise(*args) unless expectation.expected_messages_received?
102           end
103           stub.invoke(*args, &block)
104         elsif expectation
105           expectation.invoke(*args, &block)
106         elsif expectation = find_almost_matching_expectation(method_name, *args)
107           expectation.advise(*args) if null_object? unless expectation.expected_messages_received?
108           raise_unexpected_message_args_error(expectation, *args) unless (has_negative_expectation?(method_name) or null_object?)
109         elsif stub = find_almost_matching_stub(method_name, *args)
110           stub.advise(*args)
111           raise_unexpected_message_args_error(stub, *args)
112         elsif @object.is_a?(Class)
113           @object.superclass.send(method_name, *args, &block)
114         else
115           @object.__send__(:method_missing, method_name, *args, &block)
116         end
117       end
118 
119       def raise_unexpected_message_args_error(expectation, *args)
120         @error_generator.raise_unexpected_message_args_error(expectation, *args)
121       end
122 
123       def raise_unexpected_message_error(method_name, *args)
124         @error_generator.raise_unexpected_message_error method_name, *args
125       end
126       
127     private
128 
129       def method_double
130         @method_double ||= Hash.new {|h,k|
131           h[k] = MethodDouble.new(@object, k, self)
132         }
133       end
134 
135       def method_doubles
136         method_double.values
137       end
138       
139       def find_matching_expectation(method_name, *args)
140         method_double[method_name].expectations.find {|expectation| expectation.matches?(method_name, *args) && !expectation.called_max_times?} || 
141         method_double[method_name].expectations.find {|expectation| expectation.matches?(method_name, *args)}
142       end
143 
144       def find_almost_matching_expectation(method_name, *args)
145         method_double[method_name].expectations.find {|expectation| expectation.matches_name_but_not_args(method_name, *args) && !expectation.called_max_times?}
146       end
147 
148       def find_matching_method_stub(method_name, *args)
149         method_double[method_name].stubs.find {|stub| stub.matches?(method_name, *args)}
150       end
151 
152       def find_almost_matching_stub(method_name, *args)
153         method_double[method_name].stubs.find {|stub| stub.matches_name_but_not_args(method_name, *args)}
154       end
155 
156     end
157   end
158 end

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