module-cluster 1.4.1 → 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,419 @@
1
+
2
+ require_relative '../../../../../lib/module-cluster.rb'
3
+
4
+ describe ModuleCluster::ClusterStack::Set::MultiSetProxy do
5
+
6
+ ###########
7
+ # name= #
8
+ # name #
9
+ ###########
10
+
11
+ it 'can set the name of each member set and retrieve the names of each member set' do
12
+ module ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock01
13
+ end
14
+ module ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock02
15
+ end
16
+ set_one = ModuleCluster::ClusterStack::Set.new( ModuleCluster::Define::Cluster, :include_also_includes, :all, :include, [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock01 ], nil )
17
+ set_two = ModuleCluster::ClusterStack::Set.new( ModuleCluster::Define::Cluster, :include_also_includes, :all, :include, [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock02 ], nil )
18
+ set_one.name = :some_name
19
+ set_two.name = :some_other_name
20
+ multi_set = ModuleCluster::ClusterStack::Set::MultiSetProxy.new( set_one, set_two )
21
+ multi_set.name.should == [ :some_name, :some_other_name ]
22
+ multi_set.name = :yet_another_other_name
23
+ multi_set.name.should == [ :yet_another_other_name, :yet_another_other_name ]
24
+ # also make sure it works nested in another MultiSetProxy
25
+ module ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock03
26
+ end
27
+ module ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock04
28
+ end
29
+ set_three = ModuleCluster::ClusterStack::Set.new( ModuleCluster::Define::Cluster, :include_also_includes, :all, :include, [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock03 ], nil )
30
+ set_four = ModuleCluster::ClusterStack::Set.new( ModuleCluster::Define::Cluster, :include_also_includes, :all, :include, [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock04 ], nil )
31
+ set_three.name = :some_name
32
+ set_four.name = :some_other_name
33
+ multi_set_two = ModuleCluster::ClusterStack::Set::MultiSetProxy.new( set_three, set_four )
34
+ multi_multi_set = ModuleCluster::ClusterStack::Set::MultiSetProxy.new( multi_set, multi_set_two )
35
+ multi_multi_set.name.should == [ :yet_another_other_name, :yet_another_other_name, :some_name, :some_other_name ]
36
+ end
37
+
38
+ ########################
39
+ # dependency_module= #
40
+ # dependency_module #
41
+ ########################
42
+
43
+ it 'can set the dependecy module of each member set and retrieve the dependency module of each member set' do
44
+ module ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock01
45
+ end
46
+ module ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock02
47
+ end
48
+ module ModuleCluster::ClusterStack::Set::MultiSetProxy::DependencyModuleMock01
49
+ end
50
+ set_one = ModuleCluster::ClusterStack::Set.new( ModuleCluster::Define::Cluster, :include_also_includes, :all, :include, [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock01 ], nil )
51
+ set_two = ModuleCluster::ClusterStack::Set.new( ModuleCluster::Define::Cluster, :include_also_includes, :all, :include, [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock02 ], nil )
52
+ multi_set = ModuleCluster::ClusterStack::Set::MultiSetProxy.new( set_one, set_two )
53
+ multi_set.dependency_module.should == [ ModuleCluster::Define::Cluster, ModuleCluster::Define::Cluster ]
54
+ multi_set.dependency_module = ModuleCluster::ClusterStack::Set::MultiSetProxy::DependencyModuleMock01
55
+ multi_set.dependency_module.should == [ ModuleCluster::ClusterStack::Set::MultiSetProxy::DependencyModuleMock01, ModuleCluster::ClusterStack::Set::MultiSetProxy::DependencyModuleMock01 ]
56
+ # also make sure it works nested in another MultiSetProxy
57
+ module ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock03
58
+ end
59
+ module ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock04
60
+ end
61
+ set_three = ModuleCluster::ClusterStack::Set.new( ModuleCluster::Define::Cluster, :include_also_includes, :all, :include, [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock03 ], nil )
62
+ set_four = ModuleCluster::ClusterStack::Set.new( ModuleCluster::Define::Cluster, :include_also_includes, :all, :include, [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock04 ], nil )
63
+ set_three.name = :some_name
64
+ set_four.name = :some_other_name
65
+ multi_set_two = ModuleCluster::ClusterStack::Set::MultiSetProxy.new( set_three, set_four )
66
+ multi_multi_set = ModuleCluster::ClusterStack::Set::MultiSetProxy.new( multi_set, multi_set_two )
67
+ multi_multi_set.dependency_module.should == [ ModuleCluster::ClusterStack::Set::MultiSetProxy::DependencyModuleMock01, ModuleCluster::ClusterStack::Set::MultiSetProxy::DependencyModuleMock01, ModuleCluster::Define::Cluster, ModuleCluster::Define::Cluster ]
68
+ end
69
+
70
+ #############
71
+ # method= #
72
+ # method #
73
+ #############
74
+
75
+ it 'can set the method of each member set and retrieve the methods of each member set' do
76
+ module ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock01
77
+ end
78
+ module ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock02
79
+ end
80
+ set_one = ModuleCluster::ClusterStack::Set.new( ModuleCluster::Define::Cluster, :include_also_includes, :all, :include, [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock01 ], nil )
81
+ set_two = ModuleCluster::ClusterStack::Set.new( ModuleCluster::Define::Cluster, :include_also_includes, :all, :include, [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock02 ], nil )
82
+ multi_set = ModuleCluster::ClusterStack::Set::MultiSetProxy.new( set_one, set_two )
83
+ multi_set.method.should == [ :include_also_includes, :include_also_includes ]
84
+ multi_set.method = :some_other_method
85
+ multi_set.method.should == [ :some_other_method, :some_other_method ]
86
+ # also make sure it works nested in another MultiSetProxy
87
+ module ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock03
88
+ end
89
+ module ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock04
90
+ end
91
+ set_three = ModuleCluster::ClusterStack::Set.new( ModuleCluster::Define::Cluster, :include_also_includes, :all, :include, [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock03 ], nil )
92
+ set_four = ModuleCluster::ClusterStack::Set.new( ModuleCluster::Define::Cluster, :include_also_includes, :all, :include, [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock04 ], nil )
93
+ set_three.name = :some_name
94
+ set_four.name = :some_other_name
95
+ multi_set_two = ModuleCluster::ClusterStack::Set::MultiSetProxy.new( set_three, set_four )
96
+ multi_multi_set = ModuleCluster::ClusterStack::Set::MultiSetProxy.new( multi_set, multi_set_two )
97
+ multi_multi_set.method.should == [ :some_other_method, :some_other_method, :include_also_includes, :include_also_includes ]
98
+ end
99
+
100
+ ###################################
101
+ # module_class_instance_or_all= #
102
+ # module_class_instance_or_all #
103
+ ###################################
104
+
105
+ it 'can set the object to which set applies for each member set and retrieve the objects to which sets apply for all member sets' do
106
+ module ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock01
107
+ end
108
+ module ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock02
109
+ end
110
+ set_one = ModuleCluster::ClusterStack::Set.new( ModuleCluster::Define::Cluster, :include_also_includes, :all, :include, [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock01 ], nil )
111
+ set_two = ModuleCluster::ClusterStack::Set.new( ModuleCluster::Define::Cluster, :include_also_includes, :all, :include, [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock02 ], nil )
112
+ multi_set = ModuleCluster::ClusterStack::Set::MultiSetProxy.new( set_one, set_two )
113
+ multi_set.module_class_instance_or_all.should == [ :all, :all ]
114
+ multi_set.module_class_instance_or_all = :module
115
+ multi_set.module_class_instance_or_all.should == [ :module, :module ]
116
+ # also make sure it works nested in another MultiSetProxy
117
+ module ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock03
118
+ end
119
+ module ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock04
120
+ end
121
+ set_three = ModuleCluster::ClusterStack::Set.new( ModuleCluster::Define::Cluster, :include_also_includes, :all, :include, [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock03 ], nil )
122
+ set_four = ModuleCluster::ClusterStack::Set.new( ModuleCluster::Define::Cluster, :include_also_includes, :all, :include, [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock04 ], nil )
123
+ set_three.name = :some_name
124
+ set_four.name = :some_other_name
125
+ multi_set_two = ModuleCluster::ClusterStack::Set::MultiSetProxy.new( set_three, set_four )
126
+ multi_multi_set = ModuleCluster::ClusterStack::Set::MultiSetProxy.new( multi_set, multi_set_two )
127
+ multi_multi_set.module_class_instance_or_all.should == [ :module, :module, :all, :all ]
128
+ end
129
+
130
+ ########################
131
+ # include_or_extend= #
132
+ # include_or_extend #
133
+ ########################
134
+
135
+ it 'can set whether set should be used to include, extend, or both and retrieve whether member sets are to be included, extended, or both' do
136
+ module ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock01
137
+ end
138
+ module ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock02
139
+ end
140
+ set_one = ModuleCluster::ClusterStack::Set.new( ModuleCluster::Define::Cluster, :include_also_includes, :all, :include, [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock01 ], nil )
141
+ set_two = ModuleCluster::ClusterStack::Set.new( ModuleCluster::Define::Cluster, :include_also_includes, :all, :include, [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock02 ], nil )
142
+ multi_set = ModuleCluster::ClusterStack::Set::MultiSetProxy.new( set_one, set_two )
143
+ multi_set.include_or_extend.should == [ :include_also_includes, :include_also_includes ]
144
+ multi_set.include_or_extend = :module
145
+ multi_set.include_or_extend.should == [ :module, :module ]
146
+ # also make sure it works nested in another MultiSetProxy
147
+ module ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock03
148
+ end
149
+ module ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock04
150
+ end
151
+ set_three = ModuleCluster::ClusterStack::Set.new( ModuleCluster::Define::Cluster, :include_also_includes, :all, :include, [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock03 ], nil )
152
+ set_four = ModuleCluster::ClusterStack::Set.new( ModuleCluster::Define::Cluster, :include_also_includes, :all, :include, [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock04 ], nil )
153
+ set_three.name = :some_name
154
+ set_four.name = :some_other_name
155
+ multi_set_two = ModuleCluster::ClusterStack::Set::MultiSetProxy.new( set_three, set_four )
156
+ multi_multi_set = ModuleCluster::ClusterStack::Set::MultiSetProxy.new( multi_set, multi_set_two )
157
+ multi_multi_set.include_or_extend.should == [ :module, :module, :include_also_includes, :include_also_includes ]
158
+ end
159
+
160
+ ##############
161
+ # modules= #
162
+ # modules #
163
+ ##############
164
+
165
+ it 'can set the modules of each member set and retrieve the modules of each member set' do
166
+ module ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock01
167
+ end
168
+ module ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock02
169
+ end
170
+ set_one = ModuleCluster::ClusterStack::Set.new( ModuleCluster::Define::Cluster, :include_also_includes, :all, :include, [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock01 ], nil )
171
+ set_two = ModuleCluster::ClusterStack::Set.new( ModuleCluster::Define::Cluster, :include_also_includes, :all, :include, [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock02 ], nil )
172
+ multi_set = ModuleCluster::ClusterStack::Set::MultiSetProxy.new( set_one, set_two )
173
+ multi_set.modules.should == [ [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock01 ], [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock02 ] ]
174
+ multi_set.modules = [ Module ]
175
+ multi_set.modules.should == [ [ Module ], [ Module ] ]
176
+ # also make sure it works nested in another MultiSetProxy
177
+ module ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock03
178
+ end
179
+ module ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock04
180
+ end
181
+ set_three = ModuleCluster::ClusterStack::Set.new( ModuleCluster::Define::Cluster, :include_also_includes, :all, :include, [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock03 ], nil )
182
+ set_four = ModuleCluster::ClusterStack::Set.new( ModuleCluster::Define::Cluster, :include_also_includes, :all, :include, [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock04 ], nil )
183
+ set_three.name = :some_name
184
+ set_four.name = :some_other_name
185
+ multi_set_two = ModuleCluster::ClusterStack::Set::MultiSetProxy.new( set_three, set_four )
186
+ multi_multi_set = ModuleCluster::ClusterStack::Set::MultiSetProxy.new( multi_set, multi_set_two )
187
+ multi_multi_set.modules.should == [ [ Module ], [ Module ], [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock03 ], [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock04 ] ]
188
+ set_five = ModuleCluster::ClusterStack::Set.new( ModuleCluster::Define::Cluster, :include_also_includes, :all, :include, [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock03 ], nil )
189
+ multi_multi_set_two = ModuleCluster::ClusterStack::Set::MultiSetProxy.new( multi_multi_set, set_five )
190
+ multi_multi_set_two.modules.should == [ [ Module ], [ Module ], [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock03 ], [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock04 ], [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock03 ] ]
191
+ end
192
+
193
+ ########################################
194
+ # runtime_includes_or_extends_block= #
195
+ # runtime_includes_or_extends_block #
196
+ ########################################
197
+
198
+ it 'can set the block for runtime determination of modules for each member set and retrieve the block from each member set' do
199
+ module ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock01
200
+ end
201
+ module ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock02
202
+ end
203
+ runtime_block = Proc.new { Module }
204
+ set_one = ModuleCluster::ClusterStack::Set.new( ModuleCluster::Define::Cluster, :include_also_includes, :all, :include, [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock01 ], runtime_block )
205
+ set_two = ModuleCluster::ClusterStack::Set.new( ModuleCluster::Define::Cluster, :include_also_includes, :all, :include, [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock02 ], runtime_block )
206
+ multi_set = ModuleCluster::ClusterStack::Set::MultiSetProxy.new( set_one, set_two )
207
+ multi_set.runtime_includes_or_extends_block.should == [ runtime_block, runtime_block ]
208
+ other_block = Proc.new { Kernel }
209
+ multi_set.runtime_includes_or_extends_block = other_block
210
+ multi_set.runtime_includes_or_extends_block.should == [ other_block, other_block ]
211
+ # also make sure it works nested in another MultiSetProxy
212
+ module ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock03
213
+ end
214
+ module ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock04
215
+ end
216
+ set_three = ModuleCluster::ClusterStack::Set.new( ModuleCluster::Define::Cluster, :include_also_includes, :all, :include, [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock03 ], runtime_block )
217
+ set_four = ModuleCluster::ClusterStack::Set.new( ModuleCluster::Define::Cluster, :include_also_includes, :all, :include, [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock04 ], runtime_block )
218
+ set_three.name = :some_name
219
+ set_four.name = :some_other_name
220
+ multi_set_two = ModuleCluster::ClusterStack::Set::MultiSetProxy.new( set_three, set_four )
221
+ multi_multi_set = ModuleCluster::ClusterStack::Set::MultiSetProxy.new( multi_set, multi_set_two )
222
+ multi_multi_set.runtime_includes_or_extends_block.should == [ other_block, other_block, runtime_block, runtime_block ]
223
+ end
224
+
225
+ ################
226
+ # suspended= #
227
+ # suspended #
228
+ # suspend #
229
+ # suspended? #
230
+ # resume #
231
+ ################
232
+
233
+ it 'can suspend and resume each member set and retrieve whether member sets are suspended' do
234
+ module ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock01
235
+ end
236
+ module ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock02
237
+ end
238
+ set_one = ModuleCluster::ClusterStack::Set.new( ModuleCluster::Define::Cluster, :include_also_includes, :all, :include, [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock01 ], nil )
239
+ set_two = ModuleCluster::ClusterStack::Set.new( ModuleCluster::Define::Cluster, :include_also_includes, :all, :include, [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock02 ], nil )
240
+ multi_set = ModuleCluster::ClusterStack::Set::MultiSetProxy.new( set_one, set_two )
241
+ multi_set.suspended.should == [ false, false ]
242
+ multi_set.suspended?.should == [ false, false ]
243
+ multi_set.suspended = true
244
+ multi_set.suspended.should == [ true, true ]
245
+ multi_set.resume
246
+ multi_set.suspended.should == [ false, false ]
247
+ multi_set.suspend
248
+ multi_set.suspended.should == [ true, true ]
249
+ # also make sure it works nested in another MultiSetProxy
250
+ module ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock03
251
+ end
252
+ module ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock04
253
+ end
254
+ set_three = ModuleCluster::ClusterStack::Set.new( ModuleCluster::Define::Cluster, :include_also_includes, :all, :include, [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock03 ], nil )
255
+ set_four = ModuleCluster::ClusterStack::Set.new( ModuleCluster::Define::Cluster, :include_also_includes, :all, :include, [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock04 ], nil )
256
+ set_three.name = :some_name
257
+ set_four.name = :some_other_name
258
+ multi_set_two = ModuleCluster::ClusterStack::Set::MultiSetProxy.new( set_three, set_four )
259
+ multi_set_two.suspended.should == [ false, false ]
260
+ multi_multi_set = ModuleCluster::ClusterStack::Set::MultiSetProxy.new( multi_set, multi_set_two )
261
+ multi_multi_set.suspended?.should == [ true, true, false, false ]
262
+ end
263
+
264
+ ################
265
+ # hooks_with #
266
+ ################
267
+
268
+ it 'can return hooks in the set matching the description' do
269
+
270
+ module ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock01
271
+ end
272
+ module ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock02
273
+ end
274
+ block_one = Proc.new do
275
+ puts 'nothing'
276
+ end
277
+ block_two = Proc.new do
278
+ puts 'more nothing'
279
+ end
280
+ set_one = ModuleCluster::ClusterStack::Set.new( ModuleCluster::Define::Cluster, :include_also_includes, :all, :include, [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock01 ], block_one )
281
+ set_two = ModuleCluster::ClusterStack::Set.new( ModuleCluster::Define::Cluster, :include_also_includes, :instance, :extend, [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock02 ], block_two )
282
+ set_one.name = :name_one
283
+ set_two.name = :name_two_and_three
284
+ multi_set = ModuleCluster::ClusterStack::Set::MultiSetProxy.new( set_one, set_two )
285
+ multi_set.suspended.should == [ false, false ]
286
+ multi_set.suspended?.should == [ false, false ]
287
+ multi_set.suspended = true
288
+ multi_set.suspended.should == [ true, true ]
289
+ multi_set.resume
290
+ multi_set.suspended.should == [ false, false ]
291
+ multi_set.suspend
292
+ multi_set.suspended.should == [ true, true ]
293
+ # also make sure it works nested in another MultiSetProxy
294
+ module ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock03
295
+ end
296
+ module ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock04
297
+ end
298
+ block_four = Proc.new do
299
+ puts 'another nothing'
300
+ end
301
+ set_three = ModuleCluster::ClusterStack::Set.new( ModuleCluster::Define::Cluster, :include_also_includes, :class, :include_and_extend, [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock03 ], nil )
302
+ set_four = ModuleCluster::ClusterStack::Set.new( ModuleCluster::Define::Cluster, :include_also_includes, :module, :include, [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock04 ], block_four )
303
+ set_three.name = :name_two_and_three
304
+ set_four.name = :name_four
305
+ multi_set_two = ModuleCluster::ClusterStack::Set::MultiSetProxy.new( set_three, set_four )
306
+ multi_set_two.suspended.should == [ false, false ]
307
+ multi_multi_set = ModuleCluster::ClusterStack::Set::MultiSetProxy.new( multi_set, multi_set_two )
308
+
309
+ # dependency_module
310
+ multi_set.hooks_with( :dependency_module => ModuleCluster::Define::Cluster ).should == [ set_one, set_two ]
311
+ multi_set_two.hooks_with( :dependency_module => ModuleCluster::Define::Cluster ).should == [ set_three, set_four ]
312
+ multi_multi_set.hooks_with( :dependency_module => ModuleCluster::Define::Cluster ).should == [ set_one, set_two, set_three, set_four ]
313
+
314
+ # method
315
+ multi_set.hooks_with( :method => :include_also_includes ).should == [ set_one, set_two ]
316
+ multi_set_two.hooks_with( :method => :include_also_includes ).should == [ set_three, set_four ]
317
+ multi_multi_set.hooks_with( :method => :include_also_includes ).should == [ set_one, set_two, set_three, set_four ]
318
+
319
+ # module_class_instance_or_all
320
+ multi_set.hooks_with( :module_class_instance_or_all => :all ).should == [ set_one ]
321
+ multi_set.hooks_with( :module_class_instance_or_all => :instance ).should == [ set_one, set_two ]
322
+ multi_set_two.hooks_with( :module_class_instance_or_all => :class ).should == [ set_three ]
323
+ multi_multi_set.hooks_with( :module_class_instance_or_all => :module ).should == [ set_one, set_four ]
324
+
325
+ # include_or_extend
326
+ multi_set.hooks_with( :include_or_extend => :include ).should == [ set_one ]
327
+ multi_set.hooks_with( :include_or_extend => :extend ).should == [ set_two ]
328
+ multi_set_two.hooks_with( :include_or_extend => :include ).should == [ set_three, set_four ]
329
+ multi_multi_set.hooks_with( :include_or_extend => :extend ).should == [ set_two, set_three ]
330
+ multi_multi_set.hooks_with( :include_or_extend => :include ).should == [ set_one, set_three, set_four ]
331
+
332
+ # modules
333
+ multi_set.hooks_with( :modules => ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock01 ).should == [ set_one ]
334
+ multi_set.hooks_with( :modules => [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock02 ] ).should == [ set_two ]
335
+ multi_set_two.hooks_with( :modules => [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock03 ] ).should == [ set_three ]
336
+ multi_multi_set.hooks_with( :modules => ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock01 ).should == [ set_one ]
337
+ multi_multi_set.hooks_with( :modules => [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock04 ] ).should == [ set_four ]
338
+
339
+ # runtime_includes_or_extends_block
340
+ multi_set.hooks_with( :runtime_includes_or_extends_block => block_one ).should == [ set_one ]
341
+ multi_set.hooks_with( :runtime_includes_or_extends_block => block_two ).should == [ set_two ]
342
+ multi_set_two.hooks_with( :runtime_includes_or_extends_block => block_four ).should == [ set_four ]
343
+ multi_set_two.hooks_with( :runtime_includes_or_extends_block => nil ).should == [ set_three ]
344
+ multi_multi_set.hooks_with( :runtime_includes_or_extends_block => block_four ).should == [ set_four ]
345
+ multi_multi_set.hooks_with( :runtime_includes_or_extends_block => block_one ).should == [ set_one ]
346
+ multi_multi_set.hooks_with( :runtime_includes_or_extends_block => nil ).should == [ set_three ]
347
+
348
+ # suspended
349
+ multi_set.hooks_with( :suspended => false ).should == [ ]
350
+ multi_set.hooks_with( :suspended => true ).should == [ set_one, set_two ]
351
+ multi_set_two.hooks_with( :suspended => false ).should == [ set_three, set_four ]
352
+ multi_multi_set.hooks_with( :suspended => true ).should == [ set_one, set_two ]
353
+ multi_multi_set.hooks_with( :suspended => false ).should == [ set_three, set_four ]
354
+
355
+ # name
356
+ multi_set.hooks_with( :name => :name_one ).should == [ set_one ]
357
+ multi_set.hooks_with( :name => :name_two_and_three ).should == [ set_two ]
358
+ multi_set_two.hooks_with( :name => :name_two_and_three ).should == [ set_three ]
359
+ multi_multi_set.hooks_with( :name => :name_two_and_three ).should == [ set_two, set_three ]
360
+ multi_multi_set.hooks_with( :name => :name_four ).should == [ set_four ]
361
+
362
+ # we've ensured individual descriptions work, now we just need to make sure the logic loops
363
+ # since each works individually, if the loop works then any loop should work
364
+ #
365
+ # name x include_or_extend
366
+ multi_set.hooks_with( :name => :name_one,
367
+ :include_or_extend => :extend ).should == [ ]
368
+ multi_set.hooks_with( :name => :name_two_and_three,
369
+ :include_or_extend => :extend ).should == [ set_two ]
370
+ multi_set_two.hooks_with( :name => :name_two_and_three,
371
+ :include_or_extend => :include ).should == [ set_three ]
372
+ multi_multi_set.hooks_with( :name => :name_two_and_three,
373
+ :include_or_extend => :include ).should == [ set_three ]
374
+ multi_multi_set.hooks_with( :name => :name_four,
375
+ :include_or_extend => :include ).should == [ set_four ]
376
+
377
+ end
378
+
379
+ ###########
380
+ # hooks #
381
+ ###########
382
+
383
+ it 'can return a hook or set of hooks in set matching name' do
384
+
385
+ module ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock01
386
+ end
387
+ module ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock02
388
+ end
389
+ set_one = ModuleCluster::ClusterStack::Set.new( ModuleCluster::Define::Cluster, :include_also_includes, :all, :include, [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock01 ], nil )
390
+ set_two = ModuleCluster::ClusterStack::Set.new( ModuleCluster::Define::Cluster, :include_also_includes, :all, :include, [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock02 ], nil )
391
+ set_one.name = :some_name
392
+ set_two.name = :some_other_name
393
+ multi_set = ModuleCluster::ClusterStack::Set::MultiSetProxy.new( set_one, set_two )
394
+ multi_set.name.should == [ :some_name, :some_other_name ]
395
+ multi_set.name = :yet_another_other_name
396
+ multi_set.name.should == [ :yet_another_other_name, :yet_another_other_name ]
397
+ # also make sure it works nested in another MultiSetProxy
398
+ module ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock03
399
+ end
400
+ module ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock04
401
+ end
402
+ set_three = ModuleCluster::ClusterStack::Set.new( ModuleCluster::Define::Cluster, :include_also_includes, :all, :include, [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock03 ], nil )
403
+ set_four = ModuleCluster::ClusterStack::Set.new( ModuleCluster::Define::Cluster, :include_also_includes, :all, :include, [ ModuleCluster::ClusterStack::Set::MultiSetProxy::Mock04 ], nil )
404
+ set_three.name = :some_name
405
+ set_four.name = :some_other_name
406
+ multi_set_two = ModuleCluster::ClusterStack::Set::MultiSetProxy.new( set_three, set_four )
407
+ multi_multi_set = ModuleCluster::ClusterStack::Set::MultiSetProxy.new( multi_set, multi_set_two )
408
+ multi_multi_set.name.should == [ :yet_another_other_name, :yet_another_other_name, :some_name, :some_other_name ]
409
+
410
+ multi_set.hooks( :yet_another_other_name ).should == [ set_one, set_two ]
411
+ multi_set_two.hooks( :some_name ).should == [ set_three ]
412
+ multi_set_two.hooks( :some_other_name ).should == [ set_four ]
413
+ multi_multi_set.hooks( :yet_another_other_name ).should == [ set_one, set_two ]
414
+ multi_multi_set.hooks( :some_name ).should == [ set_three ]
415
+ multi_multi_set.hooks( :some_other_name ).should == [ set_four ]
416
+
417
+ end
418
+
419
+ end
@@ -0,0 +1,242 @@
1
+
2
+ require_relative '../../../../lib/module-cluster.rb'
3
+
4
+ describe ModuleCluster::ClusterStack::Suspend do
5
+
6
+ ##########################
7
+ # suspend_any_hooks #
8
+ # all_hooks_suspended? #
9
+ # resume_any_hooks #
10
+ ##########################
11
+
12
+ it 'can suspend all hooks at once' do
13
+ class ModuleCluster::ClusterStack::Suspend::Mock01
14
+ include ModuleCluster::ClusterStack::Suspend
15
+ end
16
+ instance = ModuleCluster::ClusterStack::Suspend::Mock01.new
17
+ instance.all_hooks_suspended?.should == false
18
+ instance.suspend_any_hooks
19
+ instance.all_hooks_suspended?.should == true
20
+ instance.all_include_hooks_suspended?.should == true
21
+ instance.all_extend_hooks_suspended?.should == true
22
+ instance.include_hooks_suspended?.should == true
23
+ instance.extend_hooks_suspended?.should == true
24
+ instance.prepend_include_hooks_suspended?.should == true
25
+ instance.prepend_extend_hooks_suspended?.should == true
26
+ instance.resume_any_hooks
27
+ instance.all_hooks_suspended?.should == false
28
+ end
29
+
30
+ ##################################
31
+ # suspend_any_include_hooks #
32
+ # all_include_hooks_suspended? #
33
+ # resume_any_include_hooks #
34
+ ##################################
35
+
36
+ it 'can suspend all include hooks at once' do
37
+ class ModuleCluster::ClusterStack::Suspend::Mock02
38
+ include ModuleCluster::ClusterStack::Suspend
39
+ end
40
+ instance = ModuleCluster::ClusterStack::Suspend::Mock02.new
41
+ instance.all_include_hooks_suspended?.should == false
42
+ instance.suspend_any_include_hooks
43
+ instance.all_include_hooks_suspended?.should == true
44
+ instance.include_hooks_suspended?.should == true
45
+ instance.prepend_include_hooks_suspended?.should == true
46
+ instance.all_hooks_suspended?.should == false
47
+ instance.all_extend_hooks_suspended?.should == false
48
+ instance.resume_any_include_hooks
49
+ instance.all_include_hooks_suspended?.should == false
50
+ end
51
+
52
+ #################################
53
+ # suspend_any_extend_hooks #
54
+ # all_extend_hooks_suspended? #
55
+ # resume_any_extend_hooks #
56
+ #################################
57
+
58
+ it 'can suspend all extend hooks at once' do
59
+ class ModuleCluster::ClusterStack::Suspend::Mock03
60
+ include ModuleCluster::ClusterStack::Suspend
61
+ end
62
+ instance = ModuleCluster::ClusterStack::Suspend::Mock03.new
63
+ instance.all_extend_hooks_suspended?.should == false
64
+ instance.suspend_any_extend_hooks
65
+ instance.all_extend_hooks_suspended?.should == true
66
+ instance.extend_hooks_suspended?.should == true
67
+ instance.prepend_extend_hooks_suspended?.should == true
68
+ instance.all_hooks_suspended?.should == false
69
+ instance.all_include_hooks_suspended?.should == false
70
+ instance.resume_any_extend_hooks
71
+ instance.all_extend_hooks_suspended?.should == false
72
+ end
73
+
74
+ ##############################
75
+ # suspend_include_hooks #
76
+ # include_hooks_suspended? #
77
+ # resume_include_hooks #
78
+ ##############################
79
+
80
+ it 'can suspend all include hooks' do
81
+ class ModuleCluster::ClusterStack::Suspend::Mock04
82
+ include ModuleCluster::ClusterStack::Suspend
83
+ end
84
+ instance = ModuleCluster::ClusterStack::Suspend::Mock04.new
85
+ instance.include_hooks_suspended?.should == false
86
+ instance.suspend_include_hooks
87
+ instance.include_hooks_suspended?.should == true
88
+ instance.all_hooks_suspended?.should == false
89
+ instance.all_include_hooks_suspended?.should == false
90
+ instance.all_extend_hooks_suspended?.should == false
91
+ instance.extend_hooks_suspended?.should == false
92
+ instance.prepend_include_hooks_suspended?.should == false
93
+ instance.prepend_extend_hooks_suspended?.should == false
94
+ instance.resume_include_hooks
95
+ instance.include_hooks_suspended?.should == false
96
+ end
97
+
98
+ #############################
99
+ # suspend_extend_hooks #
100
+ # extend_hooks_suspended? #
101
+ # resume_extend_hooks #
102
+ #############################
103
+
104
+ it 'can suspend all extend hooks' do
105
+ class ModuleCluster::ClusterStack::Suspend::Mock05
106
+ include ModuleCluster::ClusterStack::Suspend
107
+ end
108
+ instance = ModuleCluster::ClusterStack::Suspend::Mock05.new
109
+ instance.extend_hooks_suspended?.should == false
110
+ instance.suspend_extend_hooks
111
+ instance.extend_hooks_suspended?.should == true
112
+ instance.all_hooks_suspended?.should == false
113
+ instance.all_include_hooks_suspended?.should == false
114
+ instance.all_extend_hooks_suspended?.should == false
115
+ instance.include_hooks_suspended?.should == false
116
+ instance.prepend_include_hooks_suspended?.should == false
117
+ instance.prepend_extend_hooks_suspended?.should == false
118
+ instance.resume_extend_hooks
119
+ instance.extend_hooks_suspended?.should == false
120
+ end
121
+
122
+ ######################################
123
+ # suspend_prepend_include_hooks #
124
+ # prepend_include_hooks_suspended? #
125
+ # resume_prepend_include_hooks #
126
+ ######################################
127
+
128
+ it 'can suspend all prepend include hooks' do
129
+ class ModuleCluster::ClusterStack::Suspend::Mock06
130
+ include ModuleCluster::ClusterStack::Suspend
131
+ end
132
+ instance = ModuleCluster::ClusterStack::Suspend::Mock06.new
133
+ instance.prepend_include_hooks_suspended?.should == false
134
+ instance.suspend_prepend_include_hooks
135
+ instance.prepend_include_hooks_suspended?.should == true
136
+ instance.all_hooks_suspended?.should == false
137
+ instance.all_include_hooks_suspended?.should == false
138
+ instance.all_extend_hooks_suspended?.should == false
139
+ instance.include_hooks_suspended?.should == false
140
+ instance.extend_hooks_suspended?.should == false
141
+ instance.prepend_extend_hooks_suspended?.should == false
142
+ instance.resume_prepend_include_hooks
143
+ instance.prepend_include_hooks_suspended?.should == false
144
+ end
145
+
146
+ #####################################
147
+ # suspend_prepend_extend_hooks #
148
+ # prepend_extend_hooks_suspended? #
149
+ # resume_prepend_extend_hooks #
150
+ #####################################
151
+
152
+ it 'can suspend all prepend extend hooks' do
153
+ class ModuleCluster::ClusterStack::Suspend::Mock07
154
+ include ModuleCluster::ClusterStack::Suspend
155
+ end
156
+ instance = ModuleCluster::ClusterStack::Suspend::Mock07.new
157
+ instance.prepend_extend_hooks_suspended?.should == false
158
+ instance.suspend_prepend_extend_hooks
159
+ instance.prepend_extend_hooks_suspended?.should == true
160
+ instance.all_hooks_suspended?.should == false
161
+ instance.all_include_hooks_suspended?.should == false
162
+ instance.all_extend_hooks_suspended?.should == false
163
+ instance.include_hooks_suspended?.should == false
164
+ instance.extend_hooks_suspended?.should == false
165
+ instance.prepend_include_hooks_suspended?.should == false
166
+ instance.resume_prepend_extend_hooks
167
+ instance.prepend_extend_hooks_suspended?.should == false
168
+ end
169
+
170
+ ######################
171
+ # hooks_suspended? #
172
+ ######################
173
+
174
+ it 'can report whether hooks are extended for all of current action' do
175
+ class ModuleCluster::ClusterStack::Suspend::Mock08
176
+ include ModuleCluster::ClusterStack::Suspend
177
+ end
178
+ instance = ModuleCluster::ClusterStack::Suspend::Mock08.new
179
+ instance.hooks_suspended?( :prepend_include ).should == false
180
+ instance.hooks_suspended?( :include ).should == false
181
+ instance.hooks_suspended?( :prepend_extend ).should == false
182
+ instance.hooks_suspended?( :extend ).should == false
183
+
184
+ # suspend all
185
+ instance.suspend_any_hooks
186
+ instance.hooks_suspended?( :prepend_include ).should == true
187
+ instance.hooks_suspended?( :include ).should == true
188
+ instance.hooks_suspended?( :prepend_extend ).should == true
189
+ instance.hooks_suspended?( :extend ).should == true
190
+ instance.resume_any_hooks
191
+
192
+ # suspend all include
193
+ instance.suspend_any_include_hooks
194
+ instance.hooks_suspended?( :prepend_include ).should == true
195
+ instance.hooks_suspended?( :include ).should == true
196
+ instance.hooks_suspended?( :prepend_extend ).should == false
197
+ instance.hooks_suspended?( :extend ).should == false
198
+ instance.resume_any_include_hooks
199
+
200
+ # suspend all extend
201
+ instance.suspend_any_extend_hooks
202
+ instance.hooks_suspended?( :prepend_include ).should == false
203
+ instance.hooks_suspended?( :include ).should == false
204
+ instance.hooks_suspended?( :prepend_extend ).should == true
205
+ instance.hooks_suspended?( :extend ).should == true
206
+ instance.resume_any_extend_hooks
207
+
208
+ # suspend prepend include
209
+ instance.suspend_prepend_include_hooks
210
+ instance.hooks_suspended?( :prepend_include ).should == true
211
+ instance.hooks_suspended?( :include ).should == false
212
+ instance.hooks_suspended?( :prepend_extend ).should == false
213
+ instance.hooks_suspended?( :extend ).should == false
214
+ instance.resume_prepend_include_hooks
215
+
216
+ # suspend include
217
+ instance.suspend_include_hooks
218
+ instance.hooks_suspended?( :prepend_include ).should == false
219
+ instance.hooks_suspended?( :include ).should == true
220
+ instance.hooks_suspended?( :prepend_extend ).should == false
221
+ instance.hooks_suspended?( :extend ).should == false
222
+ instance.resume_include_hooks
223
+
224
+ # suspend prepend extend
225
+ instance.suspend_prepend_extend_hooks
226
+ instance.hooks_suspended?( :prepend_include ).should == false
227
+ instance.hooks_suspended?( :include ).should == false
228
+ instance.hooks_suspended?( :prepend_extend ).should == true
229
+ instance.hooks_suspended?( :extend ).should == false
230
+ instance.resume_prepend_extend_hooks
231
+
232
+ # suspend extend
233
+ instance.suspend_extend_hooks
234
+ instance.hooks_suspended?( :prepend_include ).should == false
235
+ instance.hooks_suspended?( :include ).should == false
236
+ instance.hooks_suspended?( :prepend_extend ).should == false
237
+ instance.hooks_suspended?( :extend ).should == true
238
+ instance.resume_extend_hooks
239
+
240
+ end
241
+
242
+ end