pry 0.9.9.6pre2-i386-mingw32 → 0.9.10-i386-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +41 -0
- data/CONTRIBUTORS +27 -26
- data/README.markdown +4 -4
- data/Rakefile +2 -2
- data/lib/pry.rb +25 -19
- data/lib/pry/cli.rb +31 -10
- data/lib/pry/code.rb +41 -83
- data/lib/pry/command.rb +87 -76
- data/lib/pry/command_set.rb +13 -20
- data/lib/pry/completion.rb +139 -121
- data/lib/pry/config.rb +4 -0
- data/lib/pry/core_extensions.rb +88 -31
- data/lib/pry/default_commands/cd.rb +31 -8
- data/lib/pry/default_commands/context.rb +4 -58
- data/lib/pry/default_commands/easter_eggs.rb +1 -1
- data/lib/pry/default_commands/editing.rb +21 -14
- data/lib/pry/default_commands/find_method.rb +5 -7
- data/lib/pry/default_commands/gist.rb +187 -0
- data/lib/pry/default_commands/hist.rb +6 -6
- data/lib/pry/default_commands/input_and_output.rb +73 -129
- data/lib/pry/default_commands/introspection.rb +107 -52
- data/lib/pry/default_commands/ls.rb +1 -1
- data/lib/pry/default_commands/misc.rb +0 -5
- data/lib/pry/default_commands/whereami.rb +92 -0
- data/lib/pry/helpers/base_helpers.rb +6 -1
- data/lib/pry/helpers/command_helpers.rb +30 -9
- data/lib/pry/helpers/documentation_helpers.rb +7 -7
- data/lib/pry/helpers/options_helpers.rb +1 -1
- data/lib/pry/helpers/text.rb +7 -9
- data/lib/pry/history.rb +15 -2
- data/lib/pry/hooks.rb +1 -1
- data/lib/pry/indent.rb +17 -10
- data/lib/pry/method.rb +35 -19
- data/lib/pry/module_candidate.rb +130 -0
- data/lib/pry/pry_class.rb +54 -22
- data/lib/pry/pry_instance.rb +71 -14
- data/lib/pry/repl_file_loader.rb +80 -0
- data/lib/pry/version.rb +1 -1
- data/lib/pry/wrapped_module.rb +121 -142
- data/pry.gemspec +13 -13
- data/test/candidate_helper1.rb +11 -0
- data/test/candidate_helper2.rb +8 -0
- data/test/helper.rb +16 -0
- data/test/test_code.rb +1 -1
- data/test/test_command.rb +364 -270
- data/test/test_command_integration.rb +235 -267
- data/test/test_completion.rb +36 -0
- data/test/test_control_d_handler.rb +45 -0
- data/test/test_default_commands/example.erb +5 -0
- data/test/test_default_commands/test_cd.rb +316 -11
- data/test/test_default_commands/test_context.rb +143 -192
- data/test/test_default_commands/test_documentation.rb +81 -14
- data/test/test_default_commands/test_find_method.rb +10 -2
- data/test/test_default_commands/test_input.rb +102 -111
- data/test/test_default_commands/test_introspection.rb +17 -12
- data/test/test_default_commands/test_ls.rb +8 -6
- data/test/test_default_commands/test_shell.rb +18 -15
- data/test/test_default_commands/test_show_source.rb +170 -44
- data/test/test_exception_whitelist.rb +6 -2
- data/test/test_hooks.rb +32 -0
- data/test/test_input_stack.rb +19 -16
- data/test/test_method.rb +0 -4
- data/test/test_prompt.rb +60 -0
- data/test/test_pry.rb +23 -31
- data/test/test_pry_defaults.rb +75 -57
- data/test/test_syntax_checking.rb +12 -11
- data/test/test_wrapped_module.rb +103 -0
- metadata +72 -26
data/test/test_code.rb
CHANGED
data/test/test_command.rb
CHANGED
@@ -213,7 +213,7 @@ describe "Pry::Command" do
|
|
213
213
|
it 'should provide opts and args as provided by slop' do
|
214
214
|
cmd = @set.create_command 'lintilla', "One of 800,000,000 clones" do
|
215
215
|
def options(opt)
|
216
|
-
opt.on :f, :four, "A numeric four", :as => Integer, :
|
216
|
+
opt.on :f, :four, "A numeric four", :as => Integer, :optional_argument => true
|
217
217
|
end
|
218
218
|
|
219
219
|
def process
|
@@ -342,285 +342,379 @@ describe "Pry::Command" do
|
|
342
342
|
end
|
343
343
|
end
|
344
344
|
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
it 'should accept multiline blocks' do
|
355
|
-
redirect_pry_io(InputTester.new("walking-spanish | do",
|
356
|
-
" :jesus",
|
357
|
-
"end",
|
358
|
-
"exit-all"), out = StringIO.new) do
|
359
|
-
Pry.start @context, :commands => @set
|
360
|
-
end
|
361
|
-
@context.instance_variable_get(:@x).should == :jesus
|
362
|
-
end
|
363
|
-
|
364
|
-
it 'should accept normal parameters along with block' do
|
365
|
-
@set.block_command "walking-spanish", "litella's been screeching for a blind pig.", :takes_block => true do |x, y|
|
366
|
-
inject_var(:@x, x, target)
|
367
|
-
inject_var(:@y, y, target)
|
368
|
-
inject_var(:@block_var, command_block.call, target)
|
369
|
-
end
|
370
|
-
redirect_pry_io(InputTester.new("walking-spanish john carl| { :jesus }",
|
371
|
-
"exit-all")) do
|
372
|
-
Pry.start @context, :commands => @set
|
373
|
-
end
|
374
|
-
|
375
|
-
@context.instance_variable_get(:@x).should == "john"
|
376
|
-
@context.instance_variable_get(:@y).should == "carl"
|
377
|
-
@context.instance_variable_get(:@block_var).should == :jesus
|
378
|
-
end
|
379
|
-
|
380
|
-
describe "single line blocks" do
|
381
|
-
it 'should accept blocks with do ; end' do
|
382
|
-
redirect_pry_io(InputTester.new("walking-spanish | do ; :jesus; end",
|
383
|
-
"exit-all"), out = StringIO.new) do
|
384
|
-
Pry.start @context, :commands => @set
|
385
|
-
end
|
386
|
-
@context.instance_variable_get(:@x).should == :jesus
|
387
|
-
end
|
345
|
+
describe "block parameters" do
|
346
|
+
before do
|
347
|
+
@context = Object.new
|
348
|
+
@set.command "walking-spanish", "down the hall", :takes_block => true do
|
349
|
+
inject_var(:@x, command_block.call, target)
|
350
|
+
end
|
351
|
+
@set.import Pry::Commands
|
352
|
+
end
|
388
353
|
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
354
|
+
it 'should accept multiline blocks' do
|
355
|
+
redirect_pry_io(InputTester.new("walking-spanish | do",
|
356
|
+
" :jesus",
|
357
|
+
"end",
|
358
|
+
"exit-all"), out = StringIO.new) do
|
359
|
+
Pry.start @context, :commands => @set
|
360
|
+
end
|
361
|
+
@context.instance_variable_get(:@x).should == :jesus
|
362
|
+
end
|
396
363
|
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
describe "block-related content removed from arguments" do
|
408
|
-
|
409
|
-
describe "arg_string" do
|
410
|
-
it 'should remove block-related content from arg_string (with one normal arg)' do
|
411
|
-
@set.block_command "walking-spanish", "down the hall", :takes_block => true do |x, y|
|
412
|
-
inject_var(:@arg_string, arg_string, target)
|
413
|
-
inject_var(:@x, x, target)
|
414
|
-
end
|
415
|
-
redirect_pry_io(InputTester.new("walking-spanish john| { :jesus }",
|
416
|
-
"exit-all")) do
|
417
|
-
Pry.start @context, :commands => @set
|
418
|
-
end
|
419
|
-
@context.instance_variable_get(:@arg_string).should == @context.instance_variable_get(:@x)
|
420
|
-
end
|
364
|
+
it 'should accept normal parameters along with block' do
|
365
|
+
@set.block_command "walking-spanish", "litella's been screeching for a blind pig.", :takes_block => true do |x, y|
|
366
|
+
inject_var(:@x, x, target)
|
367
|
+
inject_var(:@y, y, target)
|
368
|
+
inject_var(:@block_var, command_block.call, target)
|
369
|
+
end
|
370
|
+
redirect_pry_io(InputTester.new("walking-spanish john carl| { :jesus }",
|
371
|
+
"exit-all")) do
|
372
|
+
Pry.start @context, :commands => @set
|
373
|
+
end
|
421
374
|
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
redirect_pry_io(InputTester.new("walking-spanish | { :jesus }",
|
427
|
-
"exit-all")) do
|
428
|
-
Pry.start @context, :commands => @set
|
429
|
-
end
|
430
|
-
@context.instance_variable_get(:@arg_string).should == ""
|
431
|
-
end
|
375
|
+
@context.instance_variable_get(:@x).should == "john"
|
376
|
+
@context.instance_variable_get(:@y).should == "carl"
|
377
|
+
@context.instance_variable_get(:@block_var).should == :jesus
|
378
|
+
end
|
432
379
|
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
end
|
442
|
-
@context.instance_variable_get(:@arg_string).should == block_string
|
443
|
-
end
|
444
|
-
end
|
445
|
-
|
446
|
-
describe "args" do
|
447
|
-
describe "block_command" do
|
448
|
-
it "should remove block-related content from arguments" do
|
449
|
-
@set.block_command "walking-spanish", "glass is full of sand", :takes_block => true do |x, y|
|
450
|
-
inject_var(:@x, x, target)
|
451
|
-
inject_var(:@y, y, target)
|
452
|
-
end
|
453
|
-
redirect_pry_io(InputTester.new("walking-spanish | { :jesus }",
|
454
|
-
"exit-all"), out = StringIO.new) do
|
455
|
-
Pry.start @context, :commands => @set
|
456
|
-
end
|
457
|
-
@context.instance_variable_get(:@x).should == nil
|
458
|
-
@context.instance_variable_get(:@y).should == nil
|
459
|
-
end
|
460
|
-
|
461
|
-
it "should NOT remove block-related content from arguments if :takes_block => false" do
|
462
|
-
@set.block_command "walking-spanish", "litella screeching for a blind pig", :takes_block => false do |x, y|
|
463
|
-
inject_var(:@x, x, target)
|
464
|
-
inject_var(:@y, y, target)
|
465
|
-
end
|
466
|
-
redirect_pry_io(InputTester.new("walking-spanish | { :jesus }",
|
467
|
-
"exit-all"), out = StringIO.new) do
|
468
|
-
Pry.start @context, :commands => @set
|
469
|
-
end
|
470
|
-
@context.instance_variable_get(:@x).should == "|"
|
471
|
-
@context.instance_variable_get(:@y).should == "{"
|
472
|
-
end
|
473
|
-
end
|
380
|
+
describe "single line blocks" do
|
381
|
+
it 'should accept blocks with do ; end' do
|
382
|
+
redirect_pry_io(InputTester.new("walking-spanish | do ; :jesus; end",
|
383
|
+
"exit-all"), out = StringIO.new) do
|
384
|
+
Pry.start @context, :commands => @set
|
385
|
+
end
|
386
|
+
@context.instance_variable_get(:@x).should == :jesus
|
387
|
+
end
|
474
388
|
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
end
|
483
|
-
redirect_pry_io(InputTester.new("walking-spanish | { :jesus }",
|
484
|
-
"exit-all"), out = StringIO.new) do
|
485
|
-
Pry.start @context, :commands => @set
|
486
|
-
end
|
487
|
-
@context.instance_variable_get(:@x).should == nil
|
488
|
-
@context.instance_variable_get(:@y).should == nil
|
489
|
-
end
|
490
|
-
|
491
|
-
it "should NOT remove block-related content from arguments if :takes_block => false" do
|
492
|
-
@set.create_command "walking-spanish", "down the hall", :takes_block => false do
|
493
|
-
def process(x, y)
|
494
|
-
inject_var(:@x, x, target)
|
495
|
-
inject_var(:@y, y, target)
|
496
|
-
end
|
497
|
-
end
|
498
|
-
redirect_pry_io(InputTester.new("walking-spanish | { :jesus }",
|
499
|
-
"exit-all")) do
|
500
|
-
Pry.start @context, :commands => @set
|
501
|
-
end
|
502
|
-
@context.instance_variable_get(:@x).should == "|"
|
503
|
-
@context.instance_variable_get(:@y).should == "{"
|
504
|
-
end
|
505
|
-
end
|
506
|
-
end
|
507
|
-
end
|
508
|
-
|
509
|
-
describe "blocks can take parameters" do
|
510
|
-
describe "{} style blocks" do
|
511
|
-
it 'should accept multiple parameters' do
|
512
|
-
@set.block_command "walking-spanish", "down the hall", :takes_block => true do
|
513
|
-
inject_var(:@x, command_block.call(1, 2), target)
|
514
|
-
end
|
515
|
-
|
516
|
-
redirect_pry_io(InputTester.new("walking-spanish | { |x, y| [x, y] }",
|
517
|
-
"exit-all")) do
|
518
|
-
Pry.start @context, :commands => @set
|
519
|
-
end
|
520
|
-
@context.instance_variable_get(:@x).should == [1, 2]
|
521
|
-
end
|
522
|
-
end
|
523
|
-
|
524
|
-
describe "do/end style blocks" do
|
525
|
-
it 'should accept multiple parameters' do
|
526
|
-
@set.create_command "walking-spanish", "litella", :takes_block => true do
|
527
|
-
def process
|
528
|
-
inject_var(:@x, command_block.call(1, 2), target)
|
529
|
-
end
|
530
|
-
end
|
531
|
-
|
532
|
-
redirect_pry_io(InputTester.new("walking-spanish | do |x, y|",
|
533
|
-
" [x, y]",
|
534
|
-
"end",
|
535
|
-
"exit-all")) do
|
536
|
-
Pry.start @context, :commands => @set
|
537
|
-
end
|
538
|
-
@context.instance_variable_get(:@x).should == [1, 2]
|
539
|
-
end
|
540
|
-
end
|
541
|
-
end
|
542
|
-
|
543
|
-
describe "closure behaviour" do
|
544
|
-
it 'should close over locals in the definition context' do
|
545
|
-
redirect_pry_io(InputTester.new("var = :hello",
|
546
|
-
"walking-spanish | { var }",
|
547
|
-
"exit-all")) do
|
548
|
-
Pry.start @context, :commands => @set
|
549
|
-
end
|
550
|
-
@context.instance_variable_get(:@x).should == :hello
|
551
|
-
end
|
552
|
-
end
|
553
|
-
|
554
|
-
describe "exposing block parameter" do
|
555
|
-
describe "block_command" do
|
556
|
-
it "should expose block in command_block method" do
|
557
|
-
@set.block_command "walking-spanish", "glass full of sand", :takes_block => true do
|
558
|
-
inject_var(:@x, command_block.call, target)
|
559
|
-
end
|
560
|
-
redirect_pry_io(InputTester.new("walking-spanish | { :jesus }",
|
561
|
-
"exit-all")) do
|
562
|
-
Pry.start @context, :commands => @set
|
563
|
-
end
|
564
|
-
@context.instance_variable_get(:@x).should == :jesus
|
565
|
-
end
|
566
|
-
end
|
567
|
-
|
568
|
-
describe "create_command" do
|
569
|
-
it "should NOT expose &block in create_command's process method" do
|
570
|
-
@set.create_command "walking-spanish", "down the hall", :takes_block => true do
|
571
|
-
def process(&block)
|
572
|
-
inject_var(:@x, block.call, target)
|
573
|
-
end
|
574
|
-
end
|
575
|
-
redirect_pry_io(InputTester.new("walking-spanish | { :jesus }",
|
576
|
-
"exit-all")) do
|
577
|
-
Pry.start @context, :commands => @set
|
578
|
-
end
|
579
|
-
@context.instance_variable_get(:@x).should == nil
|
580
|
-
end
|
389
|
+
it 'should accept blocks with do; end' do
|
390
|
+
redirect_pry_io(InputTester.new("walking-spanish | do; :jesus; end",
|
391
|
+
"exit-all"), out = StringIO.new) do
|
392
|
+
Pry.start @context, :commands => @set
|
393
|
+
end
|
394
|
+
@context.instance_variable_get(:@x).should == :jesus
|
395
|
+
end
|
581
396
|
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
"exit-all"), out = StringIO.new) do
|
590
|
-
Pry.start @context, :commands => @set
|
591
|
-
end
|
592
|
-
@context.instance_variable_get(:@x).should == :jesus
|
593
|
-
end
|
594
|
-
end
|
595
|
-
end
|
596
|
-
end
|
397
|
+
it 'should accept blocks with { }' do
|
398
|
+
redirect_pry_io(InputTester.new("walking-spanish | { :jesus }",
|
399
|
+
"exit-all"), out = StringIO.new) do
|
400
|
+
Pry.start @context, :commands => @set
|
401
|
+
end
|
402
|
+
@context.instance_variable_get(:@x).should == :jesus
|
403
|
+
end
|
597
404
|
|
598
|
-
|
599
|
-
before do
|
405
|
+
end
|
600
406
|
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
407
|
+
describe "block-related content removed from arguments" do
|
408
|
+
|
409
|
+
describe "arg_string" do
|
410
|
+
it 'should remove block-related content from arg_string (with one normal arg)' do
|
411
|
+
@set.block_command "walking-spanish", "down the hall", :takes_block => true do |x, y|
|
412
|
+
inject_var(:@arg_string, arg_string, target)
|
413
|
+
inject_var(:@x, x, target)
|
414
|
+
end
|
415
|
+
redirect_pry_io(InputTester.new("walking-spanish john| { :jesus }",
|
416
|
+
"exit-all")) do
|
417
|
+
Pry.start @context, :commands => @set
|
418
|
+
end
|
419
|
+
@context.instance_variable_get(:@arg_string).should == @context.instance_variable_get(:@x)
|
420
|
+
end
|
605
421
|
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
422
|
+
it 'should remove block-related content from arg_string (with no normal args)' do
|
423
|
+
@set.block_command "walking-spanish", "down the hall", :takes_block => true do
|
424
|
+
inject_var(:@arg_string, arg_string, target)
|
425
|
+
end
|
426
|
+
redirect_pry_io(InputTester.new("walking-spanish | { :jesus }",
|
427
|
+
"exit-all")) do
|
428
|
+
Pry.start @context, :commands => @set
|
429
|
+
end
|
430
|
+
@context.instance_variable_get(:@arg_string).should == ""
|
431
|
+
end
|
610
432
|
|
611
|
-
|
612
|
-
|
433
|
+
it 'should NOT remove block-related content from arg_string when :takes_block => false' do
|
434
|
+
block_string = "| { :jesus }"
|
435
|
+
@set.block_command "walking-spanish", "homemade special", :takes_block => false do
|
436
|
+
inject_var(:@arg_string, arg_string, target)
|
437
|
+
end
|
438
|
+
redirect_pry_io(InputTester.new("walking-spanish #{block_string}",
|
439
|
+
"exit-all")) do
|
440
|
+
Pry.start @context, :commands => @set
|
441
|
+
end
|
442
|
+
@context.instance_variable_get(:@arg_string).should == block_string
|
443
|
+
end
|
444
|
+
end
|
613
445
|
|
614
|
-
|
615
|
-
|
616
|
-
|
446
|
+
describe "args" do
|
447
|
+
describe "block_command" do
|
448
|
+
it "should remove block-related content from arguments" do
|
449
|
+
@set.block_command "walking-spanish", "glass is full of sand", :takes_block => true do |x, y|
|
450
|
+
inject_var(:@x, x, target)
|
451
|
+
inject_var(:@y, y, target)
|
452
|
+
end
|
453
|
+
redirect_pry_io(InputTester.new("walking-spanish | { :jesus }",
|
454
|
+
"exit-all"), out = StringIO.new) do
|
455
|
+
Pry.start @context, :commands => @set
|
456
|
+
end
|
457
|
+
@context.instance_variable_get(:@x).should == nil
|
458
|
+
@context.instance_variable_get(:@y).should == nil
|
459
|
+
end
|
460
|
+
|
461
|
+
it "should NOT remove block-related content from arguments if :takes_block => false" do
|
462
|
+
@set.block_command "walking-spanish", "litella screeching for a blind pig", :takes_block => false do |x, y|
|
463
|
+
inject_var(:@x, x, target)
|
464
|
+
inject_var(:@y, y, target)
|
465
|
+
end
|
466
|
+
redirect_pry_io(InputTester.new("walking-spanish | { :jesus }",
|
467
|
+
"exit-all"), out = StringIO.new) do
|
468
|
+
Pry.start @context, :commands => @set
|
469
|
+
end
|
470
|
+
@context.instance_variable_get(:@x).should == "|"
|
471
|
+
@context.instance_variable_get(:@y).should == "{"
|
472
|
+
end
|
473
|
+
end
|
617
474
|
|
618
|
-
|
619
|
-
|
620
|
-
|
475
|
+
describe "create_command" do
|
476
|
+
it "should remove block-related content from arguments" do
|
477
|
+
@set.create_command "walking-spanish", "punk sanders carved one out of wood", :takes_block => true do
|
478
|
+
def process(x, y)
|
479
|
+
inject_var(:@x, x, target)
|
480
|
+
inject_var(:@y, y, target)
|
481
|
+
end
|
482
|
+
end
|
483
|
+
redirect_pry_io(InputTester.new("walking-spanish | { :jesus }",
|
484
|
+
"exit-all"), out = StringIO.new) do
|
485
|
+
Pry.start @context, :commands => @set
|
486
|
+
end
|
487
|
+
@context.instance_variable_get(:@x).should == nil
|
488
|
+
@context.instance_variable_get(:@y).should == nil
|
489
|
+
end
|
490
|
+
|
491
|
+
it "should NOT remove block-related content from arguments if :takes_block => false" do
|
492
|
+
@set.create_command "walking-spanish", "down the hall", :takes_block => false do
|
493
|
+
def process(x, y)
|
494
|
+
inject_var(:@x, x, target)
|
495
|
+
inject_var(:@y, y, target)
|
496
|
+
end
|
497
|
+
end
|
498
|
+
redirect_pry_io(InputTester.new("walking-spanish | { :jesus }",
|
499
|
+
"exit-all")) do
|
500
|
+
Pry.start @context, :commands => @set
|
501
|
+
end
|
502
|
+
@context.instance_variable_get(:@x).should == "|"
|
503
|
+
@context.instance_variable_get(:@y).should == "{"
|
504
|
+
end
|
505
|
+
end
|
506
|
+
end
|
507
|
+
end
|
621
508
|
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
509
|
+
describe "blocks can take parameters" do
|
510
|
+
describe "{} style blocks" do
|
511
|
+
it 'should accept multiple parameters' do
|
512
|
+
@set.block_command "walking-spanish", "down the hall", :takes_block => true do
|
513
|
+
inject_var(:@x, command_block.call(1, 2), target)
|
514
|
+
end
|
515
|
+
|
516
|
+
redirect_pry_io(InputTester.new("walking-spanish | { |x, y| [x, y] }",
|
517
|
+
"exit-all")) do
|
518
|
+
Pry.start @context, :commands => @set
|
519
|
+
end
|
520
|
+
@context.instance_variable_get(:@x).should == [1, 2]
|
521
|
+
end
|
522
|
+
end
|
523
|
+
|
524
|
+
describe "do/end style blocks" do
|
525
|
+
it 'should accept multiple parameters' do
|
526
|
+
@set.create_command "walking-spanish", "litella", :takes_block => true do
|
527
|
+
def process
|
528
|
+
inject_var(:@x, command_block.call(1, 2), target)
|
529
|
+
end
|
530
|
+
end
|
531
|
+
|
532
|
+
redirect_pry_io(InputTester.new("walking-spanish | do |x, y|",
|
533
|
+
" [x, y]",
|
534
|
+
"end",
|
535
|
+
"exit-all")) do
|
536
|
+
Pry.start @context, :commands => @set
|
537
|
+
end
|
538
|
+
@context.instance_variable_get(:@x).should == [1, 2]
|
539
|
+
end
|
540
|
+
end
|
541
|
+
end
|
542
|
+
|
543
|
+
describe "closure behaviour" do
|
544
|
+
it 'should close over locals in the definition context' do
|
545
|
+
redirect_pry_io(InputTester.new("var = :hello",
|
546
|
+
"walking-spanish | { var }",
|
547
|
+
"exit-all")) do
|
548
|
+
Pry.start @context, :commands => @set
|
549
|
+
end
|
550
|
+
@context.instance_variable_get(:@x).should == :hello
|
551
|
+
end
|
552
|
+
end
|
553
|
+
|
554
|
+
describe "exposing block parameter" do
|
555
|
+
describe "block_command" do
|
556
|
+
it "should expose block in command_block method" do
|
557
|
+
@set.block_command "walking-spanish", "glass full of sand", :takes_block => true do
|
558
|
+
inject_var(:@x, command_block.call, target)
|
559
|
+
end
|
560
|
+
redirect_pry_io(InputTester.new("walking-spanish | { :jesus }",
|
561
|
+
"exit-all")) do
|
562
|
+
Pry.start @context, :commands => @set
|
563
|
+
end
|
564
|
+
@context.instance_variable_get(:@x).should == :jesus
|
565
|
+
end
|
566
|
+
end
|
567
|
+
|
568
|
+
describe "create_command" do
|
569
|
+
it "should NOT expose &block in create_command's process method" do
|
570
|
+
@set.create_command "walking-spanish", "down the hall", :takes_block => true do
|
571
|
+
def process(&block)
|
572
|
+
inject_var(:@x, block.call, target)
|
573
|
+
end
|
574
|
+
end
|
575
|
+
redirect_pry_io(InputTester.new("walking-spanish | { :jesus }",
|
576
|
+
"exit-all")) do
|
577
|
+
Pry.start @context, :commands => @set
|
578
|
+
end
|
579
|
+
@context.instance_variable_get(:@x).should == nil
|
580
|
+
end
|
581
|
+
|
582
|
+
it "should expose block in command_block method" do
|
583
|
+
@set.create_command "walking-spanish", "homemade special", :takes_block => true do
|
584
|
+
def process
|
585
|
+
inject_var(:@x, command_block.call, target)
|
586
|
+
end
|
587
|
+
end
|
588
|
+
redirect_pry_io(InputTester.new("walking-spanish | { :jesus }",
|
589
|
+
"exit-all"), out = StringIO.new) do
|
590
|
+
Pry.start @context, :commands => @set
|
591
|
+
end
|
592
|
+
@context.instance_variable_get(:@x).should == :jesus
|
593
|
+
end
|
594
|
+
end
|
595
|
+
end
|
596
|
+
end
|
597
|
+
|
598
|
+
describe "commands made with custom sub-classes" do
|
599
|
+
before do
|
600
|
+
|
601
|
+
class MyTestCommand < Pry::ClassCommand
|
602
|
+
match /my-*test/
|
603
|
+
description "So just how many sound technicians does it take to change a lightbulb? 1? 2? 3? 1-2-3? Testing?"
|
604
|
+
options :shellwords => false, :listing => "my-test"
|
605
|
+
|
606
|
+
def process
|
607
|
+
output.puts command_name * 2
|
608
|
+
end
|
609
|
+
end
|
610
|
+
|
611
|
+
Pry.commands.add_command MyTestCommand
|
612
|
+
end
|
613
|
+
|
614
|
+
after do
|
615
|
+
Pry.commands.delete 'my-test'
|
616
|
+
end
|
617
|
+
|
618
|
+
it "should allow creating custom sub-classes of Pry::Command" do
|
619
|
+
mock_pry("my---test").should =~ /my-testmy-test/
|
620
|
+
end
|
621
|
+
|
622
|
+
it "should show the source of the process method" do
|
623
|
+
mock_pry("show-command my-test").should =~ /output.puts command_name/
|
624
|
+
end
|
625
|
+
end
|
626
|
+
|
627
|
+
describe "commands can save state" do
|
628
|
+
before do
|
629
|
+
@set = Pry::CommandSet.new do
|
630
|
+
create_command "litella", "desc" do
|
631
|
+
def process
|
632
|
+
state.my_state ||= 0
|
633
|
+
state.my_state += 1
|
634
|
+
end
|
635
|
+
end
|
636
|
+
|
637
|
+
create_command "sanders", "desc" do
|
638
|
+
def process
|
639
|
+
state.my_state = "wood"
|
640
|
+
end
|
641
|
+
end
|
642
|
+
|
643
|
+
create_command /[Hh]ello-world/, "desc" do
|
644
|
+
def process
|
645
|
+
state.my_state ||= 0
|
646
|
+
state.my_state += 2
|
647
|
+
end
|
648
|
+
end
|
649
|
+
|
650
|
+
end.import Pry::Commands
|
651
|
+
end
|
652
|
+
|
653
|
+
it 'should save state for the command on the Pry#command_state hash' do
|
654
|
+
instance = nil
|
655
|
+
redirect_pry_io(InputTester.new("litella",
|
656
|
+
"exit-all")) do
|
657
|
+
instance = Pry.new(:commands => @set)
|
658
|
+
instance.repl
|
659
|
+
end
|
660
|
+
|
661
|
+
instance.command_state["litella"].my_state.should == 1
|
662
|
+
end
|
663
|
+
|
664
|
+
it 'should ensure state is maintained between multiple invocations of command' do
|
665
|
+
instance = nil
|
666
|
+
redirect_pry_io(InputTester.new("litella", "litella",
|
667
|
+
"exit-all")) do
|
668
|
+
instance = Pry.new(:commands => @set)
|
669
|
+
instance.repl
|
670
|
+
end
|
671
|
+
|
672
|
+
instance.command_state["litella"].my_state.should == 2
|
673
|
+
end
|
674
|
+
|
675
|
+
it 'should ensure state with same name stored seperately for each command' do
|
676
|
+
instance = nil
|
677
|
+
redirect_pry_io(InputTester.new("litella", "sanders", "exit-all")) do
|
678
|
+
instance = Pry.new(:commands => @set)
|
679
|
+
instance.repl
|
680
|
+
end
|
681
|
+
|
682
|
+
instance.command_state["litella"].my_state.should == 1
|
683
|
+
instance.command_state["sanders"].my_state.should =="wood"
|
684
|
+
end
|
685
|
+
|
686
|
+
it 'should ensure state is properly saved for regex commands' do
|
687
|
+
instance = nil
|
688
|
+
redirect_pry_io(InputTester.new("hello-world", "Hello-world", "exit-all")) do
|
689
|
+
instance = Pry.new(:commands => @set)
|
690
|
+
instance.repl
|
691
|
+
end
|
692
|
+
|
693
|
+
instance.command_state[/[Hh]ello-world/].my_state.should == 4
|
694
|
+
end
|
695
|
+
end
|
696
|
+
|
697
|
+
describe 'group' do
|
698
|
+
before do
|
699
|
+
@set.import(
|
700
|
+
Pry::CommandSet.new do
|
701
|
+
create_command("magic") { group("Not for a public use") }
|
702
|
+
end
|
703
|
+
)
|
704
|
+
end
|
705
|
+
|
706
|
+
it 'should be correct for default commands' do
|
707
|
+
@set.commands["help"].group.should == "Help"
|
708
|
+
end
|
709
|
+
|
710
|
+
it 'should not change once it is initialized' do
|
711
|
+
@set.commands["magic"].group("-==CD COMMAND==-")
|
712
|
+
@set.commands["magic"].group.should == "Not for a public use"
|
713
|
+
end
|
714
|
+
|
715
|
+
it 'should not disappear after the call without parameters' do
|
716
|
+
@set.commands["magic"].group
|
717
|
+
@set.commands["magic"].group.should == "Not for a public use"
|
718
|
+
end
|
719
|
+
end
|
720
|
+
end
|