aquarium 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. data/CHANGES +4 -0
  2. data/EXAMPLES.rd +4 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README +250 -0
  5. data/RELEASE-PLAN +1 -0
  6. data/Rakefile +236 -0
  7. data/UPGRADE +3 -0
  8. data/examples/aspect_design_example.rb +36 -0
  9. data/examples/design_by_contract_example.rb +88 -0
  10. data/examples/method_missing_example.rb +44 -0
  11. data/examples/method_tracing_example.rb +64 -0
  12. data/lib/aquarium.rb +7 -0
  13. data/lib/aquarium/aspects.rb +6 -0
  14. data/lib/aquarium/aspects/advice.rb +189 -0
  15. data/lib/aquarium/aspects/aspect.rb +577 -0
  16. data/lib/aquarium/aspects/default_object_handler.rb +27 -0
  17. data/lib/aquarium/aspects/dsl.rb +1 -0
  18. data/lib/aquarium/aspects/dsl/aspect_dsl.rb +61 -0
  19. data/lib/aquarium/aspects/join_point.rb +158 -0
  20. data/lib/aquarium/aspects/pointcut.rb +254 -0
  21. data/lib/aquarium/aspects/pointcut_composition.rb +36 -0
  22. data/lib/aquarium/extensions.rb +5 -0
  23. data/lib/aquarium/extensions/hash.rb +85 -0
  24. data/lib/aquarium/extensions/regexp.rb +20 -0
  25. data/lib/aquarium/extensions/set.rb +49 -0
  26. data/lib/aquarium/extensions/string.rb +13 -0
  27. data/lib/aquarium/extensions/symbol.rb +22 -0
  28. data/lib/aquarium/extras.rb +4 -0
  29. data/lib/aquarium/extras/design_by_contract.rb +64 -0
  30. data/lib/aquarium/finders.rb +4 -0
  31. data/lib/aquarium/finders/finder_result.rb +121 -0
  32. data/lib/aquarium/finders/method_finder.rb +228 -0
  33. data/lib/aquarium/finders/object_finder.rb +74 -0
  34. data/lib/aquarium/finders/type_finder.rb +127 -0
  35. data/lib/aquarium/utils.rb +9 -0
  36. data/lib/aquarium/utils/array_utils.rb +29 -0
  37. data/lib/aquarium/utils/hash_utils.rb +28 -0
  38. data/lib/aquarium/utils/html_escaper.rb +17 -0
  39. data/lib/aquarium/utils/invalid_options.rb +9 -0
  40. data/lib/aquarium/utils/method_utils.rb +18 -0
  41. data/lib/aquarium/utils/nil_object.rb +13 -0
  42. data/lib/aquarium/utils/set_utils.rb +32 -0
  43. data/lib/aquarium/version.rb +30 -0
  44. data/rake_tasks/examples.rake +7 -0
  45. data/rake_tasks/examples_specdoc.rake +8 -0
  46. data/rake_tasks/examples_with_rcov.rake +8 -0
  47. data/rake_tasks/verify_rcov.rake +7 -0
  48. data/spec/aquarium/aspects/advice_chain_node_spec.rb +34 -0
  49. data/spec/aquarium/aspects/advice_spec.rb +103 -0
  50. data/spec/aquarium/aspects/aspect_invocation_spec.rb +111 -0
  51. data/spec/aquarium/aspects/aspect_spec.rb +978 -0
  52. data/spec/aquarium/aspects/aspect_with_nested_types_spec.rb +129 -0
  53. data/spec/aquarium/aspects/concurrent_aspects_spec.rb +423 -0
  54. data/spec/aquarium/aspects/concurrent_aspects_with_objects_and_types_spec.rb +103 -0
  55. data/spec/aquarium/aspects/concurrently_accessed.rb +21 -0
  56. data/spec/aquarium/aspects/dsl/aspect_dsl_spec.rb +514 -0
  57. data/spec/aquarium/aspects/join_point_spec.rb +302 -0
  58. data/spec/aquarium/aspects/pointcut_and_composition_spec.rb +131 -0
  59. data/spec/aquarium/aspects/pointcut_or_composition_spec.rb +111 -0
  60. data/spec/aquarium/aspects/pointcut_spec.rb +800 -0
  61. data/spec/aquarium/extensions/hash_spec.rb +187 -0
  62. data/spec/aquarium/extensions/regex_spec.rb +40 -0
  63. data/spec/aquarium/extensions/set_spec.rb +105 -0
  64. data/spec/aquarium/extensions/string_spec.rb +25 -0
  65. data/spec/aquarium/extensions/symbol_spec.rb +37 -0
  66. data/spec/aquarium/extras/design_by_contract_spec.rb +68 -0
  67. data/spec/aquarium/finders/finder_result_spec.rb +359 -0
  68. data/spec/aquarium/finders/method_finder_spec.rb +878 -0
  69. data/spec/aquarium/finders/method_sorting_spec.rb +16 -0
  70. data/spec/aquarium/finders/object_finder_spec.rb +230 -0
  71. data/spec/aquarium/finders/type_finder_spec.rb +210 -0
  72. data/spec/aquarium/spec_example_classes.rb +117 -0
  73. data/spec/aquarium/spec_helper.rb +3 -0
  74. data/spec/aquarium/utils/array_utils_spec.rb +47 -0
  75. data/spec/aquarium/utils/hash_utils_spec.rb +48 -0
  76. data/spec/aquarium/utils/html_escaper_spec.rb +18 -0
  77. data/spec/aquarium/utils/method_utils_spec.rb +50 -0
  78. data/spec/aquarium/utils/nil_object_spec.rb +19 -0
  79. data/spec/aquarium/utils/set_utils_spec.rb +60 -0
  80. metadata +132 -0
@@ -0,0 +1,16 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
+
3
+ describe "Method Extension" do
4
+ it "should compare methods by type and name." do
5
+ actual = %w[send nil? clone gsub! ].map {|m| Kernel.method(m)}
6
+ actual << Module.method(:nesting)
7
+ sorted = actual.sort_by {|method| method.to_s}
8
+ sorted.should == [
9
+ Kernel.method(:gsub!),
10
+ Kernel.method(:clone),
11
+ Kernel.method(:nil?),
12
+ Kernel.method(:send),
13
+ Module.method(:nesting)
14
+ ]
15
+ end
16
+ end
@@ -0,0 +1,230 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
+ require 'aquarium/finders/object_finder'
3
+
4
+ # :stopdoc:
5
+ class OBase
6
+ attr_reader :name
7
+ def initialize name; @name = name; end
8
+ def == other
9
+ name == other.name
10
+ end
11
+ end
12
+
13
+ class ODerived < OBase
14
+ def initialize name; super; end
15
+ end
16
+
17
+ module Mod; end
18
+
19
+ class IncludesMod
20
+ include Mod
21
+ attr_reader :name
22
+ def initialize name; @name = name; end
23
+ def == other
24
+ name == other.name
25
+ end
26
+ end
27
+
28
+ class ClassNotInstantiated; end
29
+ class ClassNotInstantiated2; end
30
+ # :startdoc:
31
+
32
+ b1 = OBase.new "b1"
33
+ b2 = OBase.new "b2"
34
+ d1 = ODerived.new "d1"
35
+ d2 = ODerived.new "d2"
36
+ m1 = IncludesMod.new "m1"
37
+ m2 = IncludesMod.new "m2"
38
+
39
+ def space_of_objects
40
+ end
41
+
42
+ # Running the tests with the real Aquarium::Finders::ObjectFinder is too slow when looking
43
+ # for "objects" of type Class or Module, i.e., to retrieve classes and modules.
44
+ class MockObjectSpace
45
+ @@space_of_objects = [OBase, ODerived, String, IncludesMod, Mod, Kernel, Class]
46
+
47
+ def self.each_object type
48
+ @@space_of_objects.each do |object|
49
+ yield(object) if (object.kind_of?(type) and block_given?)
50
+ end
51
+ end
52
+ end
53
+
54
+ class TestObjectFinder < Aquarium::Finders::ObjectFinder
55
+ def initialize
56
+ super MockObjectSpace
57
+ end
58
+ end
59
+
60
+ describe Aquarium::Finders::ObjectFinder, "#find_all_by_types" do
61
+ it "should return an empty FinderResult#matched hash and FinderResult#not_matched list if no types are specified." do
62
+ actual = Aquarium::Finders::ObjectFinder.new.find_all_by_types
63
+ actual.matched.should == {}
64
+ actual.not_matched == []
65
+ end
66
+
67
+ it "should return the input types in the FinderResult#not_matched list if the specified types have no instances." do
68
+ actual = Aquarium::Finders::ObjectFinder.new.find_all_by_types ClassNotInstantiated
69
+ actual.matched_keys.should == []
70
+ actual.not_matched == [ClassNotInstantiated]
71
+ end
72
+ end
73
+
74
+ describe Aquarium::Finders::ObjectFinder, ".find_all_by_types" do
75
+
76
+ it "should return all objects of a specified base type and its derivatives." do
77
+ actual = Aquarium::Finders::ObjectFinder.new.find_all_by_types(OBase)
78
+ actual.matched.size.should == 1
79
+ actual.matched[OBase].sort_by {|o| o.name}.should == [b1, b2, d1, d2]
80
+ actual.not_matched.should == {}
81
+ end
82
+
83
+ it "should return all objects of a specified derived type." do
84
+ actual = Aquarium::Finders::ObjectFinder.new.find_all_by_types(ODerived)
85
+ actual.matched.size.should == 1
86
+ actual.matched[ODerived].sort_by {|o| o.name}.should == [d1, d2]
87
+ actual.not_matched.should == {}
88
+ end
89
+
90
+ it "should return all objects of a specified module." do
91
+ actual = Aquarium::Finders::ObjectFinder.new.find_all_by_types(Mod)
92
+ actual.matched.size.should == 1
93
+ actual.matched[Mod].sort_by {|o| o.name}.should == [m1, m2]
94
+ actual.not_matched.should == {}
95
+ end
96
+
97
+ it "should return all objects of a list of types." do
98
+ actual = Aquarium::Finders::ObjectFinder.new.find_all_by_types(ODerived, Mod)
99
+ actual.matched.size.should == 2
100
+ actual.matched[ODerived].sort_by {|o| o.name}.should == [d1, d2]
101
+ actual.matched[Mod].sort_by {|o| o.name}.should == [m1, m2]
102
+ actual.not_matched.should == {}
103
+ end
104
+
105
+ it "should return all objects of an array of types." do
106
+ actual = Aquarium::Finders::ObjectFinder.new.find_all_by_types([ODerived, Mod])
107
+ actual.matched.size.should == 2
108
+ actual.matched[ODerived].sort_by {|o| o.name}.should == [d1, d2]
109
+ actual.matched[Mod].sort_by {|o| o.name}.should == [m1, m2]
110
+ actual.not_matched.should == {}
111
+ end
112
+
113
+ end
114
+
115
+ describe Aquarium::Finders::ObjectFinder, "#find" do
116
+
117
+ it "should return all objects of a specified base type and its derivatives." do
118
+ actual = Aquarium::Finders::ObjectFinder.new.find :type => OBase
119
+ actual.matched.size.should == 1
120
+ actual.matched[OBase].sort_by {|o| o.name}.should == [b1, b2, d1, d2]
121
+ actual.not_matched.should == {}
122
+ end
123
+
124
+ it "should return all objects of a specified derived type." do
125
+ actual = Aquarium::Finders::ObjectFinder.new.find :types => ODerived
126
+ actual.matched.size.should == 1
127
+ actual.matched[ODerived].sort_by {|o| o.name}.should == [d1, d2]
128
+ actual.not_matched.should == {}
129
+ end
130
+
131
+ it "should return all objects of a specified module." do
132
+ actual = Aquarium::Finders::ObjectFinder.new.find :type => Mod
133
+ actual.matched.size.should == 1
134
+ actual.matched[Mod].sort_by {|o| o.name}.should == [m1, m2]
135
+ actual.not_matched.should == {}
136
+ end
137
+
138
+ it "should return all objects of a list of types." do
139
+ actual = Aquarium::Finders::ObjectFinder.new.find :type => [ODerived, Mod]
140
+ actual.matched.size.should == 2
141
+ actual.matched[ODerived].sort_by {|o| o.name}.should == [d1, d2]
142
+ actual.matched[Mod].sort_by {|o| o.name}.should == [m1, m2]
143
+ actual.not_matched.should == {}
144
+ end
145
+
146
+ it "should accept an array of one type or the type itself as the value for the :type key." do
147
+ actual1 = Aquarium::Finders::ObjectFinder.new.find :type => Mod
148
+ actual2 = Aquarium::Finders::ObjectFinder.new.find :type => [Mod]
149
+ actual1.matched.should == actual2.matched
150
+ actual1.matched.should == actual2.matched
151
+ end
152
+
153
+ it "should accept :type as a synonym for the :types key." do
154
+ actual1 = Aquarium::Finders::ObjectFinder.new.find :types => Mod
155
+ actual2 = Aquarium::Finders::ObjectFinder.new.find :type => Mod
156
+ actual1.matched.should == actual2.matched
157
+ actual1.matched.should == actual2.matched
158
+ end
159
+
160
+
161
+ it "should behave as find_all_by with a different invocation syntax." do
162
+ actual1 = Aquarium::Finders::ObjectFinder.new.find :types => Mod
163
+ actual2 = Aquarium::Finders::ObjectFinder.new.find :type => Mod
164
+ actual1.matched.should == actual2.matched
165
+ actual1.matched.should == actual2.matched
166
+ end
167
+ end
168
+
169
+ describe Aquarium::Finders::ObjectFinder, "#find" do
170
+ it "should return an empty FinderResult#matched hash and FinderResult#not_matched list if no types are specified." do
171
+ actual = Aquarium::Finders::ObjectFinder.new.find
172
+ actual.matched.should == {}
173
+ actual.not_matched.should == {}
174
+ end
175
+
176
+ it "should return the input types in the FinderResult#not_matched list if the types have no instances." do
177
+ actual = Aquarium::Finders::ObjectFinder.new.find :type => "ClassNotInstantiated"
178
+ actual.matched_keys.should == []
179
+ actual.not_matched_keys.should == [ClassNotInstantiated]
180
+ end
181
+
182
+ it "should accept a single type name as the value for the key :type." do
183
+ actual = Aquarium::Finders::ObjectFinder.new.find :type => "ClassNotInstantiated"
184
+ actual.matched_keys.should == []
185
+ actual.not_matched_keys.should == [ClassNotInstantiated]
186
+ end
187
+
188
+ it "should accept an array of type names as the value for the key :types." do
189
+ actual = Aquarium::Finders::ObjectFinder.new.find :type => ["ClassNotInstantiated", "ClassNotInstantiated2"]
190
+ actual.matched_keys.should == []
191
+ actual.not_matched_keys.size.should == 2
192
+ actual.not_matched_keys.should include(ClassNotInstantiated)
193
+ actual.not_matched_keys.should include(ClassNotInstantiated2)
194
+ end
195
+
196
+ it "should return the input types in the FinderResult#not_matched list if the types do not exist." do
197
+ type_list = [/^NeverBeforeSeen/, "NotLikelyToExistClass"]
198
+ actual = Aquarium::Finders::ObjectFinder.new.find :type => type_list
199
+ actual.matched_keys.should == []
200
+ actual.not_matched_keys.should == type_list
201
+ end
202
+
203
+ it "should accept :type and :types as synonyms for type name hash keys." do
204
+ type_list = [/^NeverBeforeSeen/, "NotLikelyToExistClass"]
205
+ actual1 = Aquarium::Finders::ObjectFinder.new.find :type => type_list
206
+ actual2 = Aquarium::Finders::ObjectFinder.new.find :types => type_list
207
+ actual1.matched.should == actual2.matched
208
+ actual1.not_matched.should == actual2.not_matched
209
+ end
210
+ end
211
+
212
+ describe Aquarium::Finders::ObjectFinder, "#find" do
213
+ it "should return classes, not objects, when given Class as the type." do
214
+ # Uses Test override for faster test execution.
215
+ actual = TestObjectFinder.new.find :type => Class
216
+ actual.matched[Class].should include(OBase)
217
+ actual.matched[Class].should include(ODerived)
218
+ actual.matched[Class].should include(String)
219
+ actual.not_matched_keys.should == []
220
+ end
221
+
222
+ it "should return modules, not objects, when given Module as the type." do
223
+ # Uses Test override for faster test execution.
224
+ actual = TestObjectFinder.new.find :type => Module
225
+ actual.matched[Module].should include(Mod)
226
+ actual.matched[Module].should include(Kernel)
227
+ actual.matched[Module].should include(Class)
228
+ actual.not_matched_keys.should == []
229
+ end
230
+ end
@@ -0,0 +1,210 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
+ require 'aquarium/finders/type_finder'
3
+
4
+ describe Aquarium::Finders::TypeFinder, "#find" do
5
+
6
+ it "should raise if an uknown option is specified." do
7
+ lambda { Aquarium::Finders::TypeFinder.new.find :foo => 'bar', :baz => ''}.should raise_error(Aquarium::Utils::InvalidOptions)
8
+ end
9
+
10
+ it "should raise if the input parameters do not form a hash." do
11
+ lambda { Aquarium::Finders::TypeFinder.new.find "foo" }.should raise_error(Aquarium::Utils::InvalidOptions)
12
+ end
13
+
14
+ it "should return no matched and no unmatched expressions by default (i.e., the input is empty)." do
15
+ actual = Aquarium::Finders::TypeFinder.new.find
16
+ actual.matched.should == {}
17
+ actual.not_matched.should == {}
18
+ end
19
+
20
+ it "should return no matched and no unmatched expressions if the input hash is empty." do
21
+ actual = Aquarium::Finders::TypeFinder.new.find {}
22
+ actual.matched.should == {}
23
+ actual.not_matched.should == {}
24
+ end
25
+
26
+ it "should trim leading and trailing whitespace in the specified types." do
27
+ actual = Aquarium::Finders::TypeFinder.new.find :type => [" \t ", "\t \n"]
28
+ actual.matched.should == {}
29
+ actual.not_matched.should == {}
30
+ end
31
+
32
+ it "should ignore an empty string as the specified type." do
33
+ actual = Aquarium::Finders::TypeFinder.new.find :type => " \t "
34
+ actual.matched.should == {}
35
+ actual.not_matched.should == {}
36
+ end
37
+
38
+ it "should ignore empty strings as the specified types in an array of types." do
39
+ actual = Aquarium::Finders::TypeFinder.new.find :types => [" \t ", "\t \n"]
40
+ actual.matched.should == {}
41
+ actual.not_matched.should == {}
42
+ end
43
+ end
44
+
45
+ describe Aquarium::Finders::TypeFinder, "#is_recognized_option" do
46
+
47
+ it "should be true for :names, :types, :name, :type (synonyms), as strings or symbols." do
48
+ %w[name type names types].each do |s|
49
+ Aquarium::Finders::TypeFinder.is_recognized_option(s).should == true
50
+ Aquarium::Finders::TypeFinder.is_recognized_option(s.to_sym).should == true
51
+ end
52
+ end
53
+
54
+ it "should be false for unknown options." do
55
+ %w[public2 wierd unknown string method object].each do |s|
56
+ Aquarium::Finders::TypeFinder.is_recognized_option(s).should == false
57
+ Aquarium::Finders::TypeFinder.is_recognized_option(s.to_sym).should == false
58
+ end
59
+ end
60
+ end
61
+
62
+ class Outside
63
+ class Inside1; end
64
+ class Inside2; end
65
+ end
66
+
67
+ describe Aquarium::Finders::TypeFinder, "#find with :type or :name used to specify a single type" do
68
+ it "should find a type matching a simple name (without :: namespace delimiters) using its name." do
69
+ actual = Aquarium::Finders::TypeFinder.new.find :type => :Object
70
+ actual.matched_keys.should == [Object]
71
+ actual.not_matched.should == {}
72
+ end
73
+
74
+ it "should return an empty match for a simple name (without :: namespace delimiters) that doesn't match an existing class." do
75
+ actual = Aquarium::Finders::TypeFinder.new.find :name => :Unknown
76
+ actual.matched.should == {}
77
+ actual.not_matched_keys.should == [:Unknown]
78
+ end
79
+
80
+ it "should find a type matching a name with :: namespace delimiters using its name." do
81
+ actual = Aquarium::Finders::TypeFinder.new.find :name => "Outside::Inside1"
82
+ actual.matched_keys.should == [Outside::Inside1]
83
+ actual.not_matched.should == {}
84
+ end
85
+ end
86
+
87
+ describe Aquarium::Finders::TypeFinder, "#find with :types, :names, :type, and :name used to specify one or more names and/or regular expressions" do
88
+ it "should find types matching simple names (without :: namespace delimiters) using their names." do
89
+ expected_found_types = [Class, Kernel, Module, Object]
90
+ expected_unfound_exps = %w[TestCase Unknown1 Unknown2]
91
+ actual = Aquarium::Finders::TypeFinder.new.find :types=> %w[Kernel Module Object Class TestCase Unknown1 Unknown2]
92
+ actual.matched_keys.sort.should == expected_found_types.sort
93
+ actual.not_matched_keys.should == expected_unfound_exps
94
+ end
95
+
96
+ it "should find types matching simple names (without :: namespace delimiters) using lists of regular expressions." do
97
+ expected_found_types = [Class, Kernel, Module, Object]
98
+ expected_unfound_exps = [/Unknown2/, /^.*TestCase.*$/, /^Unknown1/]
99
+ actual = Aquarium::Finders::TypeFinder.new.find :types => [/K.+l/, /^Mod.+e$/, /^Object$/, /Clas{2}/, /^.*TestCase.*$/, /^Unknown1/, /Unknown2/]
100
+ actual.matched_keys.sort_by {|x| x.to_s}.should == expected_found_types.sort_by {|x| x.to_s}
101
+ actual.not_matched_keys.sort.should == expected_unfound_exps.sort
102
+ end
103
+
104
+ it "should find types with :: namespace delimiters using their names." do
105
+ expected_found_types = [Outside::Inside1, Outside::Inside2]
106
+ expected_unfound_exps = %w[Foo::Bar::Baz]
107
+ actual = Aquarium::Finders::TypeFinder.new.find :names => (expected_found_types.map {|t| t.to_s} + expected_unfound_exps)
108
+ actual.matched_keys.sort_by {|x| x.to_s}.should == expected_found_types.sort_by {|x| x.to_s}
109
+ actual.not_matched_keys.sort.should == expected_unfound_exps.sort
110
+ end
111
+
112
+ it "should find types with :: namespace delimiters using lists of regular expressions." do
113
+ expected_found_types = [Outside::Inside1, Outside::Inside2]
114
+ expected_unfound_exps = [/^.*Fo+::.*Bar+::Baz.$/]
115
+ actual = Aquarium::Finders::TypeFinder.new.find :types => [/^.*Fo+::.*Bar+::Baz.$/, /Outside::.*1$/, "Out.*::In.*2"]
116
+ actual.matched_keys.sort_by {|x| x.to_s}.should == expected_found_types.sort_by {|x| x.to_s}
117
+ actual.not_matched_keys.should == expected_unfound_exps
118
+ end
119
+ end
120
+
121
+ describe Aquarium::Finders::TypeFinder, "#find" do
122
+ it "should find types when types given." do
123
+ expected_found_types = [Outside::Inside1, Outside::Inside2]
124
+ actual = Aquarium::Finders::TypeFinder.new.find :names => expected_found_types
125
+ actual.matched_keys.sort_by {|x| x.to_s}.should == expected_found_types.sort_by {|x| x.to_s}
126
+ actual.not_matched_keys.should == []
127
+ end
128
+ end
129
+
130
+ describe Aquarium::Finders::TypeFinder, "#find_all_by" do
131
+ it "should find types with :: namespace delimiters using lists of regular expressions." do
132
+ expected_found_types = [Outside::Inside1, Outside::Inside2]
133
+ expected_unfound_exps = [/^.*Fo+::.*Bar+::Baz.$/]
134
+ actual = Aquarium::Finders::TypeFinder.new.find_all_by [/^.*Fo+::.*Bar+::Baz.$/, /Outside::.*1$/, "Out.*::In.*2"]
135
+ actual.matched_keys.sort_by {|x| x.to_s}.should == expected_found_types.sort_by {|x| x.to_s}
136
+ actual.not_matched_keys.should == expected_unfound_exps
137
+ end
138
+
139
+ it "should find types with :: namespace delimiters using their names." do
140
+ expected_found_types = [Outside::Inside1, Outside::Inside2]
141
+ expected_unfound_exps = %w[Foo::Bar::Baz]
142
+ actual = Aquarium::Finders::TypeFinder.new.find_all_by(expected_found_types.map {|t| t.to_s} + expected_unfound_exps)
143
+ actual.matched_keys.sort_by {|x| x.to_s}.should == expected_found_types.sort_by {|x| x.to_s}
144
+ actual.not_matched_keys.should == expected_unfound_exps
145
+ end
146
+
147
+ it "should find types when types given." do
148
+ expected_found_types = [Outside::Inside1, Outside::Inside2]
149
+ actual = Aquarium::Finders::TypeFinder.new.find_all_by expected_found_types
150
+ actual.matched_keys.sort_by {|x| x.to_s}.should == expected_found_types.sort_by {|x| x.to_s}
151
+ actual.not_matched_keys.should == []
152
+ end
153
+ end
154
+
155
+ describe Aquarium::Finders::TypeFinder, "#find_by_name" do
156
+ it "should find a single type when given a single type name." do
157
+ tf = Aquarium::Finders::TypeFinder.new
158
+ actual = tf.find_by_name("String")
159
+ actual.matched_keys.should == [String]
160
+ actual.not_matched_keys.should == []
161
+ actual = tf.find_by_name("Kernel")
162
+ actual.matched_keys.should == [Kernel]
163
+ actual.not_matched_keys.should == []
164
+ actual = tf.find_by_name("Module")
165
+ actual.matched_keys.should == [Module]
166
+ actual.not_matched_keys.should == []
167
+ end
168
+
169
+ it "should find a single type when given a valid type name with :: separators." do
170
+ tf = Aquarium::Finders::TypeFinder.new
171
+ actual = tf.find_by_name "Outside::Inside1"
172
+ actual.matched_keys.should == [Outside::Inside1]
173
+ actual.not_matched_keys.should == []
174
+ end
175
+
176
+ it "should find a single type when given that type." do
177
+ tf = Aquarium::Finders::TypeFinder.new
178
+ actual = tf.find_by_name Outside::Inside1
179
+ actual.matched_keys.should == [Outside::Inside1]
180
+ actual.not_matched_keys.should == []
181
+ end
182
+
183
+ it "should return no matches if the type can't be found." do
184
+ tf = Aquarium::Finders::TypeFinder.new
185
+ actual = tf.find_by_name "UnknownClass1::UnknownClass2"
186
+ actual.matched_keys.should == []
187
+ actual.not_matched_keys.should == ["UnknownClass1::UnknownClass2"]
188
+ end
189
+
190
+ it "should return no matches if the type name is invalid." do
191
+ tf = Aquarium::Finders::TypeFinder.new
192
+ actual = tf.find_by_name "$foo:bar"
193
+ actual.matched_keys.should == []
194
+ actual.not_matched_keys.should == ["$foo:bar"]
195
+ end
196
+ end
197
+
198
+ describe Aquarium::Finders::TypeFinder, "#find_by_type" do
199
+ it "is synonymous with find_by_name." do
200
+ tf = Aquarium::Finders::TypeFinder.new
201
+ actual = tf.find_by_name "Outside::Inside1"
202
+ actual.matched_keys.should == [Outside::Inside1]
203
+ actual.not_matched_keys.should == []
204
+ actual = tf.find_by_name Outside::Inside1
205
+ actual.matched_keys.should == [Outside::Inside1]
206
+ actual.not_matched_keys.should == []
207
+ end
208
+ end
209
+
210
+