pry 0.9.11.4-i386-mswin32 → 0.9.12-i386-mswin32
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.
- data/.travis.yml +2 -0
- data/CHANGELOG +19 -0
- data/Rakefile +4 -0
- data/lib/pry.rb +1 -1
- data/lib/pry/cli.rb +14 -8
- data/lib/pry/code.rb +3 -3
- data/lib/pry/command.rb +20 -5
- data/lib/pry/command_set.rb +3 -3
- data/lib/pry/commands.rb +1 -1
- data/lib/pry/commands/disabled_commands.rb +2 -0
- data/lib/pry/commands/ls.rb +1 -2
- data/lib/pry/commands/reload_code.rb +8 -1
- data/lib/pry/commands/show_info.rb +66 -5
- data/lib/pry/commands/show_source.rb +2 -1
- data/lib/pry/commands/whereami.rb +87 -19
- data/lib/pry/completion.rb +13 -4
- data/lib/pry/helpers/base_helpers.rb +5 -2
- data/lib/pry/helpers/command_helpers.rb +3 -1
- data/lib/pry/helpers/documentation_helpers.rb +18 -7
- data/lib/pry/helpers/table.rb +4 -4
- data/lib/pry/indent.rb +2 -7
- data/lib/pry/method.rb +89 -129
- data/lib/pry/method/disowned.rb +53 -0
- data/lib/pry/method/weird_method_locator.rb +186 -0
- data/lib/pry/module_candidate.rb +13 -8
- data/lib/pry/pager.rb +12 -11
- data/lib/pry/plugins.rb +2 -0
- data/lib/pry/pry_class.rb +19 -3
- data/lib/pry/pry_instance.rb +3 -0
- data/lib/pry/terminal.rb +78 -0
- data/lib/pry/version.rb +1 -1
- data/lib/pry/wrapped_module.rb +63 -1
- data/spec/Procfile +3 -0
- data/spec/command_helpers_spec.rb +21 -1
- data/spec/commands/ls_spec.rb +4 -0
- data/spec/commands/show_doc_spec.rb +255 -123
- data/spec/commands/show_source_spec.rb +421 -236
- data/spec/commands/whereami_spec.rb +60 -11
- data/spec/completion_spec.rb +6 -0
- data/spec/documentation_helper_spec.rb +73 -0
- data/spec/fixtures/whereami_helper.rb +6 -0
- data/spec/helpers/table_spec.rb +19 -0
- data/spec/method_spec.rb +24 -7
- metadata +12 -5
- data/.gemtest +0 -0
- data/lib/pry/commands/deprecated_commands.rb +0 -2
- data/lib/pry/terminal_info.rb +0 -48
@@ -136,7 +136,7 @@ if !PryTestHelpers.mri18_and_no_real_source_location?
|
|
136
136
|
end
|
137
137
|
|
138
138
|
pry_eval(binding, "show-source --super o.foo").
|
139
|
-
|
139
|
+
should =~ /:super_wibble/
|
140
140
|
end
|
141
141
|
|
142
142
|
it "should raise a CommandError when super method doesn't exist" do
|
@@ -219,12 +219,12 @@ if !PryTestHelpers.mri18_and_no_real_source_location?
|
|
219
219
|
end
|
220
220
|
end
|
221
221
|
::TestHost.new.hello
|
222
|
-
|
223
|
-
|
222
|
+
EOS
|
223
|
+
end
|
224
224
|
|
225
|
-
|
226
|
-
|
227
|
-
|
225
|
+
after do
|
226
|
+
Object.remove_const(:TestHost)
|
227
|
+
end
|
228
228
|
|
229
229
|
it "source of variable should take precedence over method that is being shadowed" do
|
230
230
|
source = @t.eval('show-source hello')
|
@@ -232,124 +232,123 @@ if !PryTestHelpers.mri18_and_no_real_source_location?
|
|
232
232
|
source.should =~ /proc \{ ' smile ' \}/
|
233
233
|
end
|
234
234
|
|
235
|
-
|
235
|
+
it "source of method being shadowed should take precedence over variable
|
236
236
|
if given self.meth_name syntax" do
|
237
|
-
|
237
|
+
@t.eval('show-source self.hello').should =~ /def hello/
|
238
|
+
end
|
238
239
|
end
|
239
240
|
end
|
240
241
|
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
"hi there"
|
242
|
+
describe "on variable or constant" do
|
243
|
+
before do
|
244
|
+
class TestHost
|
245
|
+
def hello
|
246
|
+
"hi there"
|
247
|
+
end
|
248
248
|
end
|
249
249
|
end
|
250
|
-
end
|
251
250
|
|
252
|
-
|
253
|
-
|
254
|
-
|
251
|
+
after do
|
252
|
+
Object.remove_const(:TestHost)
|
253
|
+
end
|
255
254
|
|
256
|
-
|
257
|
-
|
258
|
-
|
255
|
+
it "should output source of its class if variable doesn't respond to source_location" do
|
256
|
+
test_host = TestHost.new
|
257
|
+
pry_eval(binding, 'show-source test_host').
|
259
258
|
should =~ /class TestHost\n.*def hello/
|
260
|
-
|
259
|
+
end
|
261
260
|
|
262
|
-
|
263
|
-
|
264
|
-
|
261
|
+
it "should output source of its class if constant doesn't respond to source_location" do
|
262
|
+
TEST_HOST = TestHost.new
|
263
|
+
pry_eval(binding, 'show-source TEST_HOST').
|
265
264
|
should =~ /class TestHost\n.*def hello/
|
266
|
-
|
265
|
+
Object.remove_const(:TEST_HOST)
|
266
|
+
end
|
267
267
|
end
|
268
|
-
end
|
269
268
|
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
269
|
+
describe "on modules" do
|
270
|
+
before do
|
271
|
+
class ShowSourceTestSuperClass
|
272
|
+
def alpha
|
273
|
+
end
|
274
274
|
end
|
275
|
-
end
|
276
275
|
|
277
|
-
|
278
|
-
|
276
|
+
class ShowSourceTestClass<ShowSourceTestSuperClass
|
277
|
+
def alpha
|
278
|
+
end
|
279
279
|
end
|
280
|
-
end
|
281
280
|
|
282
|
-
|
283
|
-
|
281
|
+
module ShowSourceTestSuperModule
|
282
|
+
def alpha
|
283
|
+
end
|
284
284
|
end
|
285
|
-
end
|
286
285
|
|
287
|
-
|
288
|
-
|
289
|
-
|
286
|
+
module ShowSourceTestModule
|
287
|
+
include ShowSourceTestSuperModule
|
288
|
+
def alpha
|
289
|
+
end
|
290
290
|
end
|
291
|
-
end
|
292
291
|
|
293
|
-
|
294
|
-
|
292
|
+
ShowSourceTestClassWeirdSyntax = Class.new do
|
293
|
+
def beta
|
294
|
+
end
|
295
295
|
end
|
296
|
-
end
|
297
296
|
|
298
|
-
|
299
|
-
|
297
|
+
ShowSourceTestModuleWeirdSyntax = Module.new do
|
298
|
+
def beta
|
299
|
+
end
|
300
300
|
end
|
301
301
|
end
|
302
|
-
end
|
303
302
|
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
303
|
+
after do
|
304
|
+
Object.remove_const :ShowSourceTestSuperClass
|
305
|
+
Object.remove_const :ShowSourceTestClass
|
306
|
+
Object.remove_const :ShowSourceTestClassWeirdSyntax
|
307
|
+
Object.remove_const :ShowSourceTestSuperModule
|
308
|
+
Object.remove_const :ShowSourceTestModule
|
309
|
+
Object.remove_const :ShowSourceTestModuleWeirdSyntax
|
310
|
+
end
|
312
311
|
|
313
|
-
|
314
|
-
|
315
|
-
|
312
|
+
describe "basic functionality, should find top-level module definitions" do
|
313
|
+
it 'should show source for a class' do
|
314
|
+
pry_eval('show-source ShowSourceTestClass').
|
316
315
|
should =~ /class ShowSourceTestClass.*?def alpha/m
|
317
|
-
|
316
|
+
end
|
318
317
|
|
319
|
-
|
320
|
-
|
318
|
+
it 'should show source for a super class' do
|
319
|
+
pry_eval('show-source -s ShowSourceTestClass').
|
321
320
|
should =~ /class ShowSourceTestSuperClass.*?def alpha/m
|
322
|
-
|
321
|
+
end
|
323
322
|
|
324
|
-
|
325
|
-
|
323
|
+
it 'should show source for a module' do
|
324
|
+
pry_eval('show-source ShowSourceTestModule').
|
326
325
|
should =~ /module ShowSourceTestModule/
|
327
|
-
|
326
|
+
end
|
328
327
|
|
329
|
-
|
330
|
-
|
328
|
+
it 'should show source for an ancestor module' do
|
329
|
+
pry_eval('show-source -s ShowSourceTestModule').
|
331
330
|
should =~ /module ShowSourceTestSuperModule/
|
332
|
-
|
331
|
+
end
|
333
332
|
|
334
|
-
|
335
|
-
|
333
|
+
it 'should show source for a class when Const = Class.new syntax is used' do
|
334
|
+
pry_eval('show-source ShowSourceTestClassWeirdSyntax').
|
336
335
|
should =~ /ShowSourceTestClassWeirdSyntax = Class.new/
|
337
|
-
|
336
|
+
end
|
338
337
|
|
339
|
-
|
340
|
-
|
338
|
+
it 'should show source for a super class when Const = Class.new syntax is used' do
|
339
|
+
pry_eval('show-source -s ShowSourceTestClassWeirdSyntax').
|
341
340
|
should =~ /class Object/
|
342
|
-
|
341
|
+
end
|
343
342
|
|
344
|
-
|
345
|
-
|
343
|
+
it 'should show source for a module when Const = Module.new syntax is used' do
|
344
|
+
pry_eval('show-source ShowSourceTestModuleWeirdSyntax').
|
346
345
|
should =~ /ShowSourceTestModuleWeirdSyntax = Module.new/
|
346
|
+
end
|
347
347
|
end
|
348
|
-
end
|
349
348
|
|
350
|
-
|
351
|
-
|
352
|
-
|
349
|
+
if !Pry::Helpers::BaseHelpers.mri_18?
|
350
|
+
before do
|
351
|
+
pry_eval unindent(<<-EOS)
|
353
352
|
class Dog
|
354
353
|
def woof
|
355
354
|
end
|
@@ -359,238 +358,424 @@ if !PryTestHelpers.mri18_and_no_real_source_location?
|
|
359
358
|
def woof
|
360
359
|
end
|
361
360
|
end
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
after do
|
366
|
-
Object.remove_const :Dog
|
367
|
-
Object.remove_const :TobinaMyDog
|
368
|
-
end
|
361
|
+
EOS
|
362
|
+
end
|
369
363
|
|
370
|
-
|
371
|
-
|
372
|
-
|
364
|
+
after do
|
365
|
+
Object.remove_const :Dog
|
366
|
+
Object.remove_const :TobinaMyDog
|
373
367
|
end
|
374
|
-
|
375
|
-
|
368
|
+
|
369
|
+
describe "in REPL" do
|
370
|
+
it 'should find class defined in repl' do
|
371
|
+
pry_eval('show-source TobinaMyDog').should =~ /class TobinaMyDog/
|
372
|
+
end
|
373
|
+
it 'should find superclass defined in repl' do
|
374
|
+
pry_eval('show-source -s TobinaMyDog').should =~ /class Dog/
|
375
|
+
end
|
376
376
|
end
|
377
377
|
end
|
378
|
-
end
|
379
378
|
|
380
379
|
it 'should lookup module name with respect to current context' do
|
381
380
|
|
382
|
-
|
383
|
-
|
384
|
-
|
381
|
+
constant_scope(:AlphaClass, :BetaClass) do
|
382
|
+
class BetaClass
|
383
|
+
def alpha
|
384
|
+
end
|
385
385
|
end
|
386
|
-
end
|
387
386
|
|
388
|
-
|
389
|
-
|
390
|
-
|
387
|
+
class AlphaClass
|
388
|
+
class BetaClass
|
389
|
+
def beta
|
390
|
+
end
|
391
391
|
end
|
392
392
|
end
|
393
|
+
|
394
|
+
pry_eval(AlphaClass, 'show-source BetaClass').should =~ /def beta/
|
393
395
|
end
|
396
|
+
end
|
397
|
+
|
398
|
+
it 'should lookup nested modules' do
|
399
|
+
constant_scope(:AlphaClass) do
|
400
|
+
class AlphaClass
|
401
|
+
class BetaClass
|
402
|
+
def beta
|
403
|
+
end
|
404
|
+
end
|
405
|
+
end
|
394
406
|
|
395
|
-
|
407
|
+
pry_eval('show-source AlphaClass::BetaClass').should =~ /class Beta/
|
408
|
+
end
|
396
409
|
end
|
397
|
-
end
|
398
410
|
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
411
|
+
# note that pry assumes a class is only monkey-patched at most
|
412
|
+
# ONCE per file, so will not find multiple monkeypatches in the
|
413
|
+
# SAME file.
|
414
|
+
describe "show-source -a" do
|
415
|
+
it 'should show the source for all monkeypatches defined in different files' do
|
416
|
+
class TestClassForShowSource
|
403
417
|
def beta
|
404
418
|
end
|
405
419
|
end
|
406
|
-
end
|
407
420
|
|
408
|
-
|
409
|
-
|
410
|
-
|
421
|
+
result = pry_eval('show-source TestClassForShowSource -a')
|
422
|
+
result.should =~ /def alpha/
|
423
|
+
result.should =~ /def beta/
|
424
|
+
end
|
411
425
|
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
it 'should show the source for all monkeypatches defined in different files' do
|
417
|
-
class TestClassForShowSource
|
418
|
-
def beta
|
426
|
+
it 'should show the source for a class_eval-based monkeypatch' do
|
427
|
+
TestClassForShowSourceClassEval.class_eval do
|
428
|
+
def class_eval_method
|
429
|
+
end
|
419
430
|
end
|
431
|
+
|
432
|
+
result = pry_eval('show-source TestClassForShowSourceClassEval -a')
|
433
|
+
result.should =~ /def class_eval_method/
|
420
434
|
end
|
421
435
|
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
436
|
+
it 'should ignore -a when object is not a module' do
|
437
|
+
TestClassForShowSourceClassEval.class_eval do
|
438
|
+
def class_eval_method
|
439
|
+
:bing
|
440
|
+
end
|
441
|
+
end
|
426
442
|
|
427
|
-
|
428
|
-
|
429
|
-
|
443
|
+
result = pry_eval('show-source TestClassForShowSourceClassEval#class_eval_method -a')
|
444
|
+
result.should =~ /bing/
|
445
|
+
end
|
446
|
+
|
447
|
+
it 'should show the source for an instance_eval-based monkeypatch' do
|
448
|
+
TestClassForShowSourceInstanceEval.instance_eval do
|
449
|
+
def instance_eval_method
|
450
|
+
end
|
430
451
|
end
|
452
|
+
|
453
|
+
result = pry_eval('show-source TestClassForShowSourceInstanceEval -a')
|
454
|
+
result.should =~ /def instance_eval_method/
|
431
455
|
end
|
432
456
|
|
433
|
-
|
434
|
-
|
435
|
-
|
457
|
+
describe "messages relating to -a" do
|
458
|
+
it 'indicates all available monkeypatches can be shown with -a when (when -a not used and more than one candidate exists for class)' do
|
459
|
+
class TestClassForShowSource
|
460
|
+
def beta
|
461
|
+
end
|
462
|
+
end
|
436
463
|
|
437
|
-
|
438
|
-
|
439
|
-
def class_eval_method
|
440
|
-
:bing
|
464
|
+
result = pry_eval('show-source TestClassForShowSource')
|
465
|
+
result.should =~ /available monkeypatches/
|
441
466
|
end
|
442
|
-
end
|
443
467
|
|
444
|
-
|
445
|
-
|
468
|
+
it 'shouldnt say anything about monkeypatches when only one candidate exists for selected class' do
|
469
|
+
class Aarrrrrghh
|
470
|
+
def o;end
|
471
|
+
end
|
472
|
+
|
473
|
+
result = pry_eval('show-source Aarrrrrghh')
|
474
|
+
result.should.not =~ /available monkeypatches/
|
475
|
+
Object.remove_const(:Aarrrrrghh)
|
476
|
+
end
|
477
|
+
end
|
446
478
|
end
|
447
479
|
|
448
|
-
|
449
|
-
|
450
|
-
|
480
|
+
describe "when show-source is invoked without a method or class argument" do
|
481
|
+
before do
|
482
|
+
module TestHost
|
483
|
+
class M
|
484
|
+
def alpha; end
|
485
|
+
def beta; end
|
486
|
+
end
|
487
|
+
|
488
|
+
module C
|
489
|
+
end
|
490
|
+
|
491
|
+
module D
|
492
|
+
def self.invoked_in_method
|
493
|
+
pry_eval(binding, 'show-source')
|
494
|
+
end
|
495
|
+
end
|
451
496
|
end
|
452
497
|
end
|
453
498
|
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
end
|
499
|
+
after do
|
500
|
+
Object.remove_const(:TestHost)
|
501
|
+
end
|
458
502
|
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
def alpha
|
464
|
-
def beta
|
503
|
+
describe "inside a module" do
|
504
|
+
it 'should display module source by default' do
|
505
|
+
out = pry_eval(TestHost::M, 'show-source')
|
506
|
+
out.should =~ /class M/
|
507
|
+
out.should =~ /def alpha/
|
508
|
+
out.should =~ /def beta/
|
509
|
+
end
|
510
|
+
|
511
|
+
it 'should be unable to find module source if no methods defined' do
|
512
|
+
proc {
|
513
|
+
pry_eval(TestHost::C, 'show-source')
|
514
|
+
}.should.raise(Pry::CommandError).
|
515
|
+
message.should =~ /Couldn't locate/
|
516
|
+
end
|
517
|
+
|
518
|
+
it 'should display method code (rather than class) if Pry started inside method binding' do
|
519
|
+
out = TestHost::D.invoked_in_method
|
520
|
+
out.should =~ /invoked_in_method/
|
521
|
+
out.should.not =~ /module D/
|
465
522
|
end
|
466
523
|
|
467
|
-
|
524
|
+
it 'should display class source when inside instance' do
|
525
|
+
out = pry_eval(TestHost::M.new, 'show-source')
|
526
|
+
out.should =~ /class M/
|
527
|
+
out.should =~ /def alpha/
|
528
|
+
out.should =~ /def beta/
|
468
529
|
end
|
469
530
|
|
470
|
-
|
471
|
-
|
472
|
-
|
531
|
+
it 'should allow options to be passed' do
|
532
|
+
out = pry_eval(TestHost::M, 'show-source -b')
|
533
|
+
out.should =~ /\d:\s*class M/
|
534
|
+
out.should =~ /\d:\s*def alpha/
|
535
|
+
out.should =~ /\d:\s*def beta/
|
536
|
+
end
|
537
|
+
|
538
|
+
describe "should skip over broken modules" do
|
539
|
+
before do
|
540
|
+
module BabyDuck
|
541
|
+
|
542
|
+
module Muesli
|
543
|
+
binding.eval("def a; end", "dummy.rb", 1)
|
544
|
+
binding.eval("def b; end", "dummy.rb", 2)
|
545
|
+
binding.eval("def c; end", "dummy.rb", 3)
|
546
|
+
end
|
547
|
+
|
548
|
+
module Muesli
|
549
|
+
def d; end
|
550
|
+
def e; end
|
551
|
+
end
|
552
|
+
end
|
553
|
+
end
|
554
|
+
|
555
|
+
after do
|
556
|
+
Object.remove_const(:BabyDuck)
|
557
|
+
end
|
558
|
+
|
559
|
+
it 'should return source for first valid module' do
|
560
|
+
out = pry_eval('show-source BabyDuck::Muesli')
|
561
|
+
out.should =~ /def d; end/
|
562
|
+
out.should.not =~ /def a; end/
|
473
563
|
end
|
474
564
|
end
|
475
565
|
end
|
476
566
|
end
|
567
|
+
end
|
568
|
+
|
569
|
+
describe "on commands" do
|
570
|
+
before do
|
571
|
+
@oldset = Pry.config.commands
|
572
|
+
@set = Pry.config.commands = Pry::CommandSet.new do
|
573
|
+
import Pry::Commands
|
574
|
+
end
|
575
|
+
end
|
477
576
|
|
478
577
|
after do
|
479
|
-
|
578
|
+
Pry.config.commands = @oldset
|
480
579
|
end
|
481
580
|
|
482
|
-
describe "
|
483
|
-
it 'should
|
484
|
-
|
485
|
-
out.should =~ /class M/
|
486
|
-
out.should =~ /def alpha/
|
487
|
-
out.should =~ /def beta/
|
488
|
-
end
|
581
|
+
describe "block commands" do
|
582
|
+
it 'should show source for an ordinary command' do
|
583
|
+
@set.command "foo", :body_of_foo do; end
|
489
584
|
|
490
|
-
|
491
|
-
proc {
|
492
|
-
pry_eval(TestHost::C, 'show-source')
|
493
|
-
}.should.raise(Pry::CommandError).
|
494
|
-
message.should =~ /Cannot find a definition for/
|
585
|
+
pry_eval('show-source foo').should =~ /:body_of_foo/
|
495
586
|
end
|
496
587
|
|
497
|
-
it
|
498
|
-
|
499
|
-
out.should =~ /invoked_in_method/
|
500
|
-
out.should.not =~ /module D/
|
501
|
-
end
|
588
|
+
it "should output source of commands using special characters" do
|
589
|
+
@set.command "!%$", "I gots the yellow fever" do; end
|
502
590
|
|
503
|
-
|
504
|
-
out = pry_eval(TestHost::M.new, 'show-source')
|
505
|
-
out.should =~ /class M/
|
506
|
-
out.should =~ /def alpha/
|
507
|
-
out.should =~ /def beta/
|
591
|
+
pry_eval('show-source !%$').should =~ /yellow fever/
|
508
592
|
end
|
509
593
|
|
510
|
-
it 'should
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
out.should =~ /\d:\s*def beta/
|
594
|
+
it 'should show source for a command with spaces in its name' do
|
595
|
+
@set.command "foo bar", :body_of_foo_bar do; end
|
596
|
+
|
597
|
+
pry_eval('show-source foo bar').should =~ /:body_of_foo_bar/
|
515
598
|
end
|
516
599
|
|
517
|
-
|
518
|
-
|
519
|
-
module BabyDuck
|
600
|
+
it 'should show source for a command by listing name' do
|
601
|
+
@set.command /foo(.*)/, :body_of_foo_bar_regex, :listing => "bar" do; end
|
520
602
|
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
binding.eval("def c; end", "dummy.rb", 3)
|
525
|
-
end
|
603
|
+
pry_eval('show-source bar').should =~ /:body_of_foo_bar_regex/
|
604
|
+
end
|
605
|
+
end
|
526
606
|
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
end
|
607
|
+
describe "create_command commands" do
|
608
|
+
it 'should show source for a command' do
|
609
|
+
@set.create_command "foo", "babble" do
|
610
|
+
def process() :body_of_foo end
|
532
611
|
end
|
612
|
+
pry_eval('show-source foo').should =~ /:body_of_foo/
|
613
|
+
end
|
533
614
|
|
534
|
-
|
535
|
-
|
615
|
+
it 'should show source for a command defined inside pry' do
|
616
|
+
pry_eval %{
|
617
|
+
_pry_.commands.create_command "foo", "babble" do
|
618
|
+
def process() :body_of_foo end
|
536
619
|
end
|
620
|
+
}
|
621
|
+
pry_eval('show-source foo').should =~ /:body_of_foo/
|
622
|
+
end
|
623
|
+
end
|
537
624
|
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
# out.should.not =~ /def a; end/
|
544
|
-
# end
|
545
|
-
|
625
|
+
describe "real class-based commands" do
|
626
|
+
before do
|
627
|
+
class ::TemporaryCommand < Pry::ClassCommand
|
628
|
+
match 'temp-command'
|
629
|
+
def process() :body_of_temp end
|
546
630
|
end
|
631
|
+
|
632
|
+
Pry.commands.add_command(::TemporaryCommand)
|
547
633
|
end
|
548
|
-
end
|
549
|
-
end
|
550
634
|
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
635
|
+
after do
|
636
|
+
Object.remove_const(:TemporaryCommand)
|
637
|
+
end
|
638
|
+
|
639
|
+
it 'should show source for a command' do
|
640
|
+
pry_eval('show-source temp-command').should =~ /:body_of_temp/
|
641
|
+
end
|
642
|
+
|
643
|
+
it 'should show source for a command defined inside pry' do
|
644
|
+
pry_eval %{
|
645
|
+
class ::TemporaryCommandInPry < Pry::ClassCommand
|
646
|
+
match 'temp-command-in-pry'
|
647
|
+
def process() :body_of_temp end
|
648
|
+
end
|
649
|
+
}
|
650
|
+
Pry.commands.add_command(::TemporaryCommandInPry)
|
651
|
+
pry_eval('show-source temp-command-in-pry').should =~ /:body_of_temp/
|
652
|
+
Object.remove_const(:TemporaryCommandInPry)
|
556
653
|
end
|
557
654
|
end
|
655
|
+
end
|
558
656
|
|
559
|
-
|
560
|
-
|
657
|
+
describe "should set _file_ and _dir_" do
|
658
|
+
it 'should set _file_ and _dir_ to file containing method source' do
|
659
|
+
t = pry_tester
|
660
|
+
t.process_command "show-source TestClassForShowSource#alpha"
|
661
|
+
t.pry.last_file.should =~ /show_source_doc_examples/
|
662
|
+
t.pry.last_dir.should =~ /fixtures/
|
561
663
|
end
|
664
|
+
end
|
562
665
|
|
563
|
-
|
564
|
-
|
666
|
+
unless Pry::Helpers::BaseHelpers.rbx?
|
667
|
+
describe "can't find class/module code" do
|
668
|
+
describe "for classes" do
|
669
|
+
before do
|
670
|
+
module Jesus
|
671
|
+
module Pig
|
672
|
+
def lillybing; :lillybing; end
|
673
|
+
end
|
565
674
|
|
566
|
-
|
567
|
-
|
675
|
+
class Brian; end
|
676
|
+
class Jingle
|
677
|
+
def a; :doink; end
|
678
|
+
end
|
568
679
|
|
569
|
-
|
570
|
-
|
680
|
+
class Jangle < Jingle; include Pig; end
|
681
|
+
class Bangle < Jangle; end
|
682
|
+
end
|
683
|
+
end
|
571
684
|
|
572
|
-
|
573
|
-
|
685
|
+
after do
|
686
|
+
Object.remove_const(:Jesus)
|
687
|
+
end
|
574
688
|
|
575
|
-
|
576
|
-
|
689
|
+
it 'shows superclass code' do
|
690
|
+
t = pry_tester
|
691
|
+
t.process_command "show-source Jesus::Jangle"
|
692
|
+
t.last_output.should =~ /doink/
|
693
|
+
end
|
577
694
|
|
578
|
-
|
579
|
-
|
695
|
+
it 'ignores included modules' do
|
696
|
+
t = pry_tester
|
697
|
+
t.process_command "show-source Jesus::Jangle"
|
698
|
+
t.last_output.should.not =~ /lillybing/
|
699
|
+
end
|
580
700
|
|
581
|
-
|
582
|
-
|
701
|
+
it 'errors when class has no superclass to show' do
|
702
|
+
t = pry_tester
|
703
|
+
lambda { t.process_command "show-source Jesus::Brian" }.should.raise(Pry::CommandError).message.
|
704
|
+
should =~ /Couldn't locate/
|
705
|
+
end
|
583
706
|
|
584
|
-
|
585
|
-
|
586
|
-
|
707
|
+
it 'shows warning when reverting to superclass code' do
|
708
|
+
t = pry_tester
|
709
|
+
t.process_command "show-source Jesus::Jangle"
|
710
|
+
t.last_output.should =~ /Warning.*?Cannot find.*?Jesus::Jangle.*Showing.*Jesus::Jingle instead/
|
711
|
+
end
|
587
712
|
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
713
|
+
it 'shows nth level superclass code (when no intermediary superclasses have code either)' do
|
714
|
+
t = pry_tester
|
715
|
+
t.process_command "show-source Jesus::Bangle"
|
716
|
+
t.last_output.should =~ /doink/
|
717
|
+
end
|
718
|
+
|
719
|
+
it 'shows correct warning when reverting to nth level superclass' do
|
720
|
+
t = pry_tester
|
721
|
+
t.process_command "show-source Jesus::Bangle"
|
722
|
+
t.last_output.should =~ /Warning.*?Cannot find.*?Jesus::Bangle.*Showing.*Jesus::Jingle instead/
|
723
|
+
end
|
724
|
+
end
|
725
|
+
|
726
|
+
describe "for modules" do
|
727
|
+
before do
|
728
|
+
module Jesus
|
729
|
+
module Alpha
|
730
|
+
def alpha; :alpha; end
|
731
|
+
end
|
732
|
+
|
733
|
+
module Zeta; end
|
734
|
+
|
735
|
+
module Beta
|
736
|
+
include Alpha
|
737
|
+
end
|
738
|
+
|
739
|
+
module Gamma
|
740
|
+
include Beta
|
741
|
+
end
|
742
|
+
end
|
743
|
+
end
|
744
|
+
|
745
|
+
after do
|
746
|
+
Object.remove_const(:Jesus)
|
747
|
+
end
|
748
|
+
|
749
|
+
it 'shows included module code' do
|
750
|
+
t = pry_tester
|
751
|
+
t.process_command "show-source Jesus::Beta"
|
752
|
+
t.last_output.should =~ /alpha/
|
753
|
+
end
|
754
|
+
|
755
|
+
it 'shows warning when reverting to included module code' do
|
756
|
+
t = pry_tester
|
757
|
+
t.process_command "show-source Jesus::Beta"
|
758
|
+
t.last_output.should =~ /Warning.*?Cannot find.*?Jesus::Beta.*Showing.*Jesus::Alpha instead/
|
759
|
+
end
|
760
|
+
|
761
|
+
it 'errors when module has no included module to show' do
|
762
|
+
t = pry_tester
|
763
|
+
lambda { t.process_command "show-source Jesus::Zeta" }.should.raise(Pry::CommandError).message.
|
764
|
+
should =~ /Couldn't locate/
|
765
|
+
end
|
766
|
+
|
767
|
+
it 'shows nth level included module code (when no intermediary modules have code either)' do
|
768
|
+
t = pry_tester
|
769
|
+
t.process_command "show-source Jesus::Gamma"
|
770
|
+
t.last_output.should =~ /alpha/
|
771
|
+
end
|
772
|
+
|
773
|
+
it 'shows correct warning when reverting to nth level included module' do
|
774
|
+
t = pry_tester
|
775
|
+
t.process_command "show-source Jesus::Gamma"
|
776
|
+
t.last_output.should =~ /Warning.*?Cannot find.*?Jesus::Gamma.*Showing.*Jesus::Alpha instead/
|
777
|
+
end
|
778
|
+
end
|
594
779
|
end
|
595
780
|
end
|
596
781
|
end
|