pry 0.9.11.4-i386-mingw32 → 0.9.12-i386-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/.travis.yml +2 -0
  2. data/CHANGELOG +19 -0
  3. data/Rakefile +4 -0
  4. data/lib/pry.rb +1 -1
  5. data/lib/pry/cli.rb +14 -8
  6. data/lib/pry/code.rb +3 -3
  7. data/lib/pry/command.rb +20 -5
  8. data/lib/pry/command_set.rb +3 -3
  9. data/lib/pry/commands.rb +1 -1
  10. data/lib/pry/commands/disabled_commands.rb +2 -0
  11. data/lib/pry/commands/ls.rb +1 -2
  12. data/lib/pry/commands/reload_code.rb +8 -1
  13. data/lib/pry/commands/show_info.rb +66 -5
  14. data/lib/pry/commands/show_source.rb +2 -1
  15. data/lib/pry/commands/whereami.rb +87 -19
  16. data/lib/pry/completion.rb +13 -4
  17. data/lib/pry/helpers/base_helpers.rb +5 -2
  18. data/lib/pry/helpers/command_helpers.rb +3 -1
  19. data/lib/pry/helpers/documentation_helpers.rb +18 -7
  20. data/lib/pry/helpers/table.rb +4 -4
  21. data/lib/pry/indent.rb +2 -7
  22. data/lib/pry/method.rb +89 -129
  23. data/lib/pry/method/disowned.rb +53 -0
  24. data/lib/pry/method/weird_method_locator.rb +186 -0
  25. data/lib/pry/module_candidate.rb +13 -8
  26. data/lib/pry/pager.rb +12 -11
  27. data/lib/pry/plugins.rb +2 -0
  28. data/lib/pry/pry_class.rb +19 -3
  29. data/lib/pry/pry_instance.rb +3 -0
  30. data/lib/pry/terminal.rb +78 -0
  31. data/lib/pry/version.rb +1 -1
  32. data/lib/pry/wrapped_module.rb +63 -1
  33. data/spec/Procfile +3 -0
  34. data/spec/command_helpers_spec.rb +21 -1
  35. data/spec/commands/ls_spec.rb +4 -0
  36. data/spec/commands/show_doc_spec.rb +255 -123
  37. data/spec/commands/show_source_spec.rb +421 -236
  38. data/spec/commands/whereami_spec.rb +60 -11
  39. data/spec/completion_spec.rb +6 -0
  40. data/spec/documentation_helper_spec.rb +73 -0
  41. data/spec/fixtures/whereami_helper.rb +6 -0
  42. data/spec/helpers/table_spec.rb +19 -0
  43. data/spec/method_spec.rb +24 -7
  44. metadata +12 -5
  45. data/.gemtest +0 -0
  46. data/lib/pry/commands/deprecated_commands.rb +0 -2
  47. 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
- should =~ /:super_wibble/
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
- EOS
223
- end
222
+ EOS
223
+ end
224
224
 
225
- after do
226
- Object.remove_const(:TestHost)
227
- end
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
- it "source of method being shadowed should take precedence over variable
235
+ it "source of method being shadowed should take precedence over variable
236
236
  if given self.meth_name syntax" do
237
- @t.eval('show-source self.hello').should =~ /def hello/
237
+ @t.eval('show-source self.hello').should =~ /def hello/
238
+ end
238
239
  end
239
240
  end
240
241
 
241
- end
242
-
243
- describe "on variable or constant" do
244
- before do
245
- class TestHost
246
- def hello
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
- after do
253
- Object.remove_const(:TestHost)
254
- end
251
+ after do
252
+ Object.remove_const(:TestHost)
253
+ end
255
254
 
256
- it "should output source of its class if variable doesn't respond to source_location" do
257
- test_host = TestHost.new
258
- pry_eval(binding, 'show-source test_host').
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
- end
259
+ end
261
260
 
262
- it "should output source of its class if constant doesn't respond to source_location" do
263
- TEST_HOST = TestHost.new
264
- pry_eval(binding, 'show-source TEST_HOST').
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
- Object.remove_const(:TEST_HOST)
265
+ Object.remove_const(:TEST_HOST)
266
+ end
267
267
  end
268
- end
269
268
 
270
- describe "on modules" do
271
- before do
272
- class ShowSourceTestSuperClass
273
- def alpha
269
+ describe "on modules" do
270
+ before do
271
+ class ShowSourceTestSuperClass
272
+ def alpha
273
+ end
274
274
  end
275
- end
276
275
 
277
- class ShowSourceTestClass<ShowSourceTestSuperClass
278
- def alpha
276
+ class ShowSourceTestClass<ShowSourceTestSuperClass
277
+ def alpha
278
+ end
279
279
  end
280
- end
281
280
 
282
- module ShowSourceTestSuperModule
283
- def alpha
281
+ module ShowSourceTestSuperModule
282
+ def alpha
283
+ end
284
284
  end
285
- end
286
285
 
287
- module ShowSourceTestModule
288
- include ShowSourceTestSuperModule
289
- def alpha
286
+ module ShowSourceTestModule
287
+ include ShowSourceTestSuperModule
288
+ def alpha
289
+ end
290
290
  end
291
- end
292
291
 
293
- ShowSourceTestClassWeirdSyntax = Class.new do
294
- def beta
292
+ ShowSourceTestClassWeirdSyntax = Class.new do
293
+ def beta
294
+ end
295
295
  end
296
- end
297
296
 
298
- ShowSourceTestModuleWeirdSyntax = Module.new do
299
- def beta
297
+ ShowSourceTestModuleWeirdSyntax = Module.new do
298
+ def beta
299
+ end
300
300
  end
301
301
  end
302
- end
303
302
 
304
- after do
305
- Object.remove_const :ShowSourceTestSuperClass
306
- Object.remove_const :ShowSourceTestClass
307
- Object.remove_const :ShowSourceTestClassWeirdSyntax
308
- Object.remove_const :ShowSourceTestSuperModule
309
- Object.remove_const :ShowSourceTestModule
310
- Object.remove_const :ShowSourceTestModuleWeirdSyntax
311
- end
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
- describe "basic functionality, should find top-level module definitions" do
314
- it 'should show source for a class' do
315
- pry_eval('show-source ShowSourceTestClass').
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
- end
316
+ end
318
317
 
319
- it 'should show source for a super class' do
320
- pry_eval('show-source -s ShowSourceTestClass').
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
- end
321
+ end
323
322
 
324
- it 'should show source for a module' do
325
- pry_eval('show-source ShowSourceTestModule').
323
+ it 'should show source for a module' do
324
+ pry_eval('show-source ShowSourceTestModule').
326
325
  should =~ /module ShowSourceTestModule/
327
- end
326
+ end
328
327
 
329
- it 'should show source for an ancestor module' do
330
- pry_eval('show-source -s ShowSourceTestModule').
328
+ it 'should show source for an ancestor module' do
329
+ pry_eval('show-source -s ShowSourceTestModule').
331
330
  should =~ /module ShowSourceTestSuperModule/
332
- end
331
+ end
333
332
 
334
- it 'should show source for a class when Const = Class.new syntax is used' do
335
- pry_eval('show-source ShowSourceTestClassWeirdSyntax').
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
- end
336
+ end
338
337
 
339
- it 'should show source for a super class when Const = Class.new syntax is used' do
340
- pry_eval('show-source -s ShowSourceTestClassWeirdSyntax').
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
- end
341
+ end
343
342
 
344
- it 'should show source for a module when Const = Module.new syntax is used' do
345
- pry_eval('show-source ShowSourceTestModuleWeirdSyntax').
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
- if !Pry::Helpers::BaseHelpers.mri_18?
351
- before do
352
- pry_eval unindent(<<-EOS)
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
- EOS
363
- end
364
-
365
- after do
366
- Object.remove_const :Dog
367
- Object.remove_const :TobinaMyDog
368
- end
361
+ EOS
362
+ end
369
363
 
370
- describe "in REPL" do
371
- it 'should find class defined in repl' do
372
- pry_eval('show-source TobinaMyDog').should =~ /class TobinaMyDog/
364
+ after do
365
+ Object.remove_const :Dog
366
+ Object.remove_const :TobinaMyDog
373
367
  end
374
- it 'should find superclass defined in repl' do
375
- pry_eval('show-source -s TobinaMyDog').should =~ /class Dog/
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
- constant_scope(:AlphaClass, :BetaClass) do
383
- class BetaClass
384
- def alpha
381
+ constant_scope(:AlphaClass, :BetaClass) do
382
+ class BetaClass
383
+ def alpha
384
+ end
385
385
  end
386
- end
387
386
 
388
- class AlphaClass
389
- class BetaClass
390
- def beta
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
- pry_eval(AlphaClass, 'show-source BetaClass').should =~ /def beta/
407
+ pry_eval('show-source AlphaClass::BetaClass').should =~ /class Beta/
408
+ end
396
409
  end
397
- end
398
410
 
399
- it 'should lookup nested modules' do
400
- constant_scope(:AlphaClass) do
401
- class AlphaClass
402
- class BetaClass
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
- pry_eval('show-source AlphaClass::BetaClass').should =~ /class Beta/
409
- end
410
- end
421
+ result = pry_eval('show-source TestClassForShowSource -a')
422
+ result.should =~ /def alpha/
423
+ result.should =~ /def beta/
424
+ end
411
425
 
412
- # note that pry assumes a class is only monkey-patched at most
413
- # ONCE per file, so will not find multiple monkeypatches in the
414
- # SAME file.
415
- describe "show-source -a" do
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
- result = pry_eval('show-source TestClassForShowSource -a')
423
- result.should =~ /def alpha/
424
- result.should =~ /def beta/
425
- end
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
- it 'should show the source for a class_eval-based monkeypatch' do
428
- TestClassForShowSourceClassEval.class_eval do
429
- def class_eval_method
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
- result = pry_eval('show-source TestClassForShowSourceClassEval -a')
434
- result.should =~ /def class_eval_method/
435
- end
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
- it 'should ignore -a when object is not a module' do
438
- TestClassForShowSourceClassEval.class_eval do
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
- result = pry_eval('show-source TestClassForShowSourceClassEval#class_eval_method -a')
445
- result.should =~ /bing/
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
- it 'should show the source for an instance_eval-based monkeypatch' do
449
- TestClassForShowSourceInstanceEval.instance_eval do
450
- def instance_eval_method
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
- result = pry_eval('show-source TestClassForShowSourceInstanceEval -a')
455
- result.should =~ /def instance_eval_method/
456
- end
457
- end
499
+ after do
500
+ Object.remove_const(:TestHost)
501
+ end
458
502
 
459
- describe "when show-source is invoked without a method or class argument" do
460
- before do
461
- module TestHost
462
- class M
463
- def alpha; end
464
- def beta; end
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
- module C
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
- module D
471
- def self.invoked_in_method
472
- pry_eval(binding, 'show-source')
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
- Object.remove_const(:TestHost)
578
+ Pry.config.commands = @oldset
480
579
  end
481
580
 
482
- describe "inside a module" do
483
- it 'should display module source by default' do
484
- out = pry_eval(TestHost::M, 'show-source')
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
- it 'should be unable to find module source if no methods defined' do
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 'should display method code (rather than class) if Pry started inside method binding' do
498
- out = TestHost::D.invoked_in_method
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
- it 'should display class source when inside instance' do
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 allow options to be passed' do
511
- out = pry_eval(TestHost::M, 'show-source -b')
512
- out.should =~ /\d:\s*class M/
513
- out.should =~ /\d:\s*def alpha/
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
- describe "should skip over broken modules" do
518
- before do
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
- module Muesli
522
- binding.eval("def a; end", "dummy.rb", 1)
523
- binding.eval("def b; end", "dummy.rb", 2)
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
- module Muesli
528
- def d; end
529
- def e; end
530
- end
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
- after do
535
- Object.remove_const(:BabyDuck)
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
- # TODO: !!! This is a bad spec, should not be expected behaviour?!?!
539
- #
540
- # it 'should return source for first valid module' do
541
- # out = pry_eval('show-source BabyDuck::Muesli')
542
- # out.should =~ /def d; end/
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
- describe "on commands" do
552
- before do
553
- @oldset = Pry.config.commands
554
- @set = Pry.config.commands = Pry::CommandSet.new do
555
- import Pry::Commands
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
- after do
560
- Pry.config.commands = @oldset
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
- it 'should show source for an ordinary command' do
564
- @set.command "foo", :body_of_foo do; end
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
- pry_eval('show-source foo').should =~ /:body_of_foo/
567
- end
675
+ class Brian; end
676
+ class Jingle
677
+ def a; :doink; end
678
+ end
568
679
 
569
- it "should output source of commands using special characters" do
570
- @set.command "!%$", "I gots the yellow fever" do; end
680
+ class Jangle < Jingle; include Pig; end
681
+ class Bangle < Jangle; end
682
+ end
683
+ end
571
684
 
572
- pry_eval('show-source !%$').should =~ /yellow fever/
573
- end
685
+ after do
686
+ Object.remove_const(:Jesus)
687
+ end
574
688
 
575
- it 'should show source for a command with spaces in its name' do
576
- @set.command "foo bar", :body_of_foo_bar do; end
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
- pry_eval('show-source foo bar').should =~ /:body_of_foo_bar/
579
- end
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
- it 'should show source for a command by listing name' do
582
- @set.command /foo(.*)/, :body_of_foo_bar_regex, :listing => "bar" do; end
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
- pry_eval('show-source bar').should =~ /:body_of_foo_bar_regex/
585
- end
586
- end
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
- describe "should set _file_ and _dir_" do
589
- it 'should set _file_ and _dir_ to file containing method source' do
590
- t = pry_tester
591
- t.process_command "show-source TestClassForShowSource#alpha"
592
- t.pry.last_file.should =~ /show_source_doc_examples/
593
- t.pry.last_dir.should =~ /fixtures/
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