jackbox 0.9.6.2
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.
- checksums.yaml +7 -0
- data/.yardopts +5 -0
- data/CHANGES.txt +108 -0
- data/LICENSE.lic +0 -0
- data/LICENSE.txt +13 -0
- data/README.md +1395 -0
- data/Rakefile +6 -0
- data/bin/jackup +248 -0
- data/jackbox.gemspec +27 -0
- data/jackbox.jpg +0 -0
- data/lib/.document +0 -0
- data/lib/jackbox.rb +2 -0
- data/lib/jackbox/examples/dir.rb +80 -0
- data/lib/jackbox/examples/dx.rb +182 -0
- data/lib/jackbox/examples/transformers.rb +101 -0
- data/lib/jackbox/injectors.rb +2 -0
- data/lib/jackbox/rake.rb +2 -0
- data/lib/jackbox/tools/prefs.rb +2 -0
- data/lib/jackbox/version.rb +4 -0
- data/rgloader/loader.rb +23 -0
- data/rgloader/rgloader.darwin.bundle +0 -0
- data/rgloader/rgloader.freebsd.so +0 -0
- data/rgloader/rgloader.freebsd.x86_64.so +0 -0
- data/rgloader/rgloader.linux.so +0 -0
- data/rgloader/rgloader.linux.x86_64.so +0 -0
- data/rgloader/rgloader.mingw.so +0 -0
- data/rgloader/rgloader19.darwin.bundle +0 -0
- data/rgloader/rgloader19.freebsd.so +0 -0
- data/rgloader/rgloader19.freebsd.x86_64.so +0 -0
- data/rgloader/rgloader19.linux.so +0 -0
- data/rgloader/rgloader19.linux.x86_64.so +0 -0
- data/rgloader/rgloader19.mingw.so +0 -0
- data/rgloader/rgloader191.mingw.so +0 -0
- data/rgloader/rgloader192.darwin.bundle +0 -0
- data/rgloader/rgloader192.freebsd.so +0 -0
- data/rgloader/rgloader192.freebsd.x86_64.so +0 -0
- data/rgloader/rgloader192.linux.so +0 -0
- data/rgloader/rgloader192.linux.x86_64.so +0 -0
- data/rgloader/rgloader192.mingw.so +0 -0
- data/rgloader/rgloader193.darwin.bundle +0 -0
- data/rgloader/rgloader193.freebsd.so +0 -0
- data/rgloader/rgloader193.freebsd.x86_64.so +0 -0
- data/rgloader/rgloader193.linux.so +0 -0
- data/rgloader/rgloader193.linux.x86_64.so +0 -0
- data/rgloader/rgloader193.mingw.so +0 -0
- data/rgloader/rgloader20.darwin.bundle +0 -0
- data/rgloader/rgloader20.freebsd.so +0 -0
- data/rgloader/rgloader20.freebsd.x86_64.so +0 -0
- data/rgloader/rgloader20.linux.so +0 -0
- data/rgloader/rgloader20.linux.x86_64.so +0 -0
- data/rgloader/rgloader20.mingw.so +0 -0
- data/rgloader/rgloader20.mingw.x64.so +0 -0
- data/rgloader/rgloader21.darwin.bundle +0 -0
- data/rgloader/rgloader21.freebsd.so +0 -0
- data/rgloader/rgloader21.freebsd.x86_64.so +0 -0
- data/rgloader/rgloader21.linux.so +0 -0
- data/rgloader/rgloader21.linux.x86_64.so +0 -0
- data/rgloader/rgloader21.mingw.so +0 -0
- data/rgloader/rgloader21.mingw.x64.so +0 -0
- data/rgloader/rgloader22.darwin.bundle +0 -0
- data/rgloader/rgloader22.freebsd.so +0 -0
- data/rgloader/rgloader22.linux.so +0 -0
- data/rgloader/rgloader22.linux.x86_64.so +0 -0
- data/rgloader/rgloader22.mingw.so +0 -0
- data/rgloader/rgloader22.mingw.x64.so +0 -0
- data/spec/bin/jackup_cmd_shared.rb +176 -0
- data/spec/bin/jackup_cmd_spec.rb +292 -0
- data/spec/lib/abtract_spec.rb +56 -0
- data/spec/lib/jackbox/examples/dir_spec.rb +112 -0
- data/spec/lib/jackbox/examples/dx_spec.rb +346 -0
- data/spec/lib/jackbox/examples/result.xml +15 -0
- data/spec/lib/jackbox/examples/source1.xml +11 -0
- data/spec/lib/jackbox/examples/source2.xml +15 -0
- data/spec/lib/jackbox/examples/source3.xml +11 -0
- data/spec/lib/jackbox/examples/trasnformers_spec.rb +35 -0
- data/spec/lib/jackbox/injector_composition_spec.rb +950 -0
- data/spec/lib/jackbox/injector_directives_spec.rb +266 -0
- data/spec/lib/jackbox/injector_inheritance_spec.rb +799 -0
- data/spec/lib/jackbox/injector_introspection_spec.rb +614 -0
- data/spec/lib/jackbox/injector_namespacing_spec.rb +345 -0
- data/spec/lib/jackbox/injector_spec.rb +847 -0
- data/spec/lib/jackbox/injector_versioning_spec.rb +334 -0
- data/spec/lib/jackbox/patterns_spec.rb +410 -0
- data/spec/lib/jackbox/prefs_spec.rb +212 -0
- data/spec/lib/jackbox/reclassing_spec.rb +394 -0
- data/spec/lib/jackbox_spec.rb +595 -0
- data/spec/spec_helper.rb +139 -0
- metadata +218 -0
@@ -0,0 +1,35 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "jackbox/examples/transformers"
|
3
|
+
|
4
|
+
$sources = [
|
5
|
+
REXML::Document.new(open('spec/lib/jackbox/examples/source1.xml')),
|
6
|
+
REXML::Document.new(open('spec/lib/jackbox/examples/source2.xml')),
|
7
|
+
REXML::Document.new(open('spec/lib/jackbox/examples/source3.xml'))
|
8
|
+
]
|
9
|
+
|
10
|
+
REXML::Document.new(open('spec/lib/jackbox/examples/result.xml')).write $xml = '', 1
|
11
|
+
|
12
|
+
describe "transformers" do
|
13
|
+
it 'uses this pattern to process xml' do
|
14
|
+
|
15
|
+
$sources.each { |so|
|
16
|
+
|
17
|
+
peeps = People.new
|
18
|
+
|
19
|
+
with Transformer().tags do
|
20
|
+
|
21
|
+
reverse_each { |v|
|
22
|
+
peeps.extend( v )
|
23
|
+
peeps.load(so)
|
24
|
+
break unless peeps.transform.empty?
|
25
|
+
}
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
peeps.to_xml.should == $xml
|
30
|
+
# puts so, peeps.to_xml, $xml
|
31
|
+
|
32
|
+
}
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,950 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
=begin rdoc
|
3
|
+
|
4
|
+
This file describes full blown injector composition and decomposition.
|
5
|
+
|
6
|
+
NOTE: Please note that some examples are purposefully long because of the long
|
7
|
+
process any given injector can undergo during program use. We are testing the
|
8
|
+
possible lifecycle of an injector in the course of a program.
|
9
|
+
|
10
|
+
=end
|
11
|
+
|
12
|
+
|
13
|
+
include Injectors
|
14
|
+
|
15
|
+
describe 'plyability of injection/ejection' do
|
16
|
+
|
17
|
+
describe 'a new form of mixin' do
|
18
|
+
|
19
|
+
before do
|
20
|
+
|
21
|
+
suppress_warnings do
|
22
|
+
A1 = Class.new
|
23
|
+
end
|
24
|
+
|
25
|
+
injector :j1 do
|
26
|
+
def j1m1
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
A1.inject j1
|
31
|
+
|
32
|
+
# define function
|
33
|
+
j1 do
|
34
|
+
def j1m2
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
after do
|
41
|
+
|
42
|
+
j1 :implode
|
43
|
+
|
44
|
+
suppress_warnings do
|
45
|
+
A1 = nil
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'morphs mixins to a new level' do
|
51
|
+
|
52
|
+
a1 = A1.new
|
53
|
+
|
54
|
+
# instance has injectors of class
|
55
|
+
a1.injectors.sym_list.should == [:j1]
|
56
|
+
|
57
|
+
a1.j1m1.should == nil # no errors on call
|
58
|
+
a1.j1m2.should == nil # no errors on call
|
59
|
+
|
60
|
+
# eject the class injector for this object only
|
61
|
+
a1.eject j1
|
62
|
+
|
63
|
+
a1.injectors.sym_list.should == []
|
64
|
+
A1.injectors.sym_list.should == [:j1]
|
65
|
+
|
66
|
+
# expect errors on object
|
67
|
+
expect{ a1.j1m1 }.to raise_error(NoMethodError)
|
68
|
+
expect{ a1.j1m2 }.to raise_error(NoMethodError)
|
69
|
+
|
70
|
+
# class#new still the same
|
71
|
+
A1.new.j1m1.should == nil # no errors
|
72
|
+
A1.new.j1m2.should == nil # no errors
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'all fails after class ejection' do
|
77
|
+
|
78
|
+
a1 = A1.new
|
79
|
+
|
80
|
+
# eject function from the entire class
|
81
|
+
A1.eject j1
|
82
|
+
|
83
|
+
A1.injectors.sym_list.should == []
|
84
|
+
|
85
|
+
# expect all these errors
|
86
|
+
expect{ a1.j1m1 }.to raise_error(NoMethodError)
|
87
|
+
expect{ a1.j1m2 }.to raise_error(NoMethodError)
|
88
|
+
expect{ A1.new.j1m1 }.to raise_error(NoMethodError)
|
89
|
+
expect{ A1.new.j1m2 }.to raise_error(NoMethodError)
|
90
|
+
expect{ A1.eject j1 }.to raise_error(ArgumentError) # no more injectors
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'regains function on individula object through enrichment' do
|
95
|
+
|
96
|
+
a1 = A1.new
|
97
|
+
|
98
|
+
# eject function from the entire class
|
99
|
+
A1.eject j1
|
100
|
+
|
101
|
+
A1.injectors.sym_list.should == [] # like above
|
102
|
+
|
103
|
+
# enrich the individual object
|
104
|
+
a1.enrich j1
|
105
|
+
A1.injectors.sym_list.should == [] # still
|
106
|
+
a1.injectors.sym_list.should == [:j1]
|
107
|
+
|
108
|
+
# regain object function
|
109
|
+
a1.j1m1.should == nil # no errors
|
110
|
+
a1.j1m2.should == nil # no errors
|
111
|
+
|
112
|
+
# class#new still errors
|
113
|
+
expect{ A1.new.j1m1 }.to raise_error(NoMethodError)
|
114
|
+
expect{ A1.new.j1m2 }.to raise_error(NoMethodError)
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'fails again on individual object ejection' do
|
119
|
+
|
120
|
+
a1 = A1.new
|
121
|
+
|
122
|
+
# eject function from the entire class
|
123
|
+
A1.eject j1
|
124
|
+
|
125
|
+
A1.injectors.sym_list.should == [] # like above
|
126
|
+
|
127
|
+
# enrich the individual object
|
128
|
+
a1.enrich j1
|
129
|
+
|
130
|
+
a1.injectors.sym_list.should == [:j1] # like above
|
131
|
+
|
132
|
+
# eject back out
|
133
|
+
a1.eject j1
|
134
|
+
|
135
|
+
a1.injectors.sym_list.should == []
|
136
|
+
A1.injectors.sym_list.should == [] # still
|
137
|
+
|
138
|
+
# expect all errors
|
139
|
+
expect{ a1.j1m1 }.to raise_error(NoMethodError)
|
140
|
+
expect{ a1.j1m2 }.to raise_error(NoMethodError)
|
141
|
+
expect{ A1.new.j1m1 }.to raise_error(NoMethodError)
|
142
|
+
expect{ A1.new.j1m2 }.to raise_error(NoMethodError)
|
143
|
+
expect{ a1.eject j1 }.to raise_error(ArgumentError) # no more injectors
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
it 'regains all function on class injection' do
|
148
|
+
|
149
|
+
a1 = A1.new
|
150
|
+
|
151
|
+
# eject function from the entire class
|
152
|
+
A1.eject j1
|
153
|
+
|
154
|
+
A1.injectors.sym_list.should == [] # like above
|
155
|
+
|
156
|
+
# enrich the individual object
|
157
|
+
a1.enrich j1
|
158
|
+
|
159
|
+
a1.injectors.sym_list.should == [:j1] # like above
|
160
|
+
|
161
|
+
# eject back out
|
162
|
+
a1.eject j1
|
163
|
+
|
164
|
+
a1.injectors.sym_list.should == [] # like above
|
165
|
+
|
166
|
+
# re-inject the entire class
|
167
|
+
A1.inject j1
|
168
|
+
|
169
|
+
A1.injectors.sym_list.should == [:j1]
|
170
|
+
a1.injectors.sym_list.should == [:j1]
|
171
|
+
|
172
|
+
# no errors
|
173
|
+
a1.j1m1.should == nil
|
174
|
+
a1.j1m2.should == nil
|
175
|
+
A1.new.j1m1.should == nil # no errors
|
176
|
+
A1.new.j1m2.should == nil # no errors
|
177
|
+
|
178
|
+
end
|
179
|
+
|
180
|
+
it 'fails on class injection if the premise of class ejection is not met' do
|
181
|
+
|
182
|
+
a1 = A1.new
|
183
|
+
|
184
|
+
# eject class injector from just this object again
|
185
|
+
a1.eject j1
|
186
|
+
|
187
|
+
A1.injectors.sym_list.should == [:j1] # like above
|
188
|
+
a1.injectors.sym_list.should == []
|
189
|
+
|
190
|
+
# expect errors fo object
|
191
|
+
expect{ a1.j1m1 }.to raise_error(NoMethodError)
|
192
|
+
expect{ a1.j1m2 }.to raise_error(NoMethodError)
|
193
|
+
expect{ a1.eject j1 }.to raise_error(ArgumentError)
|
194
|
+
|
195
|
+
# no errors for new objects of the class # no class ejection at any point
|
196
|
+
A1.new.j1m1.should == nil # no errors
|
197
|
+
A1.new.j1m2.should == nil # no errors
|
198
|
+
|
199
|
+
# re-inject once again
|
200
|
+
A1.inject j1 # this re-injection does not take effect
|
201
|
+
|
202
|
+
A1.injectors.sym_list.should == [:j1]
|
203
|
+
a1.injectors.sym_list.should == [] # still ejected at object
|
204
|
+
|
205
|
+
# expect errors
|
206
|
+
expect{ a1.j1m1 }.to raise_error(NoMethodError)
|
207
|
+
expect{ a1.j1m2 }.to raise_error(NoMethodError)
|
208
|
+
expect{ a1.eject j1 }.to raise_error(ArgumentError)
|
209
|
+
|
210
|
+
# class update
|
211
|
+
A1.send :update, j1 # only Class #update OVERRIDES OBJECT-LEVEL EJECTIONS!!
|
212
|
+
A1.injectors.sym_list.should == [:j1] # (or object level injection) like above
|
213
|
+
a1.injectors.sym_list.should == [:j1]
|
214
|
+
|
215
|
+
# working once again
|
216
|
+
a1.j1m1.should == nil
|
217
|
+
a1.j1m2.should == nil
|
218
|
+
|
219
|
+
end
|
220
|
+
|
221
|
+
end
|
222
|
+
|
223
|
+
describe "some special cases" do
|
224
|
+
|
225
|
+
before do
|
226
|
+
|
227
|
+
suppress_warnings do
|
228
|
+
A2 = Class.new
|
229
|
+
end
|
230
|
+
|
231
|
+
injector :j2 do
|
232
|
+
def meth
|
233
|
+
:meth
|
234
|
+
end
|
235
|
+
end
|
236
|
+
injector :j3 do
|
237
|
+
def meth
|
238
|
+
:method
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
A2.inject j2, j3
|
243
|
+
|
244
|
+
end
|
245
|
+
|
246
|
+
after do
|
247
|
+
|
248
|
+
suppress_warnings do
|
249
|
+
A2 = nil
|
250
|
+
end
|
251
|
+
j2 :implode
|
252
|
+
j3 :implode
|
253
|
+
|
254
|
+
end
|
255
|
+
|
256
|
+
it 'does cover this case' do
|
257
|
+
|
258
|
+
# same name methods on different entities
|
259
|
+
|
260
|
+
a2 = A2.new
|
261
|
+
|
262
|
+
A2.injectors.sym_list.should == [:j2, :j3]
|
263
|
+
a2.injectors.sym_list.should == [:j2, :j3]
|
264
|
+
|
265
|
+
a2.meth.should == :method
|
266
|
+
|
267
|
+
A2.eject j3
|
268
|
+
|
269
|
+
a2.meth.should == :meth
|
270
|
+
|
271
|
+
A2.inject j3
|
272
|
+
|
273
|
+
a2.meth.should == :method
|
274
|
+
|
275
|
+
A2.eject j2
|
276
|
+
|
277
|
+
a2.meth.should == :method
|
278
|
+
|
279
|
+
A2.eject j3
|
280
|
+
|
281
|
+
expect{a2.meth}.to raise_error(NoMethodError)
|
282
|
+
expect{A2.eject j3}.to raise_error(ArgumentError)
|
283
|
+
|
284
|
+
end
|
285
|
+
|
286
|
+
it 'also covers this case' do
|
287
|
+
|
288
|
+
# the same thing but ejected at the object level
|
289
|
+
|
290
|
+
a3 = A2.new
|
291
|
+
|
292
|
+
a3.meth.should == :method
|
293
|
+
|
294
|
+
a3.eject j3
|
295
|
+
a3.meth.should == :meth
|
296
|
+
|
297
|
+
A2.inject j3 # no Class #update NO CHANGE
|
298
|
+
a3.meth.should == :meth
|
299
|
+
|
300
|
+
a3.enrich j3
|
301
|
+
a3.meth.should == :method
|
302
|
+
|
303
|
+
a3.eject j3
|
304
|
+
a3.meth.should == :meth
|
305
|
+
|
306
|
+
A2.send :update, j3
|
307
|
+
|
308
|
+
a3.injectors.sym_list.should == [:j2, :j3] # gets inverted
|
309
|
+
a3.meth.should == :method
|
310
|
+
|
311
|
+
a3.eject j3
|
312
|
+
|
313
|
+
a3.meth.should == :meth
|
314
|
+
expect{a3.eject j3}.to raise_error(ArgumentError)
|
315
|
+
|
316
|
+
a3.eject j2
|
317
|
+
|
318
|
+
a3. injectors.should == []
|
319
|
+
expect{a3.meth}.to raise_error(NoMethodError)
|
320
|
+
|
321
|
+
end
|
322
|
+
end
|
323
|
+
|
324
|
+
it 'errors out when no more injectors to eject' do
|
325
|
+
|
326
|
+
Ejected = injector :ejected
|
327
|
+
|
328
|
+
class EjectionTester
|
329
|
+
inject Ejected
|
330
|
+
end
|
331
|
+
|
332
|
+
x = EjectionTester.new
|
333
|
+
x.injectors.sym_list.should == [:ejected]
|
334
|
+
|
335
|
+
x.extend Ejected
|
336
|
+
x.injectors.sym_list.should == [:ejected, :ejected]
|
337
|
+
|
338
|
+
x.eject Ejected
|
339
|
+
x.injectors.sym_list.should == [:ejected]
|
340
|
+
x.eject ejected
|
341
|
+
x.injectors.sym_list.should == []
|
342
|
+
|
343
|
+
# debugger
|
344
|
+
expect{
|
345
|
+
x.eject Ejected
|
346
|
+
}.to raise_error(ArgumentError)
|
347
|
+
|
348
|
+
EjectionTester.injectors.sym_list.should == [:ejected]
|
349
|
+
EjectionTester.eject ejected
|
350
|
+
EjectionTester.injectors.sym_list.should == []
|
351
|
+
|
352
|
+
expect{
|
353
|
+
EjectionTester.eject Ejected
|
354
|
+
}.to raise_error(ArgumentError)
|
355
|
+
|
356
|
+
end
|
357
|
+
|
358
|
+
end
|
359
|
+
|
360
|
+
|
361
|
+
|
362
|
+
#
|
363
|
+
# declare injectors
|
364
|
+
#
|
365
|
+
injector :FuelSystem
|
366
|
+
injector :Engines
|
367
|
+
injector :Capsule
|
368
|
+
injector :Landing
|
369
|
+
|
370
|
+
|
371
|
+
#
|
372
|
+
# compose the object
|
373
|
+
#
|
374
|
+
class SpaceShip
|
375
|
+
|
376
|
+
inject FuelSystem(), Engines(), Capsule(), Landing()
|
377
|
+
|
378
|
+
def launch
|
379
|
+
gas_tank fuel_lines burners ignition :go
|
380
|
+
self
|
381
|
+
end
|
382
|
+
end
|
383
|
+
|
384
|
+
|
385
|
+
describe 'multiple injector composition and decomposition' do
|
386
|
+
|
387
|
+
# define functionality
|
388
|
+
FuelSystem do
|
389
|
+
def gas_tank arg
|
390
|
+
:gas
|
391
|
+
end
|
392
|
+
|
393
|
+
def fuel_lines arg
|
394
|
+
:fuel
|
395
|
+
end
|
396
|
+
|
397
|
+
def burners arg
|
398
|
+
:metal
|
399
|
+
end
|
400
|
+
end
|
401
|
+
|
402
|
+
# further define function
|
403
|
+
Engines do
|
404
|
+
def ignition arg
|
405
|
+
:spark
|
406
|
+
end
|
407
|
+
end
|
408
|
+
|
409
|
+
# create object
|
410
|
+
sat = SpaceShip.new.launch
|
411
|
+
# sat = subject.new.launch
|
412
|
+
|
413
|
+
# in flight definitions, ha ha!!
|
414
|
+
Capsule do
|
415
|
+
def o2
|
416
|
+
:oxigen
|
417
|
+
end
|
418
|
+
def hydration
|
419
|
+
:water
|
420
|
+
end
|
421
|
+
end
|
422
|
+
|
423
|
+
# more inflight definitions
|
424
|
+
var = 'wheels'
|
425
|
+
Landing do
|
426
|
+
define_method :gear do
|
427
|
+
var
|
428
|
+
end
|
429
|
+
end
|
430
|
+
|
431
|
+
the 'domain is specified as follows' do
|
432
|
+
|
433
|
+
#####
|
434
|
+
# 0. Nornal operation
|
435
|
+
SpaceShip.injectors.sym_list.should == [:FuelSystem, :Engines, :Capsule, :Landing]
|
436
|
+
sat.injectors.sym_list.should == [:FuelSystem, :Engines, :Capsule, :Landing]
|
437
|
+
sat.fuel_lines( :on ).should == :fuel
|
438
|
+
sat.ignition( :on ).should == :spark
|
439
|
+
sat.o2.should == :oxigen
|
440
|
+
sat.gear.should == 'wheels'
|
441
|
+
|
442
|
+
#####
|
443
|
+
# 1. eject class level injector at the object level
|
444
|
+
sat.eject :Capsule
|
445
|
+
|
446
|
+
# expect errors
|
447
|
+
SpaceShip.injectors.sym_list.should == [:FuelSystem, :Engines, :Capsule, :Landing]
|
448
|
+
sat.injectors.sym_list.should == [:FuelSystem, :Engines, :Landing]
|
449
|
+
expect{sat.o2}.to raise_error(NoMethodError)
|
450
|
+
sat.fuel_lines( :good ).should == :fuel
|
451
|
+
sat.ignition( :on ).should == :spark
|
452
|
+
sat.gear.should == 'wheels'
|
453
|
+
|
454
|
+
#####
|
455
|
+
# 2. eject 2nd class level injector at the object level
|
456
|
+
sat.eject :Engines
|
457
|
+
|
458
|
+
# expect more errors
|
459
|
+
SpaceShip.injectors.sym_list.should == [:FuelSystem, :Engines, :Capsule, :Landing]
|
460
|
+
sat.injectors.sym_list.should == [:FuelSystem, :Landing]
|
461
|
+
expect{sat.o2}.to raise_error(NoMethodError)
|
462
|
+
expect{sat.ignition :on}.to raise_error(NoMethodError)
|
463
|
+
sat.fuel_lines( :good ).should == :fuel
|
464
|
+
sat.gear.should == 'wheels'
|
465
|
+
|
466
|
+
#####
|
467
|
+
# 3. launch a second vessel
|
468
|
+
flyer = SpaceShip.new.launch
|
469
|
+
|
470
|
+
# should have normal config
|
471
|
+
SpaceShip.injectors.sym_list.should == [:FuelSystem, :Engines, :Capsule, :Landing]
|
472
|
+
flyer.injectors.sym_list.should == [:FuelSystem, :Engines, :Capsule, :Landing]
|
473
|
+
flyer.fuel_lines( :on ).should == :fuel
|
474
|
+
flyer.ignition( :on ).should == :spark
|
475
|
+
flyer.o2.should == :oxigen
|
476
|
+
|
477
|
+
# sat is still cripled
|
478
|
+
sat.injectors.sym_list.should == [:FuelSystem, :Landing]
|
479
|
+
sat.fuel_lines( :good ).should == :fuel
|
480
|
+
expect{sat.ignition :on}.to raise_error(NoMethodError)
|
481
|
+
expect{sat.o2}.to raise_error(NoMethodError)
|
482
|
+
sat.gear.should == 'wheels'
|
483
|
+
|
484
|
+
#####
|
485
|
+
# 4. re-inject sat with Capsule
|
486
|
+
sat.enrich Capsule() # object level re-injection
|
487
|
+
|
488
|
+
# sat regains some function
|
489
|
+
SpaceShip.injectors.sym_list.should == [:FuelSystem, :Engines, :Capsule, :Landing]
|
490
|
+
sat.injectors.sym_list.should == [:FuelSystem, :Landing, :Capsule]
|
491
|
+
sat.o2.should == :oxigen
|
492
|
+
sat.fuel_lines( :good ).should == :fuel
|
493
|
+
sat.gear.should == 'wheels'
|
494
|
+
|
495
|
+
# sat ignition still failing
|
496
|
+
expect{sat.ignition :on}.to raise_error(NoMethodError)
|
497
|
+
|
498
|
+
# flyer normal
|
499
|
+
flyer.injectors.sym_list.should == [:FuelSystem, :Engines, :Capsule, :Landing]
|
500
|
+
flyer.ignition( :on ).should == :spark
|
501
|
+
flyer.fuel_lines( :on ).should == :fuel
|
502
|
+
flyer.o2.should == :oxigen
|
503
|
+
flyer.gear.should == 'wheels'
|
504
|
+
|
505
|
+
#####
|
506
|
+
# 5. Class Level ejection: from Ground control
|
507
|
+
SpaceShip.eject :Capsule
|
508
|
+
SpaceShip.injectors.sym_list.should == [:FuelSystem, :Engines, :Landing]
|
509
|
+
|
510
|
+
# class level ejection: affects objects of the class
|
511
|
+
# that have not been re-injected at the object level
|
512
|
+
|
513
|
+
# flyer is now affected
|
514
|
+
flyer.injectors.sym_list.should == [:FuelSystem, :Engines, :Landing]
|
515
|
+
expect{flyer.o2}.to raise_error(NoMethodError)
|
516
|
+
flyer.ignition( :on ).should == :spark
|
517
|
+
flyer.fuel_lines( :on ).should == :fuel
|
518
|
+
flyer.gear.should == 'wheels'
|
519
|
+
|
520
|
+
# sat not affected because previously enriched at the object level
|
521
|
+
sat.injectors.sym_list.should == [:FuelSystem, :Landing, :Capsule]
|
522
|
+
sat.o2.should == :oxigen
|
523
|
+
sat.fuel_lines( :good ).should == :fuel
|
524
|
+
sat.gear.should == 'wheels'
|
525
|
+
expect{sat.ignition :on}.to raise_error(NoMethodError)
|
526
|
+
|
527
|
+
#####
|
528
|
+
# 6. 2nd Class Level ejection from Ground Control
|
529
|
+
SpaceShip.eject :FuelSystem
|
530
|
+
SpaceShip.injectors.sym_list.should == [:Engines, :Landing]
|
531
|
+
|
532
|
+
# sat affected
|
533
|
+
sat.injectors.sym_list.should == [:Landing, :Capsule]
|
534
|
+
expect{sat.ignition :on}.to raise_error(NoMethodError)
|
535
|
+
expect{sat.fuel_lines :off}.to raise_error(NoMethodError)
|
536
|
+
sat.o2.should == :oxigen
|
537
|
+
sat.gear.should == 'wheels'
|
538
|
+
|
539
|
+
# flyer affected
|
540
|
+
flyer.injectors.sym_list.should == [:Engines, :Landing]
|
541
|
+
expect{flyer.fuel_lines :on}.to raise_error(NoMethodError)
|
542
|
+
expect{flyer.o2}.to raise_error(NoMethodError)
|
543
|
+
flyer.ignition( :on ).should == :spark
|
544
|
+
flyer.gear.should == 'wheels'
|
545
|
+
|
546
|
+
#####
|
547
|
+
# 7. 2nd vessel gets aided by aliens
|
548
|
+
flyer.enrich FuelSystem() # object level re-injection
|
549
|
+
|
550
|
+
# regains some function
|
551
|
+
SpaceShip.injectors.sym_list.should == [:Engines, :Landing]
|
552
|
+
flyer.injectors.sym_list.should == [:Engines, :Landing, :FuelSystem]
|
553
|
+
flyer.fuel_lines( :on ).should == :fuel
|
554
|
+
flyer.ignition( :on ).should == :spark
|
555
|
+
flyer.gear.should == 'wheels'
|
556
|
+
|
557
|
+
# o2 still failing
|
558
|
+
expect{flyer.o2}.to raise_error(NoMethodError)
|
559
|
+
|
560
|
+
# first vessel still same failures
|
561
|
+
sat.injectors.sym_list.should == [:Landing, :Capsule]
|
562
|
+
expect{sat.ignition :on}.to raise_error(NoMethodError)
|
563
|
+
expect{sat.fuel_lines :on}.to raise_error(NoMethodError)
|
564
|
+
sat.o2.should == :oxigen
|
565
|
+
sat.gear.should == 'wheels'
|
566
|
+
|
567
|
+
#####
|
568
|
+
# 8. flyer vessel gets aided by aliens a second time
|
569
|
+
flyer.enrich Capsule() # object level re-injection
|
570
|
+
|
571
|
+
# regains all function
|
572
|
+
SpaceShip.injectors.sym_list.should == [:Engines, :Landing]
|
573
|
+
flyer.injectors.sym_list.should == [:Engines, :Landing, :FuelSystem, :Capsule]
|
574
|
+
flyer.fuel_lines( :on ).should == :fuel
|
575
|
+
flyer.ignition( :on ).should == :spark
|
576
|
+
flyer.o2.should == :oxigen
|
577
|
+
flyer.gear.should == 'wheels'
|
578
|
+
|
579
|
+
# sat vessel still same failures
|
580
|
+
sat.injectors.sym_list.should == [:Landing, :Capsule]
|
581
|
+
expect{sat.ignition :on}.to raise_error(NoMethodError)
|
582
|
+
expect{sat.fuel_lines :on}.to raise_error(NoMethodError)
|
583
|
+
sat.o2.should == :oxigen
|
584
|
+
sat.gear.should == 'wheels'
|
585
|
+
|
586
|
+
#####
|
587
|
+
# 9. sat vessel looses capsule
|
588
|
+
sat.eject :Capsule # object level ejection
|
589
|
+
|
590
|
+
# flyer vessel un-affected
|
591
|
+
SpaceShip.injectors.sym_list.should == [:Engines, :Landing]
|
592
|
+
sat.injectors.sym_list.should == [:Landing]
|
593
|
+
flyer.injectors.sym_list.should == [:Engines, :Landing, :FuelSystem, :Capsule]
|
594
|
+
flyer.fuel_lines( :on ).should == :fuel
|
595
|
+
flyer.ignition( :on ).should == :spark
|
596
|
+
flyer.o2.should == :oxigen
|
597
|
+
flyer.gear.should == 'wheels'
|
598
|
+
|
599
|
+
# sat vessel can only land
|
600
|
+
expect{sat.fuel_lines :on}.to raise_error(NoMethodError)
|
601
|
+
expect{sat.ignition :on}.to raise_error(NoMethodError)
|
602
|
+
expect{sat.o2}.to raise_error(NoMethodError)
|
603
|
+
sat.gear.should == 'wheels'
|
604
|
+
|
605
|
+
#####
|
606
|
+
# 10. Class Level injection from Ground Control
|
607
|
+
SpaceShip.inject FuelSystem()
|
608
|
+
SpaceShip.injectors.sym_list.should == [:Engines, :Landing, :FuelSystem]
|
609
|
+
|
610
|
+
# class level re-injection: affects all objects
|
611
|
+
# even if they have been re-injected at the object level
|
612
|
+
|
613
|
+
# sat vessel regains some function
|
614
|
+
sat.injectors.sym_list.should == [:Landing, :FuelSystem]
|
615
|
+
sat.fuel_lines( :on ).should == :fuel
|
616
|
+
sat.gear.should == 'wheels'
|
617
|
+
|
618
|
+
# but still errors
|
619
|
+
expect{sat.ignition :off}.to raise_error(NoMethodError)
|
620
|
+
expect{sat.hydration}.to raise_error(NoMethodError)
|
621
|
+
|
622
|
+
# flyer vessel gains a backup!
|
623
|
+
flyer.injectors.sym_list.should == [:Engines, :Landing, :FuelSystem, :FuelSystem, :Capsule]
|
624
|
+
flyer.ignition( :on ).should == :spark
|
625
|
+
flyer.gas_tank( :full ).should == :gas
|
626
|
+
flyer.hydration.should == :water
|
627
|
+
flyer.gear.should == 'wheels'
|
628
|
+
|
629
|
+
#####
|
630
|
+
# Injector directives
|
631
|
+
FuelSystem(:collapse)
|
632
|
+
SpaceShip.injectors.sym_list.should == [:Engines, :Landing, :FuelSystem]
|
633
|
+
|
634
|
+
# First vessel: fuel system is inoperative, everything else the same
|
635
|
+
sat.injectors.sym_list.should == [:Landing, :FuelSystem]
|
636
|
+
sat.fuel_lines( :on ).should == nil
|
637
|
+
expect{sat.ignition :off}.to raise_error(NoMethodError)
|
638
|
+
expect{sat.hydration}.to raise_error(NoMethodError)
|
639
|
+
sat.gear.should == 'wheels'
|
640
|
+
|
641
|
+
# Second vessel: fuel system also inoperative, the rest same
|
642
|
+
flyer.injectors.sym_list.should == [:Engines, :Landing, :FuelSystem, :FuelSystem, :Capsule]
|
643
|
+
flyer.gas_tank(:full).should == nil
|
644
|
+
flyer.ignition( :on )
|
645
|
+
flyer.hydration.should == :water
|
646
|
+
flyer.gear.should == 'wheels'
|
647
|
+
|
648
|
+
#####
|
649
|
+
# second directive
|
650
|
+
FuelSystem(:rebuild)
|
651
|
+
|
652
|
+
# everything back to previous state
|
653
|
+
SpaceShip.injectors.sym_list.should == [:Engines, :Landing, :FuelSystem]
|
654
|
+
sat.injectors.sym_list.should == [:Landing, :FuelSystem]
|
655
|
+
sat.fuel_lines( :on ).should == :fuel
|
656
|
+
sat.gear.should == 'wheels'
|
657
|
+
expect{sat.ignition :off}.to raise_error(NoMethodError)
|
658
|
+
expect{sat.hydration}.to raise_error(NoMethodError)
|
659
|
+
flyer.injectors.sym_list.should == [:Engines, :Landing, :FuelSystem, :FuelSystem, :Capsule]
|
660
|
+
flyer.gas_tank(:full).should == :gas
|
661
|
+
flyer.ignition( :on ).should == :spark
|
662
|
+
flyer.hydration.should == :water
|
663
|
+
flyer.gear.should == 'wheels'
|
664
|
+
|
665
|
+
end
|
666
|
+
|
667
|
+
it 'co-exists with method_missing on classes/modules' do
|
668
|
+
|
669
|
+
# writing method_missing in conjunction with injector use
|
670
|
+
class SpaceShip
|
671
|
+
def method_missing sym, *args, &code # done on the class
|
672
|
+
if sym == :crash
|
673
|
+
:booohoooo
|
674
|
+
# ... do your stuff here
|
675
|
+
else
|
676
|
+
super(sym, *args, &code)
|
677
|
+
end
|
678
|
+
end
|
679
|
+
end
|
680
|
+
|
681
|
+
SpaceShip.injectors.sym_list.should == [:Engines, :Landing, :FuelSystem]
|
682
|
+
sat.injectors.sym_list.should == [:Landing, :FuelSystem]
|
683
|
+
sat.crash.should == :booohoooo
|
684
|
+
sat.fuel_lines( :on ).should == :fuel
|
685
|
+
expect{sat.ignition :off}.to raise_error(NoMethodError)
|
686
|
+
expect{sat.hydration}.to raise_error(NoMethodError)
|
687
|
+
sat.gear.should == 'wheels'
|
688
|
+
|
689
|
+
|
690
|
+
module CrashAndBurn
|
691
|
+
def method_missing sym, *args, &code # done on a separate module
|
692
|
+
if sym == :crash_and_burn
|
693
|
+
"look ma' no teeth"
|
694
|
+
else
|
695
|
+
super(sym, *args, &code)
|
696
|
+
end
|
697
|
+
end
|
698
|
+
end
|
699
|
+
|
700
|
+
class SpaceShip
|
701
|
+
include CrashAndBurn
|
702
|
+
end
|
703
|
+
|
704
|
+
sat.crash_and_burn.should == "look ma' no teeth"
|
705
|
+
|
706
|
+
#####
|
707
|
+
# Done on the injector
|
708
|
+
# . cannot be done at the injector level
|
709
|
+
injector :Pilot do
|
710
|
+
def automatic
|
711
|
+
'auto pilot'
|
712
|
+
end
|
713
|
+
def method_missing sym, *args, &code # THIS NEVER EXECUTES!!!
|
714
|
+
'Going dauwn...'
|
715
|
+
end
|
716
|
+
end
|
717
|
+
|
718
|
+
# object level injection: no go!
|
719
|
+
sat.enrich Pilot()
|
720
|
+
|
721
|
+
SpaceShip.injectors.sym_list.should == [:Engines, :Landing, :FuelSystem]
|
722
|
+
sat.injectors.sym_list.should == [:Landing, :FuelSystem, :Pilot]
|
723
|
+
sat.automatic.should == 'auto pilot'
|
724
|
+
expect{sat.noMethod.should == 'Going dauwn...' }.to raise_error(NoMethodError)
|
725
|
+
sat.fuel_lines( :on ).should == :fuel
|
726
|
+
expect{sat.ignition :off}.to raise_error(NoMethodError)
|
727
|
+
expect{sat.hydration}.to raise_error(NoMethodError)
|
728
|
+
sat.gear.should == 'wheels'
|
729
|
+
|
730
|
+
# class level injection: no go!
|
731
|
+
SpaceShip.inject Pilot()
|
732
|
+
|
733
|
+
SpaceShip.injectors.sym_list.should == [:Engines, :Landing, :FuelSystem, :Pilot]
|
734
|
+
sat.injectors.sym_list.should == [:Landing, :FuelSystem, :Pilot, :Pilot]
|
735
|
+
sat.automatic.should == 'auto pilot'
|
736
|
+
expect{sat.noMethod.should == 'Going dauwn...' }.to raise_error(NoMethodError)
|
737
|
+
sat.fuel_lines( :on ).should == :fuel
|
738
|
+
expect{sat.ignition :off}.to raise_error(NoMethodError)
|
739
|
+
expect{sat.hydration}.to raise_error(NoMethodError)
|
740
|
+
sat.gear.should == 'wheels'
|
741
|
+
|
742
|
+
#####
|
743
|
+
# Un-affected by directives
|
744
|
+
Pilot(:silence)
|
745
|
+
|
746
|
+
SpaceShip.injectors.sym_list.should == [:Engines, :Landing, :FuelSystem, :Pilot]
|
747
|
+
sat.injectors.sym_list.should == [:Landing, :FuelSystem, :Pilot, :Pilot]
|
748
|
+
sat.automatic.should == nil
|
749
|
+
sat.fuel_lines( :on ).should == :fuel
|
750
|
+
expect{sat.ignition :off}.to raise_error(NoMethodError)
|
751
|
+
expect{sat.hydration}.to raise_error(NoMethodError)
|
752
|
+
sat.gear.should == 'wheels'
|
753
|
+
|
754
|
+
expect{sat.boohoo}.to raise_error(NoMethodError)
|
755
|
+
expect{flyer.boohoo}.to raise_error(NameError)
|
756
|
+
|
757
|
+
#####
|
758
|
+
# Un-affected by directives
|
759
|
+
Pilot(:rebuild)
|
760
|
+
|
761
|
+
SpaceShip.injectors.sym_list.should == [:Engines, :Landing, :FuelSystem, :Pilot]
|
762
|
+
sat.injectors.sym_list.should == [:Landing, :FuelSystem, :Pilot, :Pilot]
|
763
|
+
sat.automatic.should == 'auto pilot'
|
764
|
+
sat.fuel_lines( :on ).should == :fuel
|
765
|
+
expect{sat.ignition :off}.to raise_error(NoMethodError)
|
766
|
+
expect{sat.hydration}.to raise_error(NoMethodError)
|
767
|
+
sat.gear.should == 'wheels'
|
768
|
+
|
769
|
+
expect{sat.boohoo}.to raise_error(NoMethodError)
|
770
|
+
expect{flyer.boohoo}.to raise_error(NameError)
|
771
|
+
|
772
|
+
end
|
773
|
+
|
774
|
+
describe 'standard inclusion/extension aspects' do
|
775
|
+
|
776
|
+
it 'works with included/extended callbacks' do
|
777
|
+
|
778
|
+
$stdout.should_receive(:puts).with('++++++++--------------++++++++++').twice()
|
779
|
+
|
780
|
+
SS = injector :StarShipFunction do
|
781
|
+
|
782
|
+
def phaser
|
783
|
+
'_+_+_+_+_+_+'
|
784
|
+
end
|
785
|
+
|
786
|
+
def neutron_torpedoes
|
787
|
+
'---ooooOOOO()()()'
|
788
|
+
end
|
789
|
+
|
790
|
+
def self.included host
|
791
|
+
puts '++++++++--------------++++++++++'
|
792
|
+
host.class_eval {
|
793
|
+
def warp_speed
|
794
|
+
end
|
795
|
+
}
|
796
|
+
end
|
797
|
+
|
798
|
+
def self.extended host
|
799
|
+
puts '++++++++--------------++++++++++'
|
800
|
+
host.instance_eval {
|
801
|
+
def link_to_ships
|
802
|
+
|
803
|
+
end
|
804
|
+
}
|
805
|
+
|
806
|
+
end
|
807
|
+
end
|
808
|
+
|
809
|
+
class Airplane
|
810
|
+
inject SS
|
811
|
+
end
|
812
|
+
expect{
|
813
|
+
|
814
|
+
Airplane.new.warp_speed
|
815
|
+
Airplane.new.neutron_torpedoes.should == '---ooooOOOO()()()'
|
816
|
+
|
817
|
+
}.to_not raise_error
|
818
|
+
|
819
|
+
|
820
|
+
class Building
|
821
|
+
extend SS
|
822
|
+
end
|
823
|
+
expect{
|
824
|
+
|
825
|
+
Building.link_to_ships
|
826
|
+
|
827
|
+
}.to_not raise_error
|
828
|
+
|
829
|
+
end
|
830
|
+
|
831
|
+
it 'does not interfere for module inclusion and extension' do
|
832
|
+
|
833
|
+
expect{
|
834
|
+
|
835
|
+
module AB
|
836
|
+
def meth
|
837
|
+
end
|
838
|
+
end
|
839
|
+
|
840
|
+
module BA
|
841
|
+
include AB
|
842
|
+
def mith
|
843
|
+
end
|
844
|
+
end
|
845
|
+
|
846
|
+
class Base
|
847
|
+
include BA
|
848
|
+
def moth
|
849
|
+
end
|
850
|
+
end
|
851
|
+
|
852
|
+
Base.new.meth
|
853
|
+
Base.new.mith
|
854
|
+
Base.new.moth
|
855
|
+
|
856
|
+
class Second
|
857
|
+
def math
|
858
|
+
end
|
859
|
+
end
|
860
|
+
|
861
|
+
Second.new.extend(BA).mith
|
862
|
+
Second.new.extend(BA).meth
|
863
|
+
|
864
|
+
}.to_not raise_error
|
865
|
+
|
866
|
+
end
|
867
|
+
|
868
|
+
it 'raises cyclic inclusion on module self inclusion' do
|
869
|
+
|
870
|
+
expect{
|
871
|
+
module AC
|
872
|
+
def foo
|
873
|
+
end
|
874
|
+
include self
|
875
|
+
end
|
876
|
+
}.to raise_error(ArgumentError)
|
877
|
+
|
878
|
+
end
|
879
|
+
|
880
|
+
it 'does the same for Injector self inclusion' do
|
881
|
+
|
882
|
+
expect{
|
883
|
+
|
884
|
+
injector :Includer
|
885
|
+
|
886
|
+
Includer do
|
887
|
+
def far
|
888
|
+
end
|
889
|
+
inject self
|
890
|
+
end
|
891
|
+
|
892
|
+
}.to raise_error(ArgumentError)
|
893
|
+
|
894
|
+
end
|
895
|
+
|
896
|
+
it "does work this way however" do
|
897
|
+
|
898
|
+
expect{
|
899
|
+
|
900
|
+
injector :Includer
|
901
|
+
|
902
|
+
Includer do
|
903
|
+
def far
|
904
|
+
end
|
905
|
+
inject Includer() # this includes a new copy of the original
|
906
|
+
end
|
907
|
+
|
908
|
+
}.to_not raise_error()
|
909
|
+
|
910
|
+
end
|
911
|
+
|
912
|
+
end
|
913
|
+
|
914
|
+
end
|
915
|
+
|
916
|
+
########################################################################################
|
917
|
+
# If you want to run these examples: you must have a debugger for your version of Ruby
|
918
|
+
# ** You must uncomment the DX line in spec_helper **
|
919
|
+
# #####################################################################################
|
920
|
+
|
921
|
+
# require 'jackbox/examples/dx'
|
922
|
+
# describe DX, 'the debugger extras makes use of another capability of injectors to just completely
|
923
|
+
# collapse leaving the method calls inplace but ejecting the actual funtion out of them' do
|
924
|
+
#
|
925
|
+
# describe 'ability to break into debugger' do
|
926
|
+
# # after(:all) { load "../../lib/tools/dx.rb"}
|
927
|
+
# it 'has a method to break into debugger mode' do
|
928
|
+
# DX.should_receive :debug
|
929
|
+
# DX.debug
|
930
|
+
# end
|
931
|
+
# it 'can break into the debugger on exception' do
|
932
|
+
# DX.should_receive :debug
|
933
|
+
# DX.seize TypeError
|
934
|
+
# expect{String.new 3}.to raise_error
|
935
|
+
# end
|
936
|
+
# the 'call to #collapse leaves the methods inplace but silent. There are no
|
937
|
+
# NoMethodError exceptions raised the programm proceeds but the DX function has been removed.
|
938
|
+
# See the #rebuild method' do
|
939
|
+
# DX.logger :collapse
|
940
|
+
# DX.splatter :collapse
|
941
|
+
#
|
942
|
+
# DX.debug # nothing happens
|
943
|
+
# DX.seize Exception # nothing happens
|
944
|
+
# DX.assert_loaded.should == nil
|
945
|
+
# DX.log("boo").should == nil
|
946
|
+
# DX.syslog("baa").should == nil
|
947
|
+
# end
|
948
|
+
# end
|
949
|
+
# end
|
950
|
+
|