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.
Files changed (88) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +5 -0
  3. data/CHANGES.txt +108 -0
  4. data/LICENSE.lic +0 -0
  5. data/LICENSE.txt +13 -0
  6. data/README.md +1395 -0
  7. data/Rakefile +6 -0
  8. data/bin/jackup +248 -0
  9. data/jackbox.gemspec +27 -0
  10. data/jackbox.jpg +0 -0
  11. data/lib/.document +0 -0
  12. data/lib/jackbox.rb +2 -0
  13. data/lib/jackbox/examples/dir.rb +80 -0
  14. data/lib/jackbox/examples/dx.rb +182 -0
  15. data/lib/jackbox/examples/transformers.rb +101 -0
  16. data/lib/jackbox/injectors.rb +2 -0
  17. data/lib/jackbox/rake.rb +2 -0
  18. data/lib/jackbox/tools/prefs.rb +2 -0
  19. data/lib/jackbox/version.rb +4 -0
  20. data/rgloader/loader.rb +23 -0
  21. data/rgloader/rgloader.darwin.bundle +0 -0
  22. data/rgloader/rgloader.freebsd.so +0 -0
  23. data/rgloader/rgloader.freebsd.x86_64.so +0 -0
  24. data/rgloader/rgloader.linux.so +0 -0
  25. data/rgloader/rgloader.linux.x86_64.so +0 -0
  26. data/rgloader/rgloader.mingw.so +0 -0
  27. data/rgloader/rgloader19.darwin.bundle +0 -0
  28. data/rgloader/rgloader19.freebsd.so +0 -0
  29. data/rgloader/rgloader19.freebsd.x86_64.so +0 -0
  30. data/rgloader/rgloader19.linux.so +0 -0
  31. data/rgloader/rgloader19.linux.x86_64.so +0 -0
  32. data/rgloader/rgloader19.mingw.so +0 -0
  33. data/rgloader/rgloader191.mingw.so +0 -0
  34. data/rgloader/rgloader192.darwin.bundle +0 -0
  35. data/rgloader/rgloader192.freebsd.so +0 -0
  36. data/rgloader/rgloader192.freebsd.x86_64.so +0 -0
  37. data/rgloader/rgloader192.linux.so +0 -0
  38. data/rgloader/rgloader192.linux.x86_64.so +0 -0
  39. data/rgloader/rgloader192.mingw.so +0 -0
  40. data/rgloader/rgloader193.darwin.bundle +0 -0
  41. data/rgloader/rgloader193.freebsd.so +0 -0
  42. data/rgloader/rgloader193.freebsd.x86_64.so +0 -0
  43. data/rgloader/rgloader193.linux.so +0 -0
  44. data/rgloader/rgloader193.linux.x86_64.so +0 -0
  45. data/rgloader/rgloader193.mingw.so +0 -0
  46. data/rgloader/rgloader20.darwin.bundle +0 -0
  47. data/rgloader/rgloader20.freebsd.so +0 -0
  48. data/rgloader/rgloader20.freebsd.x86_64.so +0 -0
  49. data/rgloader/rgloader20.linux.so +0 -0
  50. data/rgloader/rgloader20.linux.x86_64.so +0 -0
  51. data/rgloader/rgloader20.mingw.so +0 -0
  52. data/rgloader/rgloader20.mingw.x64.so +0 -0
  53. data/rgloader/rgloader21.darwin.bundle +0 -0
  54. data/rgloader/rgloader21.freebsd.so +0 -0
  55. data/rgloader/rgloader21.freebsd.x86_64.so +0 -0
  56. data/rgloader/rgloader21.linux.so +0 -0
  57. data/rgloader/rgloader21.linux.x86_64.so +0 -0
  58. data/rgloader/rgloader21.mingw.so +0 -0
  59. data/rgloader/rgloader21.mingw.x64.so +0 -0
  60. data/rgloader/rgloader22.darwin.bundle +0 -0
  61. data/rgloader/rgloader22.freebsd.so +0 -0
  62. data/rgloader/rgloader22.linux.so +0 -0
  63. data/rgloader/rgloader22.linux.x86_64.so +0 -0
  64. data/rgloader/rgloader22.mingw.so +0 -0
  65. data/rgloader/rgloader22.mingw.x64.so +0 -0
  66. data/spec/bin/jackup_cmd_shared.rb +176 -0
  67. data/spec/bin/jackup_cmd_spec.rb +292 -0
  68. data/spec/lib/abtract_spec.rb +56 -0
  69. data/spec/lib/jackbox/examples/dir_spec.rb +112 -0
  70. data/spec/lib/jackbox/examples/dx_spec.rb +346 -0
  71. data/spec/lib/jackbox/examples/result.xml +15 -0
  72. data/spec/lib/jackbox/examples/source1.xml +11 -0
  73. data/spec/lib/jackbox/examples/source2.xml +15 -0
  74. data/spec/lib/jackbox/examples/source3.xml +11 -0
  75. data/spec/lib/jackbox/examples/trasnformers_spec.rb +35 -0
  76. data/spec/lib/jackbox/injector_composition_spec.rb +950 -0
  77. data/spec/lib/jackbox/injector_directives_spec.rb +266 -0
  78. data/spec/lib/jackbox/injector_inheritance_spec.rb +799 -0
  79. data/spec/lib/jackbox/injector_introspection_spec.rb +614 -0
  80. data/spec/lib/jackbox/injector_namespacing_spec.rb +345 -0
  81. data/spec/lib/jackbox/injector_spec.rb +847 -0
  82. data/spec/lib/jackbox/injector_versioning_spec.rb +334 -0
  83. data/spec/lib/jackbox/patterns_spec.rb +410 -0
  84. data/spec/lib/jackbox/prefs_spec.rb +212 -0
  85. data/spec/lib/jackbox/reclassing_spec.rb +394 -0
  86. data/spec/lib/jackbox_spec.rb +595 -0
  87. data/spec/spec_helper.rb +139 -0
  88. metadata +218 -0
@@ -0,0 +1,595 @@
1
+ require 'spec_helper'
2
+ =begin rdoc
3
+ jackbox_spec
4
+ author: Lou Henry
5
+ :nodoc:all:
6
+ =end
7
+
8
+ include Injectors
9
+
10
+ #####
11
+ #
12
+ # We spec the jackbox library part of this gem
13
+ #
14
+ describe Jackbox, 'jackbox library', :library do
15
+
16
+
17
+ #####
18
+ # Dynamic Method decorators
19
+
20
+ it 'adds method decorators' do
21
+ Object.new.should respond_to :decorate
22
+ Object.should respond_to :decorate
23
+ end
24
+
25
+ describe 'Kernel#decorate', 'dynamic specializations of a method' do
26
+ it 'is available during class definition' do
27
+
28
+ class One
29
+ def foo
30
+ 'foo '
31
+ end
32
+ end
33
+ class One
34
+ decorate :foo do
35
+ super() + 'decoration'
36
+ end
37
+ end
38
+ One.new.foo.should == 'foo decoration'
39
+
40
+ end
41
+
42
+ it 'allows decorating the same method multiple times' do
43
+
44
+ class T
45
+ def bar
46
+ 'bar '
47
+ end
48
+ end
49
+ class T
50
+ decorate :bar do # <- GETS CLOBERED
51
+ super() + 'none '
52
+ end
53
+ end
54
+ class T
55
+ decorate :bar do
56
+ super() + 'and then some'
57
+ end
58
+ end
59
+ expect{T.new.bar.should == 'bar and then some'}.to_not raise_error
60
+
61
+ end
62
+
63
+ it 'is available at the object instance level during execution' do
64
+
65
+ class One
66
+ def foo
67
+ 'foo '
68
+ end
69
+ end
70
+ class One
71
+ decorate :foo do
72
+ super() + 'decoration'
73
+ end
74
+ end
75
+ one = One.new
76
+ one.decorate :foo do |arg|
77
+ super() + arg
78
+ end
79
+ one.foo(' after').should match_regex('foo decoration after')
80
+
81
+ end
82
+
83
+ it 'allows ruby_c objects and singleton classes to be decorated as well' do
84
+
85
+ STDOUT.should_receive(:puts).with("Changing directory...")
86
+
87
+ Dir.singleton_class.instance_eval do
88
+ decorate :chdir do |*args|
89
+ puts 'Changing directory...'
90
+ super(*args)
91
+ end
92
+ end
93
+ Dir.chdir('.').should == 0
94
+ Dir.singleton_class.instance_eval { undecorate :chdir }
95
+
96
+ end
97
+
98
+ it 'raises an error when decorating singleton classes without returning them properly' do
99
+
100
+ expect {
101
+
102
+ class File
103
+ class << self
104
+ decorate :chown do |*args| end
105
+ end
106
+ end
107
+
108
+ }.to raise_error
109
+ expect {
110
+
111
+ class File
112
+ singleton_class.instance_eval do # MUST USE #singleton_class or #metaclass
113
+ decorate :chown do |*args| end
114
+ end
115
+ end
116
+
117
+ }.to_not raise_error
118
+
119
+ end
120
+
121
+ the 'decoration can be rolled back' do
122
+
123
+ class F
124
+ def bar
125
+ 'bar '
126
+ end
127
+ end
128
+ class F
129
+ decorate :bar do
130
+ super() + 'the unforseen'
131
+ end
132
+ end
133
+ F.new.bar.should == 'bar the unforseen'
134
+ class F
135
+ # remove_method :bar
136
+ undecorate :bar
137
+ end
138
+ F.new.bar.should == 'bar '
139
+
140
+ end
141
+
142
+ this 'roll-back works on singleton_class also' do
143
+
144
+ class G
145
+ class << self
146
+ def moo
147
+ 'moooo'
148
+ end
149
+ end
150
+ end
151
+ class G
152
+ singleton_class.instance_eval do
153
+ decorate :moo do
154
+ super() + ' maaaa'
155
+ end
156
+ end
157
+ end
158
+ G.moo.should == 'moooo maaaa'
159
+ class G
160
+ singleton_class.instance_eval do
161
+ undecorate :moo
162
+ end
163
+ end
164
+ G.moo.should == 'moooo'
165
+
166
+ end
167
+
168
+ it 'also works like so' do
169
+
170
+ Object.decorate :inspect do
171
+ super() + " is your object"
172
+ end
173
+ Object.new.inspect.should =~ /is your object/
174
+
175
+ end
176
+
177
+ it 'does not work on undefined methods' do
178
+
179
+ class SomeCrappyClass
180
+ end
181
+
182
+ expect {
183
+ class SomeCrappyClass
184
+ decorate :boo do
185
+ :boo
186
+ end
187
+ end
188
+ }.to raise_error
189
+ end
190
+
191
+ it 'is not intended to work on plain modules' do
192
+
193
+ module Am
194
+ def off
195
+ 'off'
196
+ end
197
+ end
198
+
199
+ class B
200
+ include Am
201
+ end
202
+
203
+ B.new.off.should == 'off'
204
+
205
+ module Am
206
+ decorate :off do
207
+ super() + 'on'
208
+ end
209
+ end
210
+
211
+ expect {
212
+
213
+ B.new.off.should == 'offon' #fails!!
214
+
215
+ }.to raise_error
216
+
217
+ end
218
+
219
+ it 'is not intended for plain injectors either' do
220
+
221
+ Aj = injector :aj do
222
+ def off
223
+ 'off'
224
+ end
225
+ end
226
+
227
+ class Bj
228
+ include Aj
229
+ end
230
+
231
+ Bj.new.off.should == 'off'
232
+
233
+ aj do
234
+ decorate :off do
235
+ super() + 'on'
236
+ end
237
+ end
238
+ Bj.inject Aj
239
+
240
+ expect {
241
+
242
+ Bj.new.off.should == 'offon' #fails!!
243
+
244
+ }.to raise_error
245
+
246
+ end
247
+
248
+ it 'does work on self-extended injectors/modules' do
249
+
250
+ include Injectors
251
+
252
+ injector :tester
253
+
254
+ tester do
255
+ extend self # extend self
256
+ # Note: you cannot self enrich an injector
257
+ def order weight
258
+ lets manus =->(){"manus for #{weight}"}
259
+ manus[]
260
+ end
261
+ end
262
+ tester.order(50).should == 'manus for 50' # call method extended to self
263
+
264
+
265
+ tester do
266
+ decorate :order do |num| # decorate the same method
267
+ self.to_s + super(num)
268
+ end
269
+ end
270
+ tester.order(50).should =~ /^|manus| for 50/ # call decorated method extended to self
271
+
272
+ end
273
+
274
+ end
275
+
276
+
277
+
278
+ #####
279
+ # lets blocks
280
+ describe '#lets' do
281
+
282
+ it 'works to define local lambdas/proc' do
283
+
284
+ lets close =->(){ 'a really local presence' }
285
+ close.call.should == 'a really local presence'
286
+
287
+ end
288
+
289
+ it 'works as shortcut to define define_method' do
290
+
291
+ class LetsTester
292
+ lets(:far){ 'some great distance'}
293
+ end
294
+ LetsTester.new.far.should == 'some great distance'
295
+
296
+ end
297
+
298
+ it 'cannot evaluate a long block' do
299
+
300
+ # $stdout.should_receive(:puts).with('perform a long evaluation for a predicate')
301
+ expect {
302
+
303
+ def tester
304
+ lets {
305
+ puts 'perform a long evaluation for a predicate'
306
+ }.call if true
307
+ end
308
+ tester
309
+
310
+ }.to raise_error(Jackbox::UserError)
311
+
312
+ end
313
+
314
+ it 'should not forbid the following' do
315
+ # does work at the instance level
316
+ expect {
317
+
318
+ instance_eval {
319
+ lets(:foo){ 'foo bar'}
320
+ }
321
+
322
+ }.to_not raise_error(Jackbox::UserError)
323
+
324
+ end
325
+
326
+ it 'does allow errors to raise thru' do
327
+
328
+ lets make =->(something){
329
+ raise something
330
+ }
331
+
332
+ expect{
333
+ make[:nothing]
334
+ }.to raise_error
335
+
336
+ end
337
+ end
338
+
339
+
340
+
341
+ #####
342
+ # Object scoping <with> statement
343
+
344
+ it 'adds a with statement' do
345
+ should respond_to :with
346
+ end
347
+ describe 'Object.with' do
348
+
349
+ it 'includes the calling context' do
350
+ class One
351
+ def foo(arg)
352
+ 'in One ' + arg
353
+ end
354
+ end
355
+ class Two
356
+ def faa(arg)
357
+ 'and in Two ' + arg
358
+ end
359
+ def tester
360
+ with One.new do
361
+ return foo faa 'with something' # context of One and Two available simultaneously!
362
+ end
363
+ end
364
+ end
365
+ expect{Two.new.tester}.to_not raise_error
366
+ Two.new.tester.should == 'in One and in Two with something'
367
+
368
+ end
369
+
370
+ it 'allows passing instance variables' do
371
+
372
+ STDOUT.should_receive(:puts).with('in One#foo with arg tester')
373
+ STDOUT.should_receive(:puts).with('in One#foo with arg mester')
374
+ STDOUT.should_receive(:puts).with('in One#foo with arg in Two#faa with arg me')
375
+
376
+ class One
377
+ def foo(arg)
378
+ 'in One#foo with arg ' + arg
379
+ end
380
+ end
381
+ class Two
382
+
383
+ def faa arg='nothing'
384
+ 'in Two#faa with arg ' + arg
385
+ end
386
+
387
+ def fii
388
+ @tester = 'tester'
389
+ @mester = 'mester'
390
+
391
+ with One.new, @tester, @mester do |*args|
392
+ args.each { |e| puts foo e }
393
+ puts foo faa 'me'
394
+ end
395
+ end
396
+
397
+ end
398
+ Two.new.fii
399
+ end
400
+
401
+ it 'raises an error if used with no block' do
402
+ expect{with Object.new}.to raise_error(LocalJumpError)
403
+ end
404
+
405
+ it 'raises an error if used on self' do
406
+ expect{
407
+
408
+ with self do
409
+
410
+ end
411
+
412
+ }.to raise_error(ArgumentError)
413
+ end
414
+
415
+ it 'works with decorate on an object multiple times' do
416
+
417
+ class Object
418
+ def foo
419
+ end
420
+ def moo
421
+ end
422
+ end
423
+
424
+ o = with Object.new do
425
+ decorate :foo do
426
+ 'foo'
427
+ end
428
+ decorate :moo do
429
+ 'moo'
430
+ end
431
+ end
432
+ o.foo.should == 'foo'
433
+ o.moo.should == 'moo'
434
+ end
435
+
436
+ end
437
+
438
+ describe 'object#with target' do
439
+
440
+ class BarNone
441
+ def bar
442
+ :large_bar
443
+ end
444
+ end
445
+ class RegularObject
446
+ def object_tester arg
447
+ puts arg or arg
448
+ end
449
+ end
450
+
451
+ it 'allows access to the receiver and the object of with on different levels' do
452
+
453
+ $stdout.should_receive(:puts).with(:large_bar)
454
+
455
+ ro = RegularObject.new
456
+ o = BarNone.new
457
+ ro.with o do
458
+
459
+ @var = object_tester bar # @var is set on o not ro
460
+
461
+ end
462
+ o.instance_variable_get(:@var).should == :large_bar
463
+
464
+ end
465
+ end
466
+
467
+ describe "exiting abnormally" do
468
+ it 'exits via error' do
469
+ expect {
470
+ with Object.new do
471
+ raise ArgumentError, 'should be this error'
472
+ end
473
+ }.to raise_error(ArgumentError, 'should be this error')
474
+
475
+ expect {
476
+ class Unbelievers
477
+ def erroneous obj
478
+ raise RuntimeError, "#{obj}"
479
+ end
480
+ with Object.new do
481
+ Unbelievers.new.erroneous 'lha is the name'
482
+ end
483
+ end
484
+ }.to raise_error(RuntimeError, 'lha is the name')
485
+
486
+ end
487
+
488
+ it 'exits via throw' do
489
+
490
+ $stdout.should_receive(:puts).with('If this is printed we have a problem').exactly(0).times
491
+
492
+ catch(:signal) {
493
+ with Object.new do
494
+ throw :signal
495
+ end
496
+ puts 'If this is printed we have a problem'
497
+ }
498
+
499
+ end
500
+
501
+ it 'also works this way' do
502
+
503
+ expect {
504
+ with Object.new do
505
+ throw :signal
506
+ end
507
+ }.to throw_symbol(:signal)
508
+
509
+ end
510
+
511
+ end
512
+
513
+
514
+ if RUBY_VERSION < '2.0.0'
515
+ #####
516
+ # #singleton_class
517
+ describe "#singleton_class" do
518
+ it 'returns the singleton_class of an object' do
519
+ singleton = class SingletonProber; class << self; self; end; end
520
+ SingletonProber.singleton_class.should == singleton
521
+ end
522
+
523
+ the 'singleton class has a reference to its root class' do
524
+ SingletonProber.singleton_class.root().should == SingletonProber
525
+ end
526
+ end
527
+
528
+
529
+ #####
530
+ # #singleton_class?
531
+ describe "#singleton_class?" do
532
+ it 'should say when class is singleton_class' do
533
+ singleton = class SingletonProber; class << self; self; end; end
534
+ singleton.singleton_class?.should == true
535
+ end
536
+
537
+ it 'should say when class is not singleton_class' do
538
+ SingletonProber.singleton_class?.should == false
539
+ end
540
+ end
541
+ end
542
+
543
+ #####
544
+ # in?
545
+ describe "#in?" do
546
+
547
+ it 'tests membership' do
548
+ a = [1,2,3]
549
+ 1.in?(a).should be
550
+
551
+ b = (3..6)
552
+ 4.in?(b).should be
553
+
554
+ require 'set'
555
+ s = Set[4,6,8]
556
+ 6.in?(s).should be
557
+
558
+ end
559
+
560
+ end
561
+
562
+
563
+ #####
564
+ # to_filepath
565
+ describe "#to_filepath" do
566
+
567
+ it 'turns a namespace to a filepath' do
568
+ module Foo
569
+ module Bar
570
+ class One
571
+ end
572
+ end
573
+ end
574
+ Foo::Bar::One.to_filepath.should == 'Foo/Bar/One'
575
+ end
576
+
577
+ end
578
+
579
+
580
+ #####
581
+ # Regular module syntax candifiers
582
+ describe 'Module#const_values' do
583
+ module ConstValuesTester
584
+ A = 123
585
+ B = 'abc'
586
+ C = [A, B]
587
+ end
588
+ it 'returns an array of all the constant values' do
589
+ ConstValuesTester.values.should be_instance_of(Array)
590
+ ConstValuesTester.values.should == [123, 'abc', [123, 'abc']]
591
+ end
592
+ end
593
+
594
+
595
+ end #library spec