C0 code coverage information
Generated on Sun Oct 26 11:18:15 -0500 2008 with rcov 0.8.1.2
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 require File.dirname(__FILE__) + '/../spec_helper'
2 require 'aquarium/finders/type_finder'
3
4 class Outside
5 class Inside1; end
6 class Inside2
7 class ReallyInside; end
8 end
9 end
10 class SubOutside < Outside; end
11
12 describe Aquarium::Finders::TypeFinder, "#find invocation parameters" do
13
14 it "should raise if an uknown option is specified." do
15 lambda { Aquarium::Finders::TypeFinder.new.find :foo => 'bar', :baz => ''}.should raise_error(Aquarium::Utils::InvalidOptions)
16 end
17
18 it "should raise if the input parameters do not form a hash." do
19 lambda { Aquarium::Finders::TypeFinder.new.find "foo" }.should raise_error(Aquarium::Utils::InvalidOptions)
20 end
21
22 it "should return no matched types and no unmatched type expressions by default (i.e., the input is empty)." do
23 actual = Aquarium::Finders::TypeFinder.new.find
24 actual.matched.should == {}
25 actual.not_matched.should == {}
26 end
27
28 it "should return no matched types and no unmatched type expressions if nil is specified for the types." do
29 actual = Aquarium::Finders::TypeFinder.new.find :type => nil
30 actual.matched.should == {}
31 actual.not_matched.should == {}
32 end
33
34 it "should return no matched types and no unmatched type expressions if the input hash is empty." do
35 actual = Aquarium::Finders::TypeFinder.new.find {}
36 actual.matched.should == {}
37 actual.not_matched.should == {}
38 end
39
40 it "should trim leading and trailing whitespace in the specified types." do
41 actual = Aquarium::Finders::TypeFinder.new.find :type => [" \t ", "\t \n"]
42 actual.matched.should == {}
43 actual.not_matched.should == {}
44 end
45
46 it "should ignore an empty string as the specified type." do
47 actual = Aquarium::Finders::TypeFinder.new.find :type => " \t "
48 actual.matched.should == {}
49 actual.not_matched.should == {}
50 end
51
52 it "should ignore empty strings as the specified types in an array of types." do
53 actual = Aquarium::Finders::TypeFinder.new.find :types => [" \t ", "\t \n"]
54 actual.matched.should == {}
55 actual.not_matched.should == {}
56 end
57
58 it "should accept a hash and treat it as equivalent to an explicit list parameters." do
59 expected_found_types = [Outside::Inside1, Outside::Inside2]
60 expected_unfound_exps = %w[NonExistent::SubNonExistent::SubSubNonExistent]
61 hash = {:names => (expected_found_types.map {|t| t.to_s} + expected_unfound_exps)}
62 actual = Aquarium::Finders::TypeFinder.new.find hash
63 actual.matched_keys.sort_by {|x| x.to_s}.should == expected_found_types.sort_by {|x| x.to_s}
64 actual.not_matched_keys.sort.should == expected_unfound_exps.sort
65 end
66 end
67
68 describe Aquarium::Finders::TypeFinder, "#find with :types used to specify a single type" do
69 it "should find a type matching a simple name (without :: namespace delimiters) using its name and the :type option." do
70 actual = Aquarium::Finders::TypeFinder.new.find :types => :Object
71 actual.matched_keys.should == [Object]
72 actual.not_matched.should == {}
73 end
74
75 it "should find a type matching a simple name (without :: namespace delimiters) using its name and the :name option." do
76 actual = Aquarium::Finders::TypeFinder.new.find :types => :Object
77 actual.matched_keys.should == [Object]
78 actual.not_matched.should == {}
79 end
80
81 it "should return an empty match for a simple name (without :: namespace delimiters) that doesn't match an existing type." do
82 actual = Aquarium::Finders::TypeFinder.new.find :types => :Unknown
83 actual.matched.should == {}
84 actual.not_matched_keys.should == [:Unknown]
85 end
86
87 it "should find a type matching a name with :: namespace delimiters using its name." do
88 actual = Aquarium::Finders::TypeFinder.new.find :types => "Outside::Inside1"
89 actual.matched_keys.should == [Outside::Inside1]
90 actual.not_matched.should == {}
91 end
92 end
93
94 describe Aquarium::Finders::TypeFinder, "#find with :types used to specify one or more names" do
95 it "should find types matching simple names (without :: namespace delimiters) using their names." do
96 expected_found_types = [Class, Kernel, Module, Object]
97 expected_unfound_exps = %w[TestCase Unknown1 Unknown2]
98 actual = Aquarium::Finders::TypeFinder.new.find :types=> %w[Kernel Module Object Class TestCase Unknown1 Unknown2]
99 actual.matched_keys.sort.should == expected_found_types.sort
100 actual.not_matched_keys.should == expected_unfound_exps
101 end
102
103 it "should find types with :: namespace delimiters using their names." do
104 expected_found_types = [Outside::Inside1, Outside::Inside2]
105 expected_unfound_exps = %w[NonExistent::SubNonExistent::SubSubNonExistent]
106 actual = Aquarium::Finders::TypeFinder.new.find :names => (expected_found_types.map {|t| t.to_s} + expected_unfound_exps)
107 actual.matched_keys.sort_by {|x| x.to_s}.should == expected_found_types.sort_by {|x| x.to_s}
108 actual.not_matched_keys.sort.should == expected_unfound_exps.sort
109 end
110 end
111
112 describe Aquarium::Finders::TypeFinder, "#find with :types used to specify one or more regular expressions" do
113 it "should find types matching simple names (without :: namespace delimiters) using lists of regular expressions." do
114 expected_found_types = [Class, Kernel, Module, Object]
115 expected_unfound_exps = [/Unknown2/, /^.*TestCase.*$/, /^Unknown1/]
116 actual = Aquarium::Finders::TypeFinder.new.find :types => [/K.+l/, /^Mod.+e$/, /^Object$/, /^Clas{2}$/, /^.*TestCase.*$/, /^Unknown1/, /Unknown2/]
117 actual.matched_keys.sort_by {|x| x.to_s}.should == expected_found_types.sort_by {|x| x.to_s}
118 actual.not_matched_keys.sort.should == expected_unfound_exps.sort
119 end
120
121 it "should find types matching simple names (without :: namespace delimiters) using regular expressions that match parts of the names." do
122 expected_found_types = [FalseClass, Module, TrueClass]
123 expected_unfound_exps = []
124 actual = Aquarium::Finders::TypeFinder.new.find :types => [/eClass$/, /^Modu/]
125 expected_found_types.each {|t| actual.matched_keys.should include(t)}
126 # actual.matched_keys.sort_by {|x| x.to_s}.should == expected_found_types.sort_by {|x| x.to_s}
127 actual.not_matched_keys.sort.should == expected_unfound_exps.sort
128 end
129
130 it "should find types with :: namespace delimiters using lists of regular expressions." do
131 expected_found_types = [Outside::Inside1, Outside::Inside2, Outside::Inside2::ReallyInside]
132 expected_unfound_exps = [/^.*Fo+::.*Bar+::Baz.$/]
133 actual = Aquarium::Finders::TypeFinder.new.find :types => [/^.*Fo+::.*Bar+::Baz.$/, /Outside::.*1$/, /Out.*::In.*2/, /Out.*::In.*2::R.*/]
134 actual.matched_keys.sort_by {|x| x.to_s}.should == expected_found_types.sort_by {|x| x.to_s}
135 actual.not_matched_keys.should == expected_unfound_exps
136 end
137
138 it "should allow a partial trailing name before the first :: namespace delimiter in a regular expression." do
139 expected_found_types = [Outside::Inside1, Outside::Inside2]
140 actual = Aquarium::Finders::TypeFinder.new.find :types => [/side::In.*/]
141 actual.matched_keys.sort_by {|x| x.to_s}.should == expected_found_types.sort_by {|x| x.to_s}
142 actual.not_matched_keys.size.should == 0
143 end
144
145 it "should allow a partial leading name after the last :: namespace delimiter in a regular expression." do
146 expected_found_types = [Outside::Inside1, Outside::Inside2, Outside::Inside2::ReallyInside]
147 actual = Aquarium::Finders::TypeFinder.new.find :types => [/side::In/, /side::Inside2::Real/]
148 actual.matched_keys.sort_by {|x| x.to_s}.should == expected_found_types.sort_by {|x| x.to_s}
149 actual.not_matched_keys.size.should == 0
150 end
151
152 it "should require a full name-matching regular expression between :: namespace delimiters." do
153 expected_found_types = [Outside::Inside2::ReallyInside]
154 actual = Aquarium::Finders::TypeFinder.new.find :types => [/side::In::Real/]
155 actual.matched_keys.size.should == 0
156 actual.not_matched_keys.should == [/side::In::Real/]
157 end
158 end
159
160 describe Aquarium::Finders::TypeFinder, "#find with :types" do
161 Aquarium::Finders::TypeFinder::CANONICAL_OPTIONS["types"].reject{|key| key.eql?("types")}.each do |key|
162 it "should accept :#{key} as a synonym for :types." do
163 actual = Aquarium::Finders::TypeFinder.new.find key.intern => "Outside::Inside1"
164 actual.matched_keys.should == [Outside::Inside1]
165 actual.not_matched.should == {}
166 end
167 end
168 end
169
170 describe Aquarium::Finders::TypeFinder, "#find with :exclude_types" do
171 it "should exclude types specified with a regular expression." do
172 expected_found_types = [Class, Module, Object]
173 actual = Aquarium::Finders::TypeFinder.new.find :types => [/K.+l/, /^Mod.+e$/, /^Object$/, /^Clas{2}$/], :exclude_types => /^Kernel$/
174 actual.matched_keys.sort_by {|x| x.to_s}.should == expected_found_types.sort_by {|x| x.to_s}
175 actual.not_matched.size.should == 0
176 end
177
178 it "should exclude types specified by name." do
179 expected_found_types = [Class, Module]
180 actual = Aquarium::Finders::TypeFinder.new.find :types => [/K.+l/, /^Mod.+e$/, /^Object$/, /^Clas{2}$/], :exclude_types => [Kernel, Object]
181 actual.matched_keys.sort_by {|x| x.to_s}.should == expected_found_types.sort_by {|x| x.to_s}
182 actual.not_matched.size.should == 0
183 end
184
185 it "should not add excluded types to the #not_matched result." do
186 expected_found_types = [Class, Module]
187 actual = Aquarium::Finders::TypeFinder.new.find :types => [/K.+l/, /^Mod.+e$/, /^Object$/, /^Clas{2}$/], :exclude_types => [Kernel, Object]
188 actual.not_matched.size.should == 0
189 end
190
191 Aquarium::Finders::TypeFinder::CANONICAL_OPTIONS["exclude_types"].reject{|key| key.eql?("exclude_types")}.each do |key|
192 it "should accept :#{key} as a synonym for :exclude_types." do
193 expected_found_types = [Class, Module]
194 actual = Aquarium::Finders::TypeFinder.new.find :types => [/K.+l/, /^Mod.+e$/, /^Object$/, /^Clas{2}$/], key.intern => [Kernel, Object]
195 actual.matched_keys.sort_by {|x| x.to_s}.should == expected_found_types.sort_by {|x| x.to_s}
196 actual.not_matched.size.should == 0
197 end
198 end
199 end
200
201 describe Aquarium::Finders::TypeFinder, "#find with :types_and_descendents" do
202 it "should find the types and their descendents." do
203 expected_found_types = [Outside, SubOutside]
204 actual = Aquarium::Finders::TypeFinder.new.find :types_and_descendents => Outside
205 actual.matched_keys.sort_by {|x| x.to_s}.should == expected_found_types.sort_by {|x| x.to_s}
206 actual.not_matched.size.should == 0
207 end
208
209 Aquarium::Finders::TypeFinder::CANONICAL_OPTIONS["types_and_descendents"].reject{|key| key.eql?("types_and_descendents")}.each do |key|
210 it "should accept :#{key} as a synonym for :types_and_descendents." do
211 lambda {actual = Aquarium::Finders::TypeFinder.new.find key.intern => Outside, :noop => true}.should_not raise_error
212 end
213 end
214 end
215
216 describe Aquarium::Finders::TypeFinder, "#find with :types_and_ancestors" do
217 it "should find the types and their ancestors." do
218 actual = Aquarium::Finders::TypeFinder.new.find :types_and_ancestors => SubOutside
219 [Outside, SubOutside, Kernel, Object].each do |x|
220 actual.matched_keys.should include(x)
221 end
222 actual.not_matched.size.should == 0
223 end
224
225 Aquarium::Finders::TypeFinder::CANONICAL_OPTIONS["types_and_ancestors"].reject{|key| key.eql?("types_and_ancestors")}.each do |key|
226 it "should accept :#{key} as a synonym for :types_and_ancestors." do
227 lambda {actual = Aquarium::Finders::TypeFinder.new.find key.intern => SubOutside, :noop => true}.should_not raise_error
228 end
229 end
230 end
231
232 describe Aquarium::Finders::TypeFinder, "#each returns found types" do
233 it "should return only types that were found" do
234 expected_found_types = [Class, Kernel, Module, Object]
235 expected_unfound_exps = %w[TestCase Unknown1 Unknown2]
236 actual = Aquarium::Finders::TypeFinder.new.find :types=> %w[Kernel Module Object Class TestCase Unknown1 Unknown2]
237 actual.each {|t| expected_found_types.include?(t) and not expected_unfound_exps.include?(t.name)}
238 end
239
240 it "should return the same types returned by #matched_keys" do
241 expected_found_types = [Class, Kernel, Module, Object]
242 expected_unfound_exps = %w[TestCase Unknown1 Unknown2]
243 actual = Aquarium::Finders::TypeFinder.new.find :types=> %w[Kernel Module Object Class TestCase Unknown1 Unknown2]
244 actual.each {|t| actual.matched_keys.include?(t)}
245 count = actual.inject(0) {|count, t| count += 1}
246 count.should == actual.matched_keys.size
247 end
248 end
249
250 # This is a spec for a protected method. It's primarily to keep the code coverage 100%, because there is rarely-invoked error handling code...
251 describe Aquarium::Finders::TypeFinder, "#get_type_from_parent should" do
252 it "should raise if a type doesn't exist that matches the constant" do
253 lambda {Aquarium::Finders::TypeFinder.new.send(:get_type_from_parent, Aquarium::Finders, "Nonexistent", /Non/)}.should raise_error(NameError)
254 end
255 end
256
257
Generated using the rcov code coverage analysis tool for Ruby version 0.8.1.2.