Geminstaller C0 Coverage Information - RCov

/Users/woolley/.rvm/gems/ruby-1.8.7-p174@geminstaller/gems/rspec-1.3.0/lib/spec/matchers/have.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/have.rb 152 92
51.32%
19.57%

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 Have #:nodoc:
4       def initialize(expected, relativity=:exactly)
5         @expected = (expected == :no ? 0 : expected)
6         @relativity = relativity
7         @actual = nil
8         @plural_collection_name = nil
9       end
10     
11       def relativities
12         @relativities ||= {
13           :exactly => "",
14           :at_least => "at least ",
15           :at_most => "at most "
16         }
17       end
18     
19       def matches?(collection_owner)
20         if collection_owner.respond_to?(@collection_name)
21           collection = collection_owner.__send__(@collection_name, *@args, &@block)
22         elsif (@plural_collection_name && collection_owner.respond_to?(@plural_collection_name))
23           collection = collection_owner.__send__(@plural_collection_name, *@args, &@block)
24         elsif (collection_owner.respond_to?(:length) || collection_owner.respond_to?(:size))
25           collection = collection_owner
26         else
27           collection_owner.__send__(@collection_name, *@args, &@block)
28         end
29         @actual = collection.size if collection.respond_to?(:size)
30         @actual = collection.length if collection.respond_to?(:length)
31         raise not_a_collection if @actual.nil?
32         return @actual >= @expected if @relativity == :at_least
33         return @actual <= @expected if @relativity == :at_most
34         return @actual == @expected
35       end
36       
37       def not_a_collection
38         "expected #{@collection_name} to be a collection but it does not respond to #length or #size"
39       end
40     
41       def failure_message_for_should
42         "expected #{relative_expectation} #{@collection_name}, got #{@actual}"
43       end
44 
45       def failure_message_for_should_not
46         if @relativity == :exactly
47           return "expected target not to have #{@expected} #{@collection_name}, got #{@actual}"
48         elsif @relativity == :at_most
49           return <<-EOF
50 Isn't life confusing enough?
51 Instead of having to figure out the meaning of this:
52   should_not have_at_most(#{@expected}).#{@collection_name}
53 We recommend that you use this instead:
54   should have_at_least(#{@expected + 1}).#{@collection_name}
55 EOF
56         elsif @relativity == :at_least
57           return <<-EOF
58 Isn't life confusing enough?
59 Instead of having to figure out the meaning of this:
60   should_not have_at_least(#{@expected}).#{@collection_name}
61 We recommend that you use this instead:
62   should have_at_most(#{@expected - 1}).#{@collection_name}
63 EOF
64         end
65       end
66       
67       def description
68         "have #{relative_expectation} #{@collection_name}"
69       end
70       
71       def respond_to?(sym)
72         @expected.respond_to?(sym) || super
73       end
74     
75       private
76       
77       def method_missing(sym, *args, &block)
78         @collection_name = sym
79         if inflector = (defined?(ActiveSupport::Inflector) ? ActiveSupport::Inflector : (defined?(Inflector) ? Inflector : nil))
80           @plural_collection_name = inflector.pluralize(sym.to_s)
81         end
82         @args = args
83         @block = block
84         self
85       end
86       
87       def relative_expectation
88         "#{relativities[@relativity]}#{@expected}"
89       end
90     end
91 
92     # :call-seq:
93     #   should have(number).named_collection__or__sugar
94     #   should_not have(number).named_collection__or__sugar
95     #
96     # Passes if receiver is a collection with the submitted
97     # number of items OR if the receiver OWNS a collection
98     # with the submitted number of items.
99     #
100     # If the receiver OWNS the collection, you must use the name
101     # of the collection. So if a <tt>Team</tt> instance has a
102     # collection named <tt>#players</tt>, you must use that name
103     # to set the expectation.
104     #
105     # If the receiver IS the collection, you can use any name
106     # you like for <tt>named_collection</tt>. We'd recommend using
107     # either "elements", "members", or "items" as these are all
108     # standard ways of describing the things IN a collection.
109     #
110     # This also works for Strings, letting you set an expectation
111     # about its length
112     #
113     # == Examples
114     #
115     #   # Passes if team.players.size == 11
116     #   team.should have(11).players
117     #
118     #   # Passes if [1,2,3].length == 3
119     #   [1,2,3].should have(3).items #"items" is pure sugar
120     #
121     #   # Passes if "this string".length == 11
122     #   "this string".should have(11).characters #"characters" is pure sugar
123     def have(n)
124       Matchers::Have.new(n)
125     end
126     alias :have_exactly :have
127 
128     # :call-seq:
129     #   should have_at_least(number).items
130     #
131     # Exactly like have() with >=.
132     #
133     # == Warning
134     #
135     # +should_not+ +have_at_least+ is not supported
136     def have_at_least(n)
137       Matchers::Have.new(n, :at_least)
138     end
139 
140     # :call-seq:
141     #   should have_at_most(number).items
142     #
143     # Exactly like have() with <=.
144     #
145     # == Warning
146     #
147     # +should_not+ +have_at_most+ is not supported
148     def have_at_most(n)
149       Matchers::Have.new(n, :at_most)
150     end
151   end
152 end

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