pry 0.8.4pre1 → 0.9.0pre1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.markdown +1 -1
- data/Rakefile +11 -5
- data/TODO +28 -2
- data/bin/pry +5 -9
- data/examples/example_basic.rb +2 -4
- data/examples/example_command_override.rb +2 -5
- data/examples/example_commands.rb +1 -4
- data/examples/example_hooks.rb +2 -5
- data/examples/example_image_edit.rb +4 -8
- data/examples/example_input.rb +1 -4
- data/examples/example_input2.rb +1 -4
- data/examples/example_output.rb +1 -4
- data/examples/example_print.rb +2 -5
- data/examples/example_prompt.rb +2 -5
- data/examples/helper.rb +6 -0
- data/lib/pry.rb +61 -4
- data/lib/pry/command_context.rb +10 -9
- data/lib/pry/command_processor.rb +29 -68
- data/lib/pry/command_set.rb +79 -28
- data/lib/pry/commands.rb +10 -121
- data/lib/pry/completion.rb +30 -29
- data/lib/pry/config.rb +93 -0
- data/lib/pry/default_commands/basic.rb +37 -0
- data/lib/pry/default_commands/context.rb +15 -15
- data/lib/pry/default_commands/documentation.rb +49 -48
- data/lib/pry/default_commands/easter_eggs.rb +1 -20
- data/lib/pry/default_commands/gems.rb +32 -41
- data/lib/pry/default_commands/input.rb +95 -19
- data/lib/pry/default_commands/introspection.rb +54 -60
- data/lib/pry/default_commands/ls.rb +2 -2
- data/lib/pry/default_commands/shell.rb +29 -39
- data/lib/pry/extended_commands/experimental.rb +48 -0
- data/lib/pry/extended_commands/user_command_api.rb +22 -0
- data/lib/pry/helpers.rb +1 -0
- data/lib/pry/helpers/base_helpers.rb +9 -106
- data/lib/pry/helpers/command_helpers.rb +96 -59
- data/lib/pry/helpers/text.rb +83 -0
- data/lib/pry/plugins.rb +79 -0
- data/lib/pry/pry_class.rb +96 -111
- data/lib/pry/pry_instance.rb +87 -55
- data/lib/pry/version.rb +1 -1
- data/test/helper.rb +56 -7
- data/test/test_command_processor.rb +99 -0
- data/test/{test_commandset.rb → test_command_set.rb} +18 -12
- data/test/test_default_commands.rb +59 -0
- data/test/test_default_commands/test_context.rb +64 -0
- data/test/test_default_commands/test_documentation.rb +31 -0
- data/test/test_default_commands/test_input.rb +157 -0
- data/test/test_default_commands/test_introspection.rb +146 -0
- data/test/test_pry.rb +430 -313
- metadata +25 -9
- data/lib/pry/hooks.rb +0 -17
- data/lib/pry/print.rb +0 -16
- data/lib/pry/prompts.rb +0 -31
data/test/test_pry.rb
CHANGED
@@ -135,13 +135,18 @@ describe Pry do
|
|
135
135
|
end
|
136
136
|
|
137
137
|
describe "test loading rc files" do
|
138
|
+
|
139
|
+
before do
|
140
|
+
Pry.instance_variable_set(:@initial_session, true)
|
141
|
+
end
|
142
|
+
|
138
143
|
after do
|
139
144
|
Pry::RC_FILES.clear
|
140
|
-
Pry.should_load_rc = false
|
145
|
+
Pry.config.should_load_rc = false
|
141
146
|
end
|
142
147
|
|
143
148
|
it "should run the rc file only once" do
|
144
|
-
Pry.should_load_rc = true
|
149
|
+
Pry.config.should_load_rc = true
|
145
150
|
Pry::RC_FILES << File.expand_path("../testrc", __FILE__)
|
146
151
|
|
147
152
|
Pry.start(self, :input => StringIO.new("exit\n"), :output => Pry::NullOutput)
|
@@ -153,17 +158,17 @@ describe Pry do
|
|
153
158
|
Object.remove_const(:TEST_RC)
|
154
159
|
end
|
155
160
|
|
156
|
-
it "should not run the rc file at all if Pry.should_load_rc is false" do
|
157
|
-
Pry.should_load_rc = false
|
161
|
+
it "should not run the rc file at all if Pry.config.should_load_rc is false" do
|
162
|
+
Pry.config.should_load_rc = false
|
158
163
|
Pry.start(self, :input => StringIO.new("exit\n"), :output => Pry::NullOutput)
|
159
164
|
Object.const_defined?(:TEST_RC).should == false
|
160
165
|
end
|
161
166
|
|
162
167
|
it "should not load the rc file if #repl method invoked" do
|
163
|
-
Pry.should_load_rc = true
|
168
|
+
Pry.config.should_load_rc = true
|
164
169
|
Pry.new(:input => StringIO.new("exit\n"), :output => Pry::NullOutput).repl(self)
|
165
170
|
Object.const_defined?(:TEST_RC).should == false
|
166
|
-
Pry.should_load_rc = false
|
171
|
+
Pry.config.should_load_rc = false
|
167
172
|
end
|
168
173
|
end
|
169
174
|
|
@@ -219,10 +224,8 @@ describe Pry do
|
|
219
224
|
val.class.instance_methods(false).map(&:to_sym).include?(:hello).should == true
|
220
225
|
end
|
221
226
|
end
|
222
|
-
|
223
227
|
end
|
224
228
|
|
225
|
-
|
226
229
|
describe "commands" do
|
227
230
|
it 'should run a command with no parameter' do
|
228
231
|
pry_tester = Pry.new
|
@@ -386,70 +389,143 @@ describe Pry do
|
|
386
389
|
str_output2.string.should =~ /7/
|
387
390
|
end
|
388
391
|
|
389
|
-
# describe "Pry.run_command" do
|
390
|
-
# before do
|
391
|
-
# class RCTest
|
392
|
-
# def a() end
|
393
|
-
# B = 20
|
394
|
-
# @x = 10
|
395
|
-
# end
|
396
|
-
# end
|
397
|
-
|
398
|
-
# after do
|
399
|
-
# Object.remove_const(:RCTest)
|
400
|
-
# end
|
401
|
-
|
402
|
-
# it "should execute command in the appropriate object context" do
|
403
|
-
# result = Pry.run_command "ls", :context => RCTest
|
404
|
-
# result.map(&:to_sym).should == [:@x]
|
405
|
-
# end
|
406
|
-
|
407
|
-
# it "should execute command with parameters in the appropriate object context" do
|
408
|
-
# result = Pry.run_command "ls -M", :context => RCTest
|
409
|
-
# result.map(&:to_sym).should == [:a]
|
410
|
-
# end
|
411
|
-
|
412
|
-
# it "should execute command and show output with :show_output => true flag" do
|
413
|
-
# str = StringIO.new
|
414
|
-
# Pry.output = str
|
415
|
-
# result = Pry.run_command "ls -afv", :context => RCTest, :show_output => true
|
416
|
-
# str.string.should =~ /global variables/
|
417
|
-
# Pry.output = $stdout
|
418
|
-
# end
|
419
|
-
|
420
|
-
# it "should execute command with multiple parameters" do
|
421
|
-
# result = Pry.run_command "ls -c -M RCTest"
|
422
|
-
# result.map(&:to_sym).should == [:a, :B]
|
423
|
-
# end
|
424
|
-
# end
|
425
|
-
|
426
392
|
describe "commands" do
|
427
393
|
it 'should interpolate ruby code into commands' do
|
428
|
-
klass = Pry::CommandSet.new
|
394
|
+
klass = Pry::CommandSet.new do
|
429
395
|
command "hello", "", :keep_retval => true do |arg|
|
430
396
|
arg
|
431
397
|
end
|
432
398
|
end
|
433
399
|
|
434
|
-
|
400
|
+
$test_interpolation = "bing"
|
435
401
|
str_output = StringIO.new
|
436
|
-
Pry.new(:input => StringIO.new(
|
402
|
+
Pry.new(:input => StringIO.new('hello #{$test_interpolation}'), :output => str_output, :commands => klass).rep
|
437
403
|
str_output.string.should =~ /bing/
|
438
|
-
|
404
|
+
$test_interpolation = nil
|
405
|
+
end
|
406
|
+
|
407
|
+
it 'should NOT interpolate ruby code into commands if :interpolate => false' do
|
408
|
+
klass = Pry::CommandSet.new do
|
409
|
+
command "hello", "", :keep_retval => true, :interpolate => false do |arg|
|
410
|
+
arg
|
411
|
+
end
|
412
|
+
end
|
413
|
+
|
414
|
+
$test_interpolation = "bing"
|
415
|
+
str_output = StringIO.new
|
416
|
+
Pry.new(:input => StringIO.new('hello #{$test_interpolation}'), :output => str_output, :commands => klass).rep
|
417
|
+
str_output.string.should =~ /test_interpolation/
|
418
|
+
$test_interpolation = nil
|
419
|
+
end
|
420
|
+
|
421
|
+
it 'should create a command with a space in its name' do
|
422
|
+
set = Pry::CommandSet.new do
|
423
|
+
command "hello baby", "" do
|
424
|
+
output.puts "hello baby command"
|
425
|
+
end
|
426
|
+
end
|
427
|
+
|
428
|
+
str_output = StringIO.new
|
429
|
+
redirect_pry_io(InputTester.new("hello baby", "exit-all"), str_output) do
|
430
|
+
Pry.new(:commands => set).rep
|
431
|
+
end
|
432
|
+
|
433
|
+
str_output.string.should =~ /hello baby command/
|
434
|
+
end
|
435
|
+
|
436
|
+
it 'should create a command with a space in its name and pass an argument' do
|
437
|
+
set = Pry::CommandSet.new do
|
438
|
+
command "hello baby", "" do |arg|
|
439
|
+
output.puts "hello baby command #{arg}"
|
440
|
+
end
|
441
|
+
end
|
442
|
+
|
443
|
+
str_output = StringIO.new
|
444
|
+
redirect_pry_io(InputTester.new("hello baby john"), str_output) do
|
445
|
+
Pry.new(:commands => set).rep
|
446
|
+
end
|
447
|
+
|
448
|
+
str_output.string.should =~ /hello baby command john/
|
449
|
+
end
|
450
|
+
|
451
|
+
it 'should create a regex command and be able to invoke it' do
|
452
|
+
set = Pry::CommandSet.new do
|
453
|
+
command /hello(.)/, "" do
|
454
|
+
c = captures.first
|
455
|
+
output.puts "hello#{c}"
|
456
|
+
end
|
457
|
+
end
|
458
|
+
|
459
|
+
str_output = StringIO.new
|
460
|
+
redirect_pry_io(InputTester.new("hello1"), str_output) do
|
461
|
+
Pry.new(:commands => set).rep
|
462
|
+
end
|
463
|
+
|
464
|
+
str_output.string.should =~ /hello1/
|
465
|
+
end
|
466
|
+
|
467
|
+
it 'should create a regex command and pass captures into the args list before regular arguments' do
|
468
|
+
set = Pry::CommandSet.new do
|
469
|
+
command /hello(.)/, "" do |c1, a1|
|
470
|
+
output.puts "hello #{c1} #{a1}"
|
471
|
+
end
|
472
|
+
end
|
473
|
+
|
474
|
+
str_output = StringIO.new
|
475
|
+
redirect_pry_io(InputTester.new("hello1 baby"), str_output) do
|
476
|
+
Pry.new(:commands => set).rep
|
477
|
+
end
|
478
|
+
|
479
|
+
str_output.string.should =~ /hello 1 baby/
|
480
|
+
end
|
481
|
+
|
482
|
+
it 'should create a regex command and interpolate the captures' do
|
483
|
+
set = Pry::CommandSet.new do
|
484
|
+
command /hello (.*)/, "" do |c1|
|
485
|
+
output.puts "hello #{c1}"
|
486
|
+
end
|
487
|
+
end
|
488
|
+
|
489
|
+
str_output = StringIO.new
|
490
|
+
$obj = "bing"
|
491
|
+
redirect_pry_io(InputTester.new('hello #{$obj}'), str_output) do
|
492
|
+
Pry.new(:commands => set).rep
|
493
|
+
end
|
494
|
+
|
495
|
+
# binding.pry
|
496
|
+
str_output.string.should =~ /hello bing/
|
497
|
+
$obj = nil
|
439
498
|
end
|
440
499
|
|
441
|
-
it '
|
442
|
-
|
500
|
+
it 'if a regex capture is missing it should be nil' do
|
501
|
+
set = Pry::CommandSet.new do
|
502
|
+
command /hello(.)?/, "" do |c1, a1|
|
503
|
+
output.puts "hello #{c1.inspect} #{a1}"
|
504
|
+
end
|
505
|
+
end
|
506
|
+
|
443
507
|
str_output = StringIO.new
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
str_output.string.should =~
|
508
|
+
redirect_pry_io(InputTester.new("hello baby"), str_output) do
|
509
|
+
Pry.new(:commands => set).rep
|
510
|
+
end
|
511
|
+
|
512
|
+
str_output.string.should =~ /hello nil baby/
|
513
|
+
end
|
514
|
+
|
515
|
+
it 'should create a command in a nested context and that command should be accessible from the parent' do
|
516
|
+
redirect_pry_io(StringIO.new, StringIO.new) do
|
517
|
+
str_input = StringIO.new("@x=nil\ncd 7\n_pry_.commands.instance_eval {\ncommand('bing') { |arg| run arg }\n}\ncd ..\nbing ls\nexit")
|
518
|
+
str_output = StringIO.new
|
519
|
+
Pry.input = str_input
|
520
|
+
obj = Object.new
|
521
|
+
Pry.new(:output => str_output).repl(obj)
|
522
|
+
Pry.input = Readline
|
523
|
+
str_output.string.should =~ /@x/
|
524
|
+
end
|
449
525
|
end
|
450
526
|
|
451
527
|
it 'should define a command that keeps its return value' do
|
452
|
-
klass = Pry::CommandSet.new
|
528
|
+
klass = Pry::CommandSet.new do
|
453
529
|
command "hello", "", :keep_retval => true do
|
454
530
|
:kept_hello
|
455
531
|
end
|
@@ -461,7 +537,7 @@ describe Pry do
|
|
461
537
|
end
|
462
538
|
|
463
539
|
it 'should define a command that does NOT keep its return value' do
|
464
|
-
klass = Pry::CommandSet.new
|
540
|
+
klass = Pry::CommandSet.new do
|
465
541
|
command "hello", "", :keep_retval => false do
|
466
542
|
:kept_hello
|
467
543
|
end
|
@@ -469,11 +545,11 @@ describe Pry do
|
|
469
545
|
str_output = StringIO.new
|
470
546
|
Pry.new(:input => StringIO.new("hello\n"), :output => str_output, :commands => klass).rep
|
471
547
|
(str_output.string =~ /:kept_hello/).should == nil
|
472
|
-
|
548
|
+
str_output.string !~ /=>/
|
473
549
|
end
|
474
550
|
|
475
551
|
it 'should set the commands default, and the default should be overridable' do
|
476
|
-
klass = Pry::CommandSet.new
|
552
|
+
klass = Pry::CommandSet.new do
|
477
553
|
command "hello" do
|
478
554
|
output.puts "hello world"
|
479
555
|
end
|
@@ -485,342 +561,383 @@ describe Pry do
|
|
485
561
|
Pry.new(:input => InputTester.new("hello"), :output => str_output).rep
|
486
562
|
str_output.string.should =~ /hello world/
|
487
563
|
|
488
|
-
|
489
|
-
|
490
|
-
|
564
|
+
other_klass = Pry::CommandSet.new do
|
565
|
+
command "goodbye", "" do
|
566
|
+
output.puts "goodbye world"
|
567
|
+
end
|
491
568
|
end
|
492
|
-
end
|
493
569
|
|
494
|
-
|
570
|
+
str_output = StringIO.new
|
495
571
|
|
496
|
-
|
497
|
-
|
498
|
-
|
572
|
+
Pry.new(:input => InputTester.new("goodbye"), :output => str_output, :commands => other_klass).rep
|
573
|
+
str_output.string.should =~ /goodbye world/
|
574
|
+
end
|
499
575
|
|
500
|
-
|
501
|
-
|
502
|
-
|
576
|
+
it 'should inherit "help" command from Pry::CommandBase' do
|
577
|
+
klass = Pry::CommandSet.new do
|
578
|
+
command "h", "h command" do
|
579
|
+
end
|
503
580
|
end
|
504
|
-
end
|
505
581
|
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
582
|
+
klass.commands.keys.size.should == 3
|
583
|
+
klass.commands.keys.include?("help").should == true
|
584
|
+
klass.commands.keys.include?("install").should == true
|
585
|
+
klass.commands.keys.include?("h").should == true
|
586
|
+
end
|
511
587
|
|
512
|
-
|
513
|
-
|
514
|
-
|
588
|
+
it 'should inherit commands from Pry::Commands' do
|
589
|
+
klass = Pry::CommandSet.new Pry::Commands do
|
590
|
+
command "v" do
|
591
|
+
end
|
515
592
|
end
|
593
|
+
|
594
|
+
klass.commands.include?("nesting").should == true
|
595
|
+
klass.commands.include?("jump-to").should == true
|
596
|
+
klass.commands.include?("cd").should == true
|
597
|
+
klass.commands.include?("v").should == true
|
516
598
|
end
|
517
599
|
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
600
|
+
it 'should alias a command with another command' do
|
601
|
+
klass = Pry::CommandSet.new do
|
602
|
+
alias_command "help2", "help"
|
603
|
+
end
|
604
|
+
klass.commands["help2"].block.should == klass.commands["help"].block
|
605
|
+
end
|
523
606
|
|
524
|
-
|
525
|
-
klass = Pry::CommandSet.new
|
526
|
-
|
607
|
+
it 'should change description of a command using desc' do
|
608
|
+
klass = Pry::CommandSet.new do; end
|
609
|
+
orig = klass.commands["help"].description
|
610
|
+
klass.instance_eval do
|
611
|
+
desc "help", "blah"
|
612
|
+
end
|
613
|
+
klass.commands["help"].description.should.not == orig
|
614
|
+
klass.commands["help"].description.should == "blah"
|
527
615
|
end
|
528
616
|
|
617
|
+
it 'should run a command from within a command' do
|
618
|
+
klass = Pry::CommandSet.new do
|
619
|
+
command "v" do
|
620
|
+
output.puts "v command"
|
621
|
+
end
|
529
622
|
|
530
|
-
|
531
|
-
|
623
|
+
command "run_v" do
|
624
|
+
run "v"
|
625
|
+
end
|
626
|
+
end
|
532
627
|
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
klass.instance_eval do
|
537
|
-
desc "help", "blah"
|
628
|
+
str_output = StringIO.new
|
629
|
+
Pry.new(:input => InputTester.new("run_v"), :output => str_output, :commands => klass).rep
|
630
|
+
str_output.string.should =~ /v command/
|
538
631
|
end
|
539
|
-
klass.commands["help"].description.should.not == orig
|
540
|
-
klass.commands["help"].description.should == "blah"
|
541
|
-
end
|
542
632
|
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
633
|
+
it 'should run a regex command from within a command' do
|
634
|
+
klass = Pry::CommandSet.new do
|
635
|
+
command /v(.*)?/ do |arg|
|
636
|
+
output.puts "v #{arg}"
|
637
|
+
end
|
638
|
+
|
639
|
+
command "run_v" do
|
640
|
+
run "vbaby"
|
641
|
+
end
|
547
642
|
end
|
548
643
|
|
549
|
-
|
550
|
-
|
644
|
+
str_output = StringIO.new
|
645
|
+
redirect_pry_io(InputTester.new("run_v"), str_output) do
|
646
|
+
Pry.new(:commands => klass).rep
|
551
647
|
end
|
648
|
+
|
649
|
+
str_output.string.should =~ /v baby/
|
552
650
|
end
|
553
651
|
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
652
|
+
it 'should run a command from within a command with arguments' do
|
653
|
+
klass = Pry::CommandSet.new do
|
654
|
+
command /v(\w+)/ do |arg1, arg2|
|
655
|
+
output.puts "v #{arg1} #{arg2}"
|
656
|
+
end
|
558
657
|
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
658
|
+
command "run_v_explicit_parameter" do
|
659
|
+
run "vbaby", "param"
|
660
|
+
end
|
661
|
+
|
662
|
+
command "run_v_embedded_parameter" do
|
663
|
+
run "vbaby param"
|
664
|
+
end
|
563
665
|
end
|
564
|
-
end
|
565
666
|
|
566
|
-
|
667
|
+
["run_v_explicit_parameter", "run_v_embedded_parameter"].each do |cmd|
|
668
|
+
str_output = StringIO.new
|
669
|
+
redirect_pry_io(InputTester.new(cmd), str_output) do
|
670
|
+
Pry.new(:commands => klass).rep
|
671
|
+
end
|
672
|
+
str_output.string.should =~ /v baby param/
|
673
|
+
end
|
567
674
|
end
|
568
675
|
|
569
|
-
|
570
|
-
|
571
|
-
|
676
|
+
it 'should enable an inherited method to access opts and output and target, due to instance_exec' do
|
677
|
+
klass = Pry::CommandSet.new do
|
678
|
+
command "v" do
|
679
|
+
output.puts "#{target.eval('self')}"
|
680
|
+
end
|
681
|
+
end
|
572
682
|
|
573
|
-
|
574
|
-
|
683
|
+
child_klass = Pry::CommandSet.new klass do
|
684
|
+
end
|
685
|
+
|
686
|
+
str_output = StringIO.new
|
687
|
+
Pry.new(:print => proc {}, :input => InputTester.new("v"),
|
688
|
+
:output => str_output, :commands => child_klass).rep("john")
|
575
689
|
|
576
|
-
|
577
|
-
klass = Pry::CommandSet.new :test do
|
578
|
-
import_from Pry::Commands, "ls", "jump-to"
|
690
|
+
str_output.string.rstrip.should == "john"
|
579
691
|
end
|
580
692
|
|
693
|
+
it 'should import commands from another command object' do
|
694
|
+
klass = Pry::CommandSet.new do
|
695
|
+
import_from Pry::Commands, "ls", "jump-to"
|
696
|
+
end
|
697
|
+
|
581
698
|
klass.commands.include?("ls").should == true
|
582
699
|
klass.commands.include?("jump-to").should == true
|
583
700
|
end
|
584
701
|
|
585
|
-
|
586
|
-
|
587
|
-
|
702
|
+
it 'should delete some inherited commands when using delete method' do
|
703
|
+
klass = Pry::CommandSet.new Pry::Commands do
|
704
|
+
command "v" do
|
705
|
+
end
|
706
|
+
|
707
|
+
delete "show-doc", "show-method"
|
708
|
+
delete "ls"
|
588
709
|
end
|
589
710
|
|
590
|
-
|
591
|
-
|
711
|
+
klass.commands.include?("nesting").should == true
|
712
|
+
klass.commands.include?("jump-to").should == true
|
713
|
+
klass.commands.include?("cd").should == true
|
714
|
+
klass.commands.include?("v").should == true
|
715
|
+
klass.commands.include?("show-doc").should == false
|
716
|
+
klass.commands.include?("show-method").should == false
|
717
|
+
klass.commands.include?("ls").should == false
|
592
718
|
end
|
593
719
|
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
klass.commands.include?("show-method").should == false
|
600
|
-
klass.commands.include?("ls").should == false
|
601
|
-
end
|
720
|
+
it 'should override some inherited commands' do
|
721
|
+
klass = Pry::CommandSet.new Pry::Commands do
|
722
|
+
command "jump-to" do
|
723
|
+
output.puts "jump-to the music"
|
724
|
+
end
|
602
725
|
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
output.puts "jump-to the music"
|
726
|
+
command "help" do
|
727
|
+
output.puts "help to the music"
|
728
|
+
end
|
607
729
|
end
|
608
730
|
|
609
|
-
|
610
|
-
|
611
|
-
end
|
612
|
-
end
|
731
|
+
# suppress evaluation output
|
732
|
+
Pry.print = proc {}
|
613
733
|
|
614
|
-
|
615
|
-
|
734
|
+
str_output = StringIO.new
|
735
|
+
Pry.new(:input => InputTester.new("jump-to"), :output => str_output, :commands => klass).rep
|
736
|
+
str_output.string.rstrip.should == "jump-to the music"
|
616
737
|
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
str_output = StringIO.new
|
622
|
-
Pry.new(:input => InputTester.new("help"), :output => str_output, :commands => klass).rep
|
623
|
-
str_output.string.rstrip.should == "help to the music"
|
738
|
+
str_output = StringIO.new
|
739
|
+
Pry.new(:input => InputTester.new("help"), :output => str_output, :commands => klass).rep
|
740
|
+
str_output.string.rstrip.should == "help to the music"
|
624
741
|
|
625
742
|
|
626
|
-
|
627
|
-
|
743
|
+
Pry.reset_defaults
|
744
|
+
Pry.color = false
|
745
|
+
end
|
628
746
|
end
|
629
|
-
end
|
630
747
|
|
631
|
-
|
632
|
-
|
633
|
-
|
748
|
+
it "should set the print default, and the default should be overridable" do
|
749
|
+
new_print = proc { |out, value| out.puts value }
|
750
|
+
Pry.print = new_print
|
634
751
|
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
str_output = StringIO.new
|
641
|
-
Pry.new(:input => InputTester.new("\"test\""), :output => str_output,
|
642
|
-
:print => proc { |out, value| out.puts value.reverse }).rep
|
643
|
-
str_output.string.should == "tset\n"
|
752
|
+
Pry.new.print.should == Pry.print
|
753
|
+
str_output = StringIO.new
|
754
|
+
Pry.new(:input => InputTester.new("\"test\""), :output => str_output).rep
|
755
|
+
str_output.string.should == "test\n"
|
644
756
|
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
end
|
757
|
+
str_output = StringIO.new
|
758
|
+
Pry.new(:input => InputTester.new("\"test\""), :output => str_output,
|
759
|
+
:print => proc { |out, value| out.puts value.reverse }).rep
|
760
|
+
str_output.string.should == "tset\n"
|
650
761
|
|
651
|
-
|
652
|
-
|
653
|
-
Pry.
|
762
|
+
Pry.new.print.should == Pry.print
|
763
|
+
str_output = StringIO.new
|
764
|
+
Pry.new(:input => InputTester.new("\"test\""), :output => str_output).rep
|
765
|
+
str_output.string.should == "test\n"
|
654
766
|
end
|
655
767
|
|
656
|
-
|
657
|
-
|
658
|
-
|
768
|
+
describe "pry return values" do
|
769
|
+
it 'should return the target object' do
|
770
|
+
Pry.start(self, :input => StringIO.new("exit"), :output => Pry::NullOutput).should == self
|
771
|
+
end
|
659
772
|
|
660
|
-
|
661
|
-
|
662
|
-
|
773
|
+
it 'should return the parameter given to exit' do
|
774
|
+
Pry.start(self, :input => StringIO.new("exit 10"), :output => Pry::NullOutput).should == 10
|
775
|
+
end
|
663
776
|
|
664
|
-
|
665
|
-
|
666
|
-
|
777
|
+
it 'should return the parameter (multi word string) given to exit' do
|
778
|
+
Pry.start(self, :input => StringIO.new("exit \"john mair\""), :output => Pry::NullOutput).should == "john mair"
|
779
|
+
end
|
667
780
|
|
668
|
-
|
669
|
-
|
781
|
+
it 'should return the parameter (function call) given to exit' do
|
782
|
+
Pry.start(self, :input => StringIO.new("exit 'abc'.reverse"), :output => Pry::NullOutput).should == 'cba'
|
783
|
+
end
|
784
|
+
|
785
|
+
it 'should return the parameter (self) given to exit' do
|
786
|
+
Pry.start("carl", :input => StringIO.new("exit self"), :output => Pry::NullOutput).should == "carl"
|
787
|
+
end
|
670
788
|
end
|
671
|
-
end
|
672
789
|
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
790
|
+
describe "prompts" do
|
791
|
+
it 'should set the prompt default, and the default should be overridable (single prompt)' do
|
792
|
+
new_prompt = proc { "test prompt> " }
|
793
|
+
Pry.prompt = new_prompt
|
677
794
|
|
678
|
-
|
679
|
-
|
680
|
-
|
795
|
+
Pry.new.prompt.should == Pry.prompt
|
796
|
+
Pry.new.select_prompt(true, 0).should == "test prompt> "
|
797
|
+
Pry.new.select_prompt(false, 0).should == "test prompt> "
|
681
798
|
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
799
|
+
new_prompt = proc { "A" }
|
800
|
+
pry_tester = Pry.new(:prompt => new_prompt)
|
801
|
+
pry_tester.prompt.should == new_prompt
|
802
|
+
pry_tester.select_prompt(true, 0).should == "A"
|
803
|
+
pry_tester.select_prompt(false, 0).should == "A"
|
687
804
|
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
805
|
+
Pry.new.prompt.should == Pry.prompt
|
806
|
+
Pry.new.select_prompt(true, 0).should == "test prompt> "
|
807
|
+
Pry.new.select_prompt(false, 0).should == "test prompt> "
|
808
|
+
end
|
692
809
|
|
693
|
-
|
694
|
-
|
695
|
-
|
810
|
+
it 'should set the prompt default, and the default should be overridable (multi prompt)' do
|
811
|
+
new_prompt = [proc { "test prompt> " }, proc { "test prompt* " }]
|
812
|
+
Pry.prompt = new_prompt
|
696
813
|
|
697
|
-
|
698
|
-
|
699
|
-
|
814
|
+
Pry.new.prompt.should == Pry.prompt
|
815
|
+
Pry.new.select_prompt(true, 0).should == "test prompt> "
|
816
|
+
Pry.new.select_prompt(false, 0).should == "test prompt* "
|
700
817
|
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
818
|
+
new_prompt = [proc { "A" }, proc { "B" }]
|
819
|
+
pry_tester = Pry.new(:prompt => new_prompt)
|
820
|
+
pry_tester.prompt.should == new_prompt
|
821
|
+
pry_tester.select_prompt(true, 0).should == "A"
|
822
|
+
pry_tester.select_prompt(false, 0).should == "B"
|
706
823
|
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
824
|
+
Pry.new.prompt.should == Pry.prompt
|
825
|
+
Pry.new.select_prompt(true, 0).should == "test prompt> "
|
826
|
+
Pry.new.select_prompt(false, 0).should == "test prompt* "
|
827
|
+
end
|
711
828
|
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
@pry.prompt.should == @b
|
728
|
-
@pry.pop_prompt
|
729
|
-
@pry.prompt.should == @a
|
730
|
-
end
|
731
|
-
|
732
|
-
it 'should restore overridden prompts when returning from file-mode' do
|
733
|
-
pry = Pry.new :input => InputTester.new('shell-mode', 'shell-mode'),
|
734
|
-
:prompt => [ proc { 'P>' } ] * 2
|
735
|
-
pry.select_prompt(true, 0).should == "P>"
|
736
|
-
pry.re
|
737
|
-
pry.select_prompt(true, 0).should =~ /\Apry .* \$ \z/
|
738
|
-
pry.re
|
739
|
-
pry.select_prompt(true, 0).should == "P>"
|
740
|
-
end
|
741
|
-
|
742
|
-
it '#pop_prompt should return the popped prompt' do
|
743
|
-
@pry.push_prompt @b
|
744
|
-
@pry.push_prompt @c
|
745
|
-
@pry.pop_prompt.should == @c
|
746
|
-
@pry.pop_prompt.should == @b
|
747
|
-
end
|
748
|
-
|
749
|
-
it 'should not pop the last prompt' do
|
750
|
-
@pry.push_prompt @b
|
751
|
-
@pry.pop_prompt.should == @b
|
752
|
-
@pry.pop_prompt.should == @a
|
753
|
-
@pry.pop_prompt.should == @a
|
754
|
-
@pry.prompt.should == @a
|
755
|
-
end
|
756
|
-
|
757
|
-
describe '#prompt= should replace the current prompt with the new prompt' do
|
758
|
-
it 'when only one prompt on the stack' do
|
759
|
-
@pry.prompt = @b
|
829
|
+
describe 'storing and restoring the prompt' do
|
830
|
+
before do
|
831
|
+
make = lambda do |name,i|
|
832
|
+
prompt = [ proc { "#{i}>" } , proc { "#{i+1}>" } ]
|
833
|
+
(class << prompt; self; end).send(:define_method, :inspect) { "<Prompt-#{name}>" }
|
834
|
+
prompt
|
835
|
+
end
|
836
|
+
@a , @b , @c = make[:a,0] , make[:b,1] , make[:c,2]
|
837
|
+
@pry = Pry.new :prompt => @a
|
838
|
+
end
|
839
|
+
it 'should have a prompt stack' do
|
840
|
+
@pry.push_prompt @b
|
841
|
+
@pry.push_prompt @c
|
842
|
+
@pry.prompt.should == @c
|
843
|
+
@pry.pop_prompt
|
760
844
|
@pry.prompt.should == @b
|
761
|
-
@pry.pop_prompt
|
762
|
-
@pry.
|
845
|
+
@pry.pop_prompt
|
846
|
+
@pry.prompt.should == @a
|
847
|
+
end
|
848
|
+
|
849
|
+
it 'should restore overridden prompts when returning from file-mode' do
|
850
|
+
pry = Pry.new :input => InputTester.new('shell-mode', 'shell-mode'),
|
851
|
+
:prompt => [ proc { 'P>' } ] * 2
|
852
|
+
pry.select_prompt(true, 0).should == "P>"
|
853
|
+
pry.re
|
854
|
+
pry.select_prompt(true, 0).should =~ /\Apry .* \$ \z/
|
855
|
+
pry.re
|
856
|
+
pry.select_prompt(true, 0).should == "P>"
|
763
857
|
end
|
764
|
-
|
858
|
+
|
859
|
+
it '#pop_prompt should return the popped prompt' do
|
765
860
|
@pry.push_prompt @b
|
766
|
-
@pry.
|
861
|
+
@pry.push_prompt @c
|
767
862
|
@pry.pop_prompt.should == @c
|
863
|
+
@pry.pop_prompt.should == @b
|
864
|
+
end
|
865
|
+
|
866
|
+
it 'should not pop the last prompt' do
|
867
|
+
@pry.push_prompt @b
|
868
|
+
@pry.pop_prompt.should == @b
|
869
|
+
@pry.pop_prompt.should == @a
|
768
870
|
@pry.pop_prompt.should == @a
|
871
|
+
@pry.prompt.should == @a
|
872
|
+
end
|
873
|
+
|
874
|
+
describe '#prompt= should replace the current prompt with the new prompt' do
|
875
|
+
it 'when only one prompt on the stack' do
|
876
|
+
@pry.prompt = @b
|
877
|
+
@pry.prompt.should == @b
|
878
|
+
@pry.pop_prompt.should == @b
|
879
|
+
@pry.pop_prompt.should == @b
|
880
|
+
end
|
881
|
+
it 'when several prompts on the stack' do
|
882
|
+
@pry.push_prompt @b
|
883
|
+
@pry.prompt = @c
|
884
|
+
@pry.pop_prompt.should == @c
|
885
|
+
@pry.pop_prompt.should == @a
|
886
|
+
end
|
769
887
|
end
|
770
888
|
end
|
771
889
|
end
|
772
|
-
end
|
773
890
|
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
891
|
+
it 'should set the hooks default, and the default should be overridable' do
|
892
|
+
Pry.input = InputTester.new("exit")
|
893
|
+
Pry.hooks = {
|
894
|
+
:before_session => proc { |out,_| out.puts "HELLO" },
|
895
|
+
:after_session => proc { |out,_| out.puts "BYE" }
|
896
|
+
}
|
780
897
|
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
898
|
+
str_output = StringIO.new
|
899
|
+
Pry.new(:output => str_output).repl
|
900
|
+
str_output.string.should =~ /HELLO/
|
901
|
+
str_output.string.should =~ /BYE/
|
785
902
|
|
786
|
-
|
903
|
+
Pry.input.rewind
|
787
904
|
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
905
|
+
str_output = StringIO.new
|
906
|
+
Pry.new(:output => str_output,
|
907
|
+
:hooks => {
|
908
|
+
:before_session => proc { |out,_| out.puts "MORNING" },
|
909
|
+
:after_session => proc { |out,_| out.puts "EVENING" }
|
910
|
+
}
|
911
|
+
).repl
|
912
|
+
|
913
|
+
str_output.string.should =~ /MORNING/
|
914
|
+
str_output.string.should =~ /EVENING/
|
915
|
+
|
916
|
+
# try below with just defining one hook
|
917
|
+
Pry.input.rewind
|
918
|
+
str_output = StringIO.new
|
919
|
+
Pry.new(:output => str_output,
|
920
|
+
:hooks => {
|
921
|
+
:before_session => proc { |out,_| out.puts "OPEN" }
|
922
|
+
}
|
923
|
+
).repl
|
807
924
|
|
808
|
-
|
925
|
+
str_output.string.should =~ /OPEN/
|
809
926
|
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
927
|
+
Pry.input.rewind
|
928
|
+
str_output = StringIO.new
|
929
|
+
Pry.new(:output => str_output,
|
930
|
+
:hooks => {
|
931
|
+
:after_session => proc { |out,_| out.puts "CLOSE" }
|
932
|
+
}
|
933
|
+
).repl
|
817
934
|
|
818
|
-
|
935
|
+
str_output.string.should =~ /CLOSE/
|
819
936
|
|
820
|
-
|
821
|
-
|
937
|
+
Pry.reset_defaults
|
938
|
+
Pry.color = false
|
939
|
+
end
|
822
940
|
end
|
823
941
|
end
|
824
942
|
end
|
825
943
|
end
|
826
|
-
end
|