Geminstaller C0 Coverage Information - RCov

/Users/woolley/.rvm/gems/ruby-1.8.7-p174@geminstaller/gems/rspec-1.3.0/lib/spec/matchers/matcher.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/matcher.rb 132 94
71.97%
61.70%

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     class Matcher
4       include Spec::Matchers::InstanceExec
5       include Spec::Matchers::Pretty
6       include Spec::Matchers
7 
8       attr_reader :expected, :actual
9 
10       def initialize(name, *expected, &declarations)
11         @name     = name
12         @expected = expected
13         @actual   = nil
14         @diffable = false
15         @expected_exception = nil
16         @messages = {
17           :description => lambda {"#{name_to_sentence}#{expected_to_sentence}"},
18           :failure_message_for_should => lambda {|actual| "expected #{actual.inspect} to #{name_to_sentence}#{expected_to_sentence}"},
19           :failure_message_for_should_not => lambda {|actual| "expected #{actual.inspect} not to #{name_to_sentence}#{expected_to_sentence}"}
20         }
21         making_declared_methods_public do
22           instance_exec(*@expected, &declarations)
23         end
24       end
25 
26       #Used internally by objects returns by +should+ and +should_not+.
27       def matches?(actual)
28         @actual = actual
29         if @expected_exception
30           begin
31             instance_exec(actual, &@match_block)
32             true
33           rescue @expected_exception
34             false
35           end
36         else
37           begin
38             instance_exec(actual, &@match_block)
39           rescue Spec::Expectations::ExpectationNotMetError
40             false
41           end
42         end
43       end
44 
45       # See Spec::Matchers
46       def match(&block)
47         @match_block = block
48       end
49 
50       # See Spec::Matchers
51       def match_unless_raises(exception=Exception, &block)
52         @expected_exception = exception
53         match(&block)
54       end
55 
56       # See Spec::Matchers
57       def failure_message_for_should(&block)
58         cache_or_call_cached(:failure_message_for_should, &block)
59       end
60 
61       # See Spec::Matchers
62       def failure_message_for_should_not(&block)
63         cache_or_call_cached(:failure_message_for_should_not, &block)
64       end
65 
66       # See Spec::Matchers
67       def description(&block)
68         cache_or_call_cached(:description, &block)
69       end
70 
71       #Used internally by objects returns by +should+ and +should_not+.
72       def diffable?
73         @diffable
74       end
75 
76       # See Spec::Matchers
77       def diffable
78         @diffable = true
79       end
80       
81       # See Spec::Matchers
82       def chain(method, &block)
83         self.class.class_eval do
84           define_method method do |*args|
85             block.call(*args)
86             self
87           end
88         end
89       end
90 
91     private
92 
93       def making_declared_methods_public # :nodoc:
94         # Our home-grown instance_exec in ruby 1.8.6 results in any methods
95         # declared in the block eval'd by instance_exec in the block to which we
96         # are yielding here are scoped private. This is NOT the case for Ruby
97         # 1.8.7 or 1.9.
98         #
99         # Also, due some crazy scoping that I don't understand, these methods
100         # are actually available in the specs (something about the matcher being
101         # defined in the scope of Spec::Matchers or within an example), so not
102         # doing the following will not cause specs to fail, but they *will*
103         # cause features to fail and that will make users unhappy. So don't.
104         orig_private_methods = private_methods
105         yield
106         st = (class << self; self; end)
107         (private_methods - orig_private_methods).each {|m| st.__send__ :public, m}
108       end
109 
110       def cache_or_call_cached(key, &block)
111         block ? cache(key, &block) : call_cached(key)
112       end
113 
114       def cache(key, &block)
115         @messages[key] = block
116       end
117 
118       def call_cached(key)
119         @messages[key].arity == 1 ? @messages[key].call(@actual) : @messages[key].call
120       end
121 
122       def name_to_sentence
123         split_words(@name)
124       end
125 
126       def expected_to_sentence
127         to_sentence(@expected)
128       end
129 
130     end
131   end
132 end

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