pry 0.6.7pre4-i386-mingw32 → 0.6.8-i386-mingw32
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/CHANGELOG +88 -75
- data/LICENSE +25 -25
- data/README.markdown +321 -309
- data/Rakefile +103 -103
- data/bin/pry +83 -82
- data/examples/example_basic.rb +17 -17
- data/examples/example_command_override.rb +35 -35
- data/examples/example_commands.rb +39 -39
- data/examples/example_hooks.rb +12 -12
- data/examples/example_image_edit.rb +71 -71
- data/examples/example_input.rb +10 -10
- data/examples/example_input2.rb +32 -32
- data/examples/example_output.rb +14 -14
- data/examples/example_print.rb +9 -9
- data/examples/example_prompt.rb +12 -12
- data/lib/pry.rb +32 -32
- data/lib/pry/command_base.rb +150 -150
- data/lib/pry/commands.rb +616 -577
- data/lib/pry/completion.rb +202 -202
- data/lib/pry/core_extensions.rb +55 -55
- data/lib/pry/hooks.rb +19 -8
- data/lib/pry/print.rb +19 -19
- data/lib/pry/prompts.rb +26 -26
- data/lib/pry/pry_class.rb +219 -186
- data/lib/pry/pry_instance.rb +316 -316
- data/lib/pry/version.rb +3 -3
- data/test/test.rb +725 -681
- data/test/test_helper.rb +46 -38
- data/test/testrc +2 -0
- metadata +102 -66
data/lib/pry/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
class Pry
|
2
|
-
VERSION = "0.6.
|
3
|
-
end
|
1
|
+
class Pry
|
2
|
+
VERSION = "0.6.8"
|
3
|
+
end
|
data/test/test.rb
CHANGED
@@ -1,681 +1,725 @@
|
|
1
|
-
direc = File.dirname(__FILE__)
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'bacon'
|
5
|
-
require "#{direc}/../lib/pry"
|
6
|
-
require "#{direc}/test_helper"
|
7
|
-
|
8
|
-
puts "Ruby Version #{RUBY_VERSION}"
|
9
|
-
puts "Testing Pry #{Pry::VERSION}"
|
10
|
-
puts "With method_source version #{MethodSource::VERSION}"
|
11
|
-
puts "--"
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
o
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
o
|
47
|
-
str_output
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
pry_tester
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
str_output
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
Pry.
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
end
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
end
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
it
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
Object.remove_const(:
|
391
|
-
end
|
392
|
-
|
393
|
-
it 'should
|
394
|
-
class
|
395
|
-
command "
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
Object.remove_const(:
|
404
|
-
end
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
Command3
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
str_output = StringIO.new
|
535
|
-
Pry.new(:input => InputTester.new("
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
Pry.
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
Pry.
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
Pry.new.
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
1
|
+
direc = File.dirname(__FILE__)
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bacon'
|
5
|
+
require "#{direc}/../lib/pry"
|
6
|
+
require "#{direc}/test_helper"
|
7
|
+
|
8
|
+
puts "Ruby Version #{RUBY_VERSION}"
|
9
|
+
puts "Testing Pry #{Pry::VERSION}"
|
10
|
+
puts "With method_source version #{MethodSource::VERSION}"
|
11
|
+
puts "--"
|
12
|
+
|
13
|
+
# Ensure we do not execute any rc files
|
14
|
+
Pry::RC_FILES.clear
|
15
|
+
Pry.color = false
|
16
|
+
Pry.should_load_rc = false
|
17
|
+
|
18
|
+
describe Pry do
|
19
|
+
describe "open a Pry session on an object" do
|
20
|
+
describe "rep" do
|
21
|
+
|
22
|
+
before do
|
23
|
+
class Hello
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
after do
|
28
|
+
Object.send(:remove_const, :Hello)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should set an ivar on an object' do
|
32
|
+
input_string = "@x = 10"
|
33
|
+
input = InputTester.new(input_string)
|
34
|
+
o = Object.new
|
35
|
+
|
36
|
+
pry_tester = Pry.new(:input => input, :output => Pry::NullOutput)
|
37
|
+
pry_tester.rep(o)
|
38
|
+
o.instance_variable_get(:@x).should == 10
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should make self evaluate to the receiver of the rep session' do
|
42
|
+
o = Object.new
|
43
|
+
str_output = StringIO.new
|
44
|
+
|
45
|
+
pry_tester = Pry.new(:input => InputTester.new("self"), :output => str_output)
|
46
|
+
pry_tester.rep(o)
|
47
|
+
str_output.string.should =~ /#{o.to_s}/
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should work with multi-line input' do
|
51
|
+
o = Object.new
|
52
|
+
str_output = StringIO.new
|
53
|
+
|
54
|
+
pry_tester = Pry.new(:input => InputTester.new("x = ", "1 + 4"), :output => str_output)
|
55
|
+
pry_tester.rep(o)
|
56
|
+
str_output.string.should =~ /5/
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should define a nested class under Hello and not on top-level or Pry' do
|
60
|
+
pry_tester = Pry.new(:input => InputTester.new("class Nested", "end"), :output => Pry::NullOutput)
|
61
|
+
pry_tester.rep(Hello)
|
62
|
+
Hello.const_defined?(:Nested).should == true
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "repl" do
|
67
|
+
describe "basic functionality" do
|
68
|
+
it 'should set an ivar on an object and exit the repl' do
|
69
|
+
input_strings = ["@x = 10", "exit"]
|
70
|
+
input = InputTester.new(*input_strings)
|
71
|
+
|
72
|
+
o = Object.new
|
73
|
+
|
74
|
+
pry_tester = Pry.start(o, :input => input, :output => Pry::NullOutput)
|
75
|
+
|
76
|
+
o.instance_variable_get(:@x).should == 10
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should execute start session and end session hooks' do
|
80
|
+
input = InputTester.new("exit")
|
81
|
+
str_output = StringIO.new
|
82
|
+
o = Object.new
|
83
|
+
|
84
|
+
pry_tester = Pry.start(o, :input => input, :output => str_output)
|
85
|
+
str_output.string.should =~ /Beginning.*#{o}/
|
86
|
+
str_output.string.should =~ /Ending.*#{o}/
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "test loading rc files" do
|
91
|
+
after do
|
92
|
+
Pry::RC_FILES.clear
|
93
|
+
Pry.should_load_rc = false
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should run the rc file only once" do
|
97
|
+
Pry.should_load_rc = true
|
98
|
+
Pry::RC_FILES << "#{direc}/testrc"
|
99
|
+
|
100
|
+
Pry.start(self, :input => StringIO.new("exit\n"), :output => Pry::NullOutput)
|
101
|
+
TEST_RC.should == [0]
|
102
|
+
|
103
|
+
Pry.start(self, :input => StringIO.new("exit\n"), :output => Pry::NullOutput)
|
104
|
+
TEST_RC.should == [0]
|
105
|
+
|
106
|
+
Object.remove_const(:TEST_RC)
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should not run the rc file at all if Pry.should_load_rc is false" do
|
110
|
+
Pry.should_load_rc = false
|
111
|
+
Pry.start(self, :input => StringIO.new("exit\n"), :output => Pry::NullOutput)
|
112
|
+
Object.const_defined?(:TEST_RC).should == false
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should not load the rc file if #repl method invoked" do
|
116
|
+
Pry.should_load_rc = true
|
117
|
+
Pry.new(:input => StringIO.new("exit\n"), :output => Pry::NullOutput).repl(self)
|
118
|
+
Object.const_defined?(:TEST_RC).should == false
|
119
|
+
Pry.should_load_rc = false
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe "nesting" do
|
124
|
+
after do
|
125
|
+
Pry.reset_defaults
|
126
|
+
Pry.color = false
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'should nest properly' do
|
130
|
+
Pry.input = InputTester.new("pry", "pry", "pry", "\"nest:\#\{Pry.nesting.level\}\"", "exit_all")
|
131
|
+
|
132
|
+
str_output = StringIO.new
|
133
|
+
Pry.output = str_output
|
134
|
+
|
135
|
+
o = Object.new
|
136
|
+
|
137
|
+
pry_tester = o.pry
|
138
|
+
str_output.string.should =~ /nest:3/
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
describe "defining methods" do
|
143
|
+
it 'should define a method on the singleton class of an object when performing "def meth;end" inside the object' do
|
144
|
+
[Object.new, {}, []].each do |val|
|
145
|
+
str_input = StringIO.new("def hello;end")
|
146
|
+
Pry.new(:input => str_input, :output => StringIO.new).rep(val)
|
147
|
+
|
148
|
+
val.methods(false).map(&:to_sym).include?(:hello).should == true
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'should define an instance method on the module when performing "def meth;end" inside the module' do
|
153
|
+
str_input = StringIO.new("def hello;end")
|
154
|
+
hello = Module.new
|
155
|
+
Pry.new(:input => str_input, :output => StringIO.new).rep(hello)
|
156
|
+
hello.instance_methods(false).map(&:to_sym).include?(:hello).should == true
|
157
|
+
end
|
158
|
+
|
159
|
+
it 'should define an instance method on the class when performing "def meth;end" inside the class' do
|
160
|
+
str_input = StringIO.new("def hello;end")
|
161
|
+
hello = Class.new
|
162
|
+
Pry.new(:input => str_input, :output => StringIO.new).rep(hello)
|
163
|
+
hello.instance_methods(false).map(&:to_sym).include?(:hello).should == true
|
164
|
+
end
|
165
|
+
|
166
|
+
it 'should define a method on the class of an object when performing "def meth;end" inside an immediate value or Numeric' do
|
167
|
+
# should include float in here, but test fails for some reason
|
168
|
+
# on 1.8.7, no idea why!
|
169
|
+
[:test, 0, true, false, nil].each do |val|
|
170
|
+
str_input = StringIO.new("def hello;end")
|
171
|
+
Pry.new(:input => str_input, :output => StringIO.new).rep(val)
|
172
|
+
val.class.instance_methods(false).map(&:to_sym).include?(:hello).should == true
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
end
|
177
|
+
|
178
|
+
|
179
|
+
describe "commands" do
|
180
|
+
it 'should run a command with no parameter' do
|
181
|
+
pry_tester = Pry.new
|
182
|
+
pry_tester.commands = CommandTester
|
183
|
+
pry_tester.input = InputTester.new("command1", "exit_all")
|
184
|
+
pry_tester.commands = CommandTester
|
185
|
+
|
186
|
+
str_output = StringIO.new
|
187
|
+
pry_tester.output = str_output
|
188
|
+
|
189
|
+
pry_tester.rep
|
190
|
+
|
191
|
+
str_output.string.should =~ /command1/
|
192
|
+
end
|
193
|
+
|
194
|
+
it 'should run a command with one parameter' do
|
195
|
+
pry_tester = Pry.new
|
196
|
+
pry_tester.commands = CommandTester
|
197
|
+
pry_tester.input = InputTester.new("command2 horsey", "exit_all")
|
198
|
+
pry_tester.commands = CommandTester
|
199
|
+
|
200
|
+
str_output = StringIO.new
|
201
|
+
pry_tester.output = str_output
|
202
|
+
|
203
|
+
pry_tester.rep
|
204
|
+
|
205
|
+
str_output.string.should =~ /horsey/
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
describe "Object#pry" do
|
210
|
+
|
211
|
+
after do
|
212
|
+
Pry.reset_defaults
|
213
|
+
Pry.color = false
|
214
|
+
end
|
215
|
+
|
216
|
+
it "should start a pry session on the receiver (first form)" do
|
217
|
+
Pry.input = InputTester.new("self", "exit")
|
218
|
+
|
219
|
+
str_output = StringIO.new
|
220
|
+
Pry.output = str_output
|
221
|
+
|
222
|
+
20.pry
|
223
|
+
|
224
|
+
str_output.string.should =~ /20/
|
225
|
+
end
|
226
|
+
|
227
|
+
it "should start a pry session on the receiver (second form)" do
|
228
|
+
Pry.input = InputTester.new("self", "exit")
|
229
|
+
|
230
|
+
str_output = StringIO.new
|
231
|
+
Pry.output = str_output
|
232
|
+
|
233
|
+
pry 20
|
234
|
+
|
235
|
+
str_output.string.should =~ /20/
|
236
|
+
end
|
237
|
+
|
238
|
+
it "should error if more than one argument is passed to Object#pry" do
|
239
|
+
lambda { pry(20, :input => Readline) }.should.raise ArgumentError
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
describe "Pry.binding_for" do
|
244
|
+
it 'should return TOPLEVEL_BINDING if parameter self is main' do
|
245
|
+
_main_ = lambda { TOPLEVEL_BINDING.eval('self') }
|
246
|
+
Pry.binding_for(_main_.call).is_a?(Binding).should == true
|
247
|
+
Pry.binding_for(_main_.call).should == TOPLEVEL_BINDING
|
248
|
+
Pry.binding_for(_main_.call).should == Pry.binding_for(_main_.call)
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
|
253
|
+
describe "test Pry defaults" do
|
254
|
+
|
255
|
+
after do
|
256
|
+
Pry.reset_defaults
|
257
|
+
Pry.color = false
|
258
|
+
end
|
259
|
+
|
260
|
+
describe "input" do
|
261
|
+
|
262
|
+
after do
|
263
|
+
Pry.reset_defaults
|
264
|
+
Pry.color = false
|
265
|
+
end
|
266
|
+
|
267
|
+
it 'should set the input default, and the default should be overridable' do
|
268
|
+
Pry.input = InputTester.new("5")
|
269
|
+
|
270
|
+
str_output = StringIO.new
|
271
|
+
Pry.output = str_output
|
272
|
+
Pry.new.rep
|
273
|
+
str_output.string.should =~ /5/
|
274
|
+
|
275
|
+
Pry.new(:input => InputTester.new("6")).rep
|
276
|
+
str_output.string.should =~ /6/
|
277
|
+
end
|
278
|
+
|
279
|
+
it 'should pass in the prompt if readline arity is 1' do
|
280
|
+
Pry.prompt = proc { "A" }
|
281
|
+
|
282
|
+
arity_one_input = Class.new do
|
283
|
+
attr_accessor :prompt
|
284
|
+
def readline(prompt)
|
285
|
+
@prompt = prompt
|
286
|
+
"exit"
|
287
|
+
end
|
288
|
+
end.new
|
289
|
+
|
290
|
+
Pry.start(self, :input => arity_one_input, :output => Pry::NullOutput)
|
291
|
+
arity_one_input.prompt.should == Pry.prompt.call
|
292
|
+
end
|
293
|
+
|
294
|
+
it 'should not pass in the prompt if the arity is 0' do
|
295
|
+
Pry.prompt = proc { "A" }
|
296
|
+
|
297
|
+
arity_zero_input = Class.new do
|
298
|
+
def readline
|
299
|
+
"exit"
|
300
|
+
end
|
301
|
+
end.new
|
302
|
+
|
303
|
+
lambda { Pry.start(self, :input => arity_zero_input, :output => Pry::NullOutput) }.should.not.raise Exception
|
304
|
+
end
|
305
|
+
|
306
|
+
it 'should not pass in the prompt if the arity is -1' do
|
307
|
+
Pry.prompt = proc { "A" }
|
308
|
+
|
309
|
+
arity_multi_input = Class.new do
|
310
|
+
attr_accessor :prompt
|
311
|
+
|
312
|
+
def readline(*args)
|
313
|
+
@prompt = args.first
|
314
|
+
"exit"
|
315
|
+
end
|
316
|
+
end.new
|
317
|
+
|
318
|
+
Pry.start(self, :input => arity_multi_input, :output => Pry::NullOutput)
|
319
|
+
arity_multi_input.prompt.should == nil
|
320
|
+
end
|
321
|
+
|
322
|
+
end
|
323
|
+
|
324
|
+
it 'should set the output default, and the default should be overridable' do
|
325
|
+
Pry.input = InputTester.new("5", "6", "7")
|
326
|
+
|
327
|
+
str_output = StringIO.new
|
328
|
+
Pry.output = str_output
|
329
|
+
|
330
|
+
Pry.new.rep
|
331
|
+
str_output.string.should =~ /5/
|
332
|
+
|
333
|
+
Pry.new.rep
|
334
|
+
str_output.string.should =~ /5\n.*6/
|
335
|
+
|
336
|
+
str_output2 = StringIO.new
|
337
|
+
Pry.new(:output => str_output2).rep
|
338
|
+
str_output2.string.should.not =~ /5\n.*6/
|
339
|
+
str_output2.string.should =~ /7/
|
340
|
+
end
|
341
|
+
|
342
|
+
describe "Pry.run_command" do
|
343
|
+
before do
|
344
|
+
class RCTest
|
345
|
+
def a() end
|
346
|
+
B = 20
|
347
|
+
@x = 10
|
348
|
+
end
|
349
|
+
end
|
350
|
+
|
351
|
+
after do
|
352
|
+
Object.remove_const(:RCTest)
|
353
|
+
end
|
354
|
+
|
355
|
+
it "should execute command in the appropriate object context" do
|
356
|
+
result = Pry.run_command "ls", :context => RCTest
|
357
|
+
result.map(&:to_sym).should == [:@x]
|
358
|
+
end
|
359
|
+
|
360
|
+
it "should execute command with parameters in the appropriate object context" do
|
361
|
+
result = Pry.run_command "ls -M", :context => RCTest
|
362
|
+
result.map(&:to_sym).should == [:a]
|
363
|
+
end
|
364
|
+
|
365
|
+
it "should execute command and show output with :show_output => true flag" do
|
366
|
+
str = StringIO.new
|
367
|
+
Pry.output = str
|
368
|
+
result = Pry.run_command "ls -av", :context => RCTest, :show_output => true
|
369
|
+
str.string.should =~ /global variables/
|
370
|
+
Pry.output = $stdout
|
371
|
+
end
|
372
|
+
|
373
|
+
it "should execute command with multiple parameters" do
|
374
|
+
result = Pry.run_command "ls -c -M RCTest"
|
375
|
+
result.map(&:to_sym).should == [:a, :B]
|
376
|
+
end
|
377
|
+
end
|
378
|
+
|
379
|
+
describe "commands" do
|
380
|
+
it 'should define a command that keeps its return value' do
|
381
|
+
class Command68 < Pry::CommandBase
|
382
|
+
command "hello", "", :keep_retval => true do
|
383
|
+
:kept_hello
|
384
|
+
end
|
385
|
+
end
|
386
|
+
str_output = StringIO.new
|
387
|
+
Pry.new(:input => StringIO.new("hello"), :output => str_output, :commands => Command68).rep
|
388
|
+
str_output.string.should =~ /:kept_hello/
|
389
|
+
|
390
|
+
Object.remove_const(:Command68)
|
391
|
+
end
|
392
|
+
|
393
|
+
it 'should define a command that does NOT keep its return value' do
|
394
|
+
class Command68 < Pry::CommandBase
|
395
|
+
command "hello", "", :keep_retval => false do
|
396
|
+
:kept_hello
|
397
|
+
end
|
398
|
+
end
|
399
|
+
str_output = StringIO.new
|
400
|
+
Pry.new(:input => StringIO.new("hello"), :output => str_output, :commands => Command68).rep
|
401
|
+
(str_output.string =~ /:kept_hello/).should == nil
|
402
|
+
|
403
|
+
Object.remove_const(:Command68)
|
404
|
+
end
|
405
|
+
|
406
|
+
|
407
|
+
it 'should set the commands default, and the default should be overridable' do
|
408
|
+
class Command0 < Pry::CommandBase
|
409
|
+
command "hello" do
|
410
|
+
output.puts "hello world"
|
411
|
+
end
|
412
|
+
end
|
413
|
+
|
414
|
+
Pry.commands = Command0
|
415
|
+
|
416
|
+
str_output = StringIO.new
|
417
|
+
Pry.new(:input => InputTester.new("hello"), :output => str_output).rep
|
418
|
+
str_output.string.should =~ /hello world/
|
419
|
+
|
420
|
+
class Command1 < Pry::CommandBase
|
421
|
+
command "goodbye", "" do
|
422
|
+
output.puts "goodbye world"
|
423
|
+
end
|
424
|
+
end
|
425
|
+
|
426
|
+
str_output = StringIO.new
|
427
|
+
|
428
|
+
Pry.new(:input => InputTester.new("goodbye"), :output => str_output, :commands => Command1).rep
|
429
|
+
str_output.string.should =~ /goodbye world/
|
430
|
+
|
431
|
+
Object.remove_const(:Command0)
|
432
|
+
Object.remove_const(:Command1)
|
433
|
+
end
|
434
|
+
|
435
|
+
it 'should inherit "help" command from Pry::CommandBase' do
|
436
|
+
class Command2 < Pry::CommandBase
|
437
|
+
command "h", "h command" do
|
438
|
+
end
|
439
|
+
end
|
440
|
+
|
441
|
+
Command2.commands.keys.size.should == 2
|
442
|
+
Command2.commands.keys.include?("help").should == true
|
443
|
+
Command2.commands.keys.include?("h").should == true
|
444
|
+
|
445
|
+
Object.remove_const(:Command2)
|
446
|
+
end
|
447
|
+
|
448
|
+
it 'should inherit commands from Pry::Commands' do
|
449
|
+
class Command3 < Pry::Commands
|
450
|
+
command "v" do
|
451
|
+
end
|
452
|
+
end
|
453
|
+
|
454
|
+
Command3.commands.include?("nesting").should == true
|
455
|
+
Command3.commands.include?("jump-to").should == true
|
456
|
+
Command3.commands.include?("cd").should == true
|
457
|
+
Command3.commands.include?("v").should == true
|
458
|
+
|
459
|
+
Object.remove_const(:Command3)
|
460
|
+
end
|
461
|
+
|
462
|
+
it 'should alias a command with another command' do
|
463
|
+
class Command6 < Pry::CommandBase
|
464
|
+
alias_command "help2", "help"
|
465
|
+
end
|
466
|
+
|
467
|
+
Command6.commands["help2"].should == Command6.commands["help"]
|
468
|
+
# str_output = StringIO.new
|
469
|
+
# Pry.new(:input => InputTester.new("run_v"), :output => str_output, :commands => Command3).rep
|
470
|
+
# str_output.string.should =~ /v command/
|
471
|
+
|
472
|
+
Object.remove_const(:Command6)
|
473
|
+
end
|
474
|
+
|
475
|
+
it 'should change description of a command using desc' do
|
476
|
+
|
477
|
+
class Command7 < Pry::Commands
|
478
|
+
end
|
479
|
+
|
480
|
+
orig = Command7.commands["help"][:description]
|
481
|
+
|
482
|
+
class Command7
|
483
|
+
desc "help", "blah"
|
484
|
+
end
|
485
|
+
|
486
|
+
Command7.commands["help"][:description].should.not == orig
|
487
|
+
Command7.commands["help"][:description].should == "blah"
|
488
|
+
|
489
|
+
Object.remove_const(:Command7)
|
490
|
+
end
|
491
|
+
|
492
|
+
it 'should run a command from within a command' do
|
493
|
+
class Command01 < Pry::Commands
|
494
|
+
command "v" do
|
495
|
+
output.puts "v command"
|
496
|
+
end
|
497
|
+
|
498
|
+
command "run_v" do
|
499
|
+
run "v"
|
500
|
+
end
|
501
|
+
end
|
502
|
+
|
503
|
+
str_output = StringIO.new
|
504
|
+
Pry.new(:input => InputTester.new("run_v"), :output => str_output, :commands => Command01).rep
|
505
|
+
str_output.string.should =~ /v command/
|
506
|
+
|
507
|
+
Object.remove_const(:Command01)
|
508
|
+
end
|
509
|
+
|
510
|
+
it 'should enable an inherited method to access opts and output and target, due to instance_exec' do
|
511
|
+
class Command3 < Pry::Commands
|
512
|
+
command "v" do
|
513
|
+
output.puts "#{target.eval('self')}"
|
514
|
+
end
|
515
|
+
end
|
516
|
+
|
517
|
+
class Command4 < Command3
|
518
|
+
end
|
519
|
+
|
520
|
+
str_output = StringIO.new
|
521
|
+
Pry.new(:print => proc {}, :input => InputTester.new("v"),
|
522
|
+
:output => str_output, :commands => Command4).rep("john")
|
523
|
+
str_output.string.chomp.should == "john"
|
524
|
+
|
525
|
+
Object.remove_const(:Command3)
|
526
|
+
Object.remove_const(:Command4)
|
527
|
+
end
|
528
|
+
|
529
|
+
it 'should import commands from another command object' do
|
530
|
+
class Command3 < Pry::CommandBase
|
531
|
+
import_from Pry::Commands, "status", "jump-to"
|
532
|
+
end
|
533
|
+
|
534
|
+
str_output = StringIO.new
|
535
|
+
Pry.new(:print => proc {}, :input => InputTester.new("status"),
|
536
|
+
:output => str_output, :commands => Command3).rep("john")
|
537
|
+
str_output.string.should =~ /Status:/
|
538
|
+
|
539
|
+
Object.remove_const(:Command3)
|
540
|
+
end
|
541
|
+
|
542
|
+
it 'should delete some inherited commands when using delete method' do
|
543
|
+
class Command3 < Pry::Commands
|
544
|
+
command "v" do
|
545
|
+
end
|
546
|
+
|
547
|
+
delete "show_doc", "show_method"
|
548
|
+
delete "ls"
|
549
|
+
end
|
550
|
+
|
551
|
+
Command3.commands.include?("nesting").should == true
|
552
|
+
Command3.commands.include?("jump-to").should == true
|
553
|
+
Command3.commands.include?("cd").should == true
|
554
|
+
Command3.commands.include?("v").should == true
|
555
|
+
Command3.commands.include?("show_doc").should == false
|
556
|
+
Command3.commands.include?("show_method").should == false
|
557
|
+
Command3.commands.include?("ls").should == false
|
558
|
+
|
559
|
+
Object.remove_const(:Command3)
|
560
|
+
end
|
561
|
+
|
562
|
+
it 'should override some inherited commands' do
|
563
|
+
class Command3 < Pry::Commands
|
564
|
+
command "jump-to" do
|
565
|
+
output.puts "jump-to the music"
|
566
|
+
end
|
567
|
+
|
568
|
+
command "help" do
|
569
|
+
output.puts "help to the music"
|
570
|
+
end
|
571
|
+
end
|
572
|
+
|
573
|
+
# suppress evaluation output
|
574
|
+
Pry.print = proc {}
|
575
|
+
|
576
|
+
str_output = StringIO.new
|
577
|
+
Pry.new(:input => InputTester.new("jump-to"), :output => str_output, :commands => Command3).rep
|
578
|
+
str_output.string.chomp.should == "jump-to the music"
|
579
|
+
|
580
|
+
str_output = StringIO.new
|
581
|
+
Pry.new(:input => InputTester.new("help"), :output => str_output, :commands => Command3).rep
|
582
|
+
str_output.string.chomp.should == "help to the music"
|
583
|
+
|
584
|
+
Object.remove_const(:Command3)
|
585
|
+
|
586
|
+
Pry.reset_defaults
|
587
|
+
Pry.color = false
|
588
|
+
end
|
589
|
+
end
|
590
|
+
|
591
|
+
it "should set the print default, and the default should be overridable" do
|
592
|
+
new_print = proc { |out, value| out.puts value }
|
593
|
+
Pry.print = new_print
|
594
|
+
|
595
|
+
Pry.new.print.should == Pry.print
|
596
|
+
str_output = StringIO.new
|
597
|
+
Pry.new(:input => InputTester.new("\"test\""), :output => str_output).rep
|
598
|
+
str_output.string.should == "test\n"
|
599
|
+
|
600
|
+
str_output = StringIO.new
|
601
|
+
Pry.new(:input => InputTester.new("\"test\""), :output => str_output,
|
602
|
+
:print => proc { |out, value| out.puts value.reverse }).rep
|
603
|
+
str_output.string.should == "tset\n"
|
604
|
+
|
605
|
+
Pry.new.print.should == Pry.print
|
606
|
+
str_output = StringIO.new
|
607
|
+
Pry.new(:input => InputTester.new("\"test\""), :output => str_output).rep
|
608
|
+
str_output.string.should == "test\n"
|
609
|
+
end
|
610
|
+
|
611
|
+
describe "pry return values" do
|
612
|
+
it 'should return the target object' do
|
613
|
+
Pry.start(self, :input => StringIO.new("exit"), :output => Pry::NullOutput).should == self
|
614
|
+
end
|
615
|
+
|
616
|
+
it 'should return the parameter given to exit' do
|
617
|
+
Pry.start(self, :input => StringIO.new("exit 10"), :output => Pry::NullOutput).should == 10
|
618
|
+
end
|
619
|
+
|
620
|
+
it 'should return the parameter (multi word string) given to exit' do
|
621
|
+
Pry.start(self, :input => StringIO.new("exit \"john mair\""), :output => Pry::NullOutput).should == "john mair"
|
622
|
+
end
|
623
|
+
|
624
|
+
it 'should return the parameter (function call) given to exit' do
|
625
|
+
Pry.start(self, :input => StringIO.new("exit 'abc'.reverse"), :output => Pry::NullOutput).should == 'cba'
|
626
|
+
end
|
627
|
+
|
628
|
+
it 'should return the parameter (self) given to exit' do
|
629
|
+
Pry.start("carl", :input => StringIO.new("exit self"), :output => Pry::NullOutput).should == "carl"
|
630
|
+
end
|
631
|
+
end
|
632
|
+
|
633
|
+
describe "prompts" do
|
634
|
+
it 'should set the prompt default, and the default should be overridable (single prompt)' do
|
635
|
+
new_prompt = proc { "test prompt> " }
|
636
|
+
Pry.prompt = new_prompt
|
637
|
+
|
638
|
+
Pry.new.prompt.should == Pry.prompt
|
639
|
+
Pry.new.select_prompt(true, 0).should == "test prompt> "
|
640
|
+
Pry.new.select_prompt(false, 0).should == "test prompt> "
|
641
|
+
|
642
|
+
new_prompt = proc { "A" }
|
643
|
+
pry_tester = Pry.new(:prompt => new_prompt)
|
644
|
+
pry_tester.prompt.should == new_prompt
|
645
|
+
pry_tester.select_prompt(true, 0).should == "A"
|
646
|
+
pry_tester.select_prompt(false, 0).should == "A"
|
647
|
+
|
648
|
+
Pry.new.prompt.should == Pry.prompt
|
649
|
+
Pry.new.select_prompt(true, 0).should == "test prompt> "
|
650
|
+
Pry.new.select_prompt(false, 0).should == "test prompt> "
|
651
|
+
end
|
652
|
+
|
653
|
+
it 'should set the prompt default, and the default should be overridable (multi prompt)' do
|
654
|
+
new_prompt = [proc { "test prompt> " }, proc { "test prompt* " }]
|
655
|
+
Pry.prompt = new_prompt
|
656
|
+
|
657
|
+
Pry.new.prompt.should == Pry.prompt
|
658
|
+
Pry.new.select_prompt(true, 0).should == "test prompt> "
|
659
|
+
Pry.new.select_prompt(false, 0).should == "test prompt* "
|
660
|
+
|
661
|
+
new_prompt = [proc { "A" }, proc { "B" }]
|
662
|
+
pry_tester = Pry.new(:prompt => new_prompt)
|
663
|
+
pry_tester.prompt.should == new_prompt
|
664
|
+
pry_tester.select_prompt(true, 0).should == "A"
|
665
|
+
pry_tester.select_prompt(false, 0).should == "B"
|
666
|
+
|
667
|
+
Pry.new.prompt.should == Pry.prompt
|
668
|
+
Pry.new.select_prompt(true, 0).should == "test prompt> "
|
669
|
+
Pry.new.select_prompt(false, 0).should == "test prompt* "
|
670
|
+
end
|
671
|
+
end
|
672
|
+
|
673
|
+
it 'should set the hooks default, and the default should be overridable' do
|
674
|
+
Pry.input = InputTester.new("exit")
|
675
|
+
Pry.hooks = {
|
676
|
+
:before_session => proc { |out,_| out.puts "HELLO" },
|
677
|
+
:after_session => proc { |out,_| out.puts "BYE" }
|
678
|
+
}
|
679
|
+
|
680
|
+
str_output = StringIO.new
|
681
|
+
Pry.new(:output => str_output).repl
|
682
|
+
str_output.string.should =~ /HELLO/
|
683
|
+
str_output.string.should =~ /BYE/
|
684
|
+
|
685
|
+
Pry.input.rewind
|
686
|
+
|
687
|
+
str_output = StringIO.new
|
688
|
+
Pry.new(:output => str_output,
|
689
|
+
:hooks => {
|
690
|
+
:before_session => proc { |out,_| out.puts "MORNING" },
|
691
|
+
:after_session => proc { |out,_| out.puts "EVENING" }
|
692
|
+
}
|
693
|
+
).repl
|
694
|
+
|
695
|
+
str_output.string.should =~ /MORNING/
|
696
|
+
str_output.string.should =~ /EVENING/
|
697
|
+
|
698
|
+
# try below with just defining one hook
|
699
|
+
Pry.input.rewind
|
700
|
+
str_output = StringIO.new
|
701
|
+
Pry.new(:output => str_output,
|
702
|
+
:hooks => {
|
703
|
+
:before_session => proc { |out,_| out.puts "OPEN" }
|
704
|
+
}
|
705
|
+
).repl
|
706
|
+
|
707
|
+
str_output.string.should =~ /OPEN/
|
708
|
+
|
709
|
+
Pry.input.rewind
|
710
|
+
str_output = StringIO.new
|
711
|
+
Pry.new(:output => str_output,
|
712
|
+
:hooks => {
|
713
|
+
:after_session => proc { |out,_| out.puts "CLOSE" }
|
714
|
+
}
|
715
|
+
).repl
|
716
|
+
|
717
|
+
str_output.string.should =~ /CLOSE/
|
718
|
+
|
719
|
+
Pry.reset_defaults
|
720
|
+
Pry.color = false
|
721
|
+
end
|
722
|
+
end
|
723
|
+
end
|
724
|
+
end
|
725
|
+
end
|