Name | Total Lines | Lines of Code | Total Coverage | Code Coverage |
---|---|---|---|---|
rcov/ruby/1.8/gems/rspec-mocks-2.5.0/lib/rspec/mocks/methods.rb | 100 | 76 | 41.00%
|
23.68%
|
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 RSpec |
2 module Mocks |
3 module Methods |
4 def should_receive(sym, opts={}, &block) |
5 __mock_proxy.add_message_expectation(opts[:expected_from] || caller(1)[0], sym.to_sym, opts, &block) |
6 end |
7 |
8 def should_not_receive(sym, &block) |
9 __mock_proxy.add_negative_message_expectation(caller(1)[0], sym.to_sym, &block) |
10 end |
11 |
12 def stub(sym_or_hash, opts={}, &block) |
13 if Hash === sym_or_hash |
14 sym_or_hash.each {|method, value| stub!(method).and_return value } |
15 else |
16 __mock_proxy.add_stub(caller(1)[0], sym_or_hash.to_sym, opts, &block) |
17 end |
18 end |
19 |
20 def unstub(sym) |
21 __mock_proxy.remove_stub(sym) |
22 end |
23 |
24 alias_method :stub!, :stub |
25 alias_method :unstub!, :unstub |
26 |
27 # :call-seq: |
28 # double.stub_chain("foo.bar") { :baz } |
29 # double.stub_chain(:foo, :bar) { :baz } |
30 # |
31 # Stubs a chain of methods. Especially useful with fluent and/or |
32 # composable interfaces. |
33 # |
34 # == Examples |
35 # |
36 # Article.stub_chain("recent.published") { [Article.new] } |
37 def stub_chain(*chain, &blk) |
38 chain, blk = format_chain(*chain, &blk) |
39 if chain.length > 1 |
40 if matching_stub = __mock_proxy.__send__(:find_matching_method_stub, chain[0].to_sym) |
41 chain.shift |
42 matching_stub.invoke.stub_chain(*chain) |
43 else |
44 next_in_chain = Object.new |
45 stub(chain.shift) { next_in_chain } |
46 next_in_chain.stub_chain(*chain, &blk) |
47 end |
48 else |
49 stub(chain.shift, &blk) |
50 end |
51 end |
52 |
53 def received_message?(sym, *args, &block) #:nodoc: |
54 __mock_proxy.received_message?(sym.to_sym, *args, &block) |
55 end |
56 |
57 def rspec_verify #:nodoc: |
58 __mock_proxy.verify |
59 end |
60 |
61 def rspec_reset #:nodoc: |
62 __mock_proxy.reset |
63 end |
64 |
65 def as_null_object |
66 __mock_proxy.as_null_object |
67 end |
68 |
69 def null_object? |
70 __mock_proxy.null_object? |
71 end |
72 |
73 private |
74 |
75 def __mock_proxy |
76 @mock_proxy ||= begin |
77 mp = if Mock === self |
78 Proxy.new(self, @name, @options) |
79 else |
80 Proxy.new(self) |
81 end |
82 |
83 Serialization.fix_for(self) |
84 mp |
85 end |
86 end |
87 |
88 def format_chain(*chain, &blk) |
89 if Hash === chain.last |
90 hash = chain.pop |
91 hash.each do |k,v| |
92 chain << k |
93 blk = lambda { v } |
94 end |
95 end |
96 return chain.join('.').split('.'), blk |
97 end |
98 end |
99 end |
100 end |
Generated on Fri Apr 22 17:22:41 -0700 2011 with rcov 0.9.8