pry 0.9.3pre1-i386-mswin32 → 0.9.4-i386-mswin32
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +53 -0
- data/CONTRIBUTORS +13 -0
- data/README.markdown +4 -2
- data/Rakefile +17 -3
- data/TODO +22 -0
- data/lib/pry.rb +102 -24
- data/lib/pry/command_context.rb +12 -0
- data/lib/pry/command_processor.rb +50 -19
- data/lib/pry/command_set.rb +17 -7
- data/lib/pry/completion.rb +6 -6
- data/lib/pry/config.rb +6 -2
- data/lib/pry/default_commands/basic.rb +8 -4
- data/lib/pry/default_commands/context.rb +84 -36
- data/lib/pry/default_commands/documentation.rb +50 -30
- data/lib/pry/default_commands/easter_eggs.rb +5 -0
- data/lib/pry/default_commands/input.rb +20 -16
- data/lib/pry/default_commands/introspection.rb +61 -77
- data/lib/pry/default_commands/ls.rb +22 -14
- data/lib/pry/default_commands/shell.rb +32 -17
- data/lib/pry/extended_commands/user_command_api.rb +32 -1
- data/lib/pry/helpers/base_helpers.rb +21 -9
- data/lib/pry/helpers/command_helpers.rb +99 -17
- data/lib/pry/helpers/text.rb +12 -11
- data/lib/pry/history.rb +61 -0
- data/lib/pry/plugins.rb +19 -8
- data/lib/pry/pry_class.rb +49 -60
- data/lib/pry/pry_instance.rb +122 -119
- data/lib/pry/version.rb +1 -1
- data/pry.gemspec +15 -14
- data/test/helper.rb +31 -0
- data/test/test_command_processor.rb +8 -87
- data/test/test_command_set.rb +40 -2
- data/test/test_completion.rb +26 -0
- data/test/test_default_commands/test_context.rb +185 -1
- data/test/test_default_commands/test_documentation.rb +10 -0
- data/test/test_default_commands/test_input.rb +39 -13
- data/test/test_default_commands/test_introspection.rb +11 -1
- data/test/test_default_commands/test_shell.rb +18 -0
- data/test/test_pry.rb +217 -47
- data/test/test_pry_history.rb +84 -0
- data/test/test_pry_output.rb +44 -0
- data/test/test_special_locals.rb +35 -0
- metadata +83 -77
@@ -10,6 +10,16 @@ describe "Pry::DefaultCommands::Introspection" do
|
|
10
10
|
|
11
11
|
str_output.string.should =~ /def sample/
|
12
12
|
end
|
13
|
+
|
14
|
+
it 'should output multiple methods\' sources' do
|
15
|
+
str_output = StringIO.new
|
16
|
+
redirect_pry_io(InputTester.new("show-method sample_method another_sample_method", "exit-all"), str_output) do
|
17
|
+
pry
|
18
|
+
end
|
19
|
+
|
20
|
+
str_output.string.should =~ /def sample/
|
21
|
+
str_output.string.should =~ /def another_sample/
|
22
|
+
end
|
13
23
|
|
14
24
|
it 'should output a method\'s source with line numbers' do
|
15
25
|
str_output = StringIO.new
|
@@ -94,7 +104,7 @@ describe "Pry::DefaultCommands::Introspection" do
|
|
94
104
|
|
95
105
|
it 'should output an instance method\'s source for a method defined inside pry using define_method' do
|
96
106
|
str_output = StringIO.new
|
97
|
-
redirect_pry_io(InputTester.new("class A", "define_method(:yup) {}", "end", "
|
107
|
+
redirect_pry_io(InputTester.new("class A", "define_method(:yup) {}", "end", "show-method A#yup"), str_output) do
|
98
108
|
TOPLEVEL_BINDING.pry
|
99
109
|
end
|
100
110
|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe "Pry::DefaultCommands::Shell" do
|
4
|
+
describe "cat" do
|
5
|
+
|
6
|
+
# this doesnt work so well on rbx due to differences in backtrace
|
7
|
+
# so we currently skip rbx until we figure out a workaround
|
8
|
+
if !rbx?
|
9
|
+
it 'cat --ex should give warning when exception is raised in repl' do
|
10
|
+
mock_pry("this raises error", "cat --ex").should =~ /Cannot cat exceptions raised in REPL/
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'cat --ex should correctly display code that generated exception' do
|
14
|
+
mock_pry("broken_method", "cat --ex").should =~ /this method is broken/
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/test/test_pry.rb
CHANGED
@@ -7,7 +7,7 @@ puts "--"
|
|
7
7
|
|
8
8
|
describe Pry do
|
9
9
|
|
10
|
-
if RUBY_PLATFORM !~ /mingw/ && RUBY_PLATFORM !~ /mswin/
|
10
|
+
if RUBY_PLATFORM !~ /mingw/ && RUBY_PLATFORM !~ /mswin/ && RUBY_PLATFORM != 'java'
|
11
11
|
describe 'warning emissions' do
|
12
12
|
it 'should emit no warnings' do
|
13
13
|
Open4.popen4 'ruby -I lib -rubygems -r"pry" -W -e "exit"' do |pid, stdin, stdout, stderr|
|
@@ -33,7 +33,6 @@ describe Pry do
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
|
37
36
|
describe "Pry.binding_for" do
|
38
37
|
|
39
38
|
# regression test for burg's bug (see git history)
|
@@ -93,6 +92,18 @@ describe Pry do
|
|
93
92
|
o.instance_variable_get(:@x).should == 10
|
94
93
|
end
|
95
94
|
|
95
|
+
it 'should not output anything for no input' do
|
96
|
+
outp = StringIO.new
|
97
|
+
|
98
|
+
# note i could not use mock_pry() for this test for some
|
99
|
+
# reason, as i'd always get "\n" as output instead of ""
|
100
|
+
redirect_pry_io(StringIO.new(""), outp) do
|
101
|
+
Pry.new.rep(self)
|
102
|
+
end
|
103
|
+
|
104
|
+
outp.string.empty?.should == true
|
105
|
+
end
|
106
|
+
|
96
107
|
it 'should make self evaluate to the receiver of the rep session' do
|
97
108
|
o = :john
|
98
109
|
str_output = StringIO.new
|
@@ -170,12 +181,18 @@ describe Pry do
|
|
170
181
|
pry_tester.rep(o)
|
171
182
|
was_called.should == true
|
172
183
|
end
|
184
|
+
|
185
|
+
it 'should not try to catch intended exceptions' do
|
186
|
+
lambda { mock_pry("raise SystemExit") }.should.raise SystemExit
|
187
|
+
# SIGTERM
|
188
|
+
lambda { mock_pry("raise SignalException.new(15)") }.should.raise SignalException
|
189
|
+
end
|
173
190
|
end
|
174
191
|
|
175
192
|
describe "repl" do
|
176
193
|
describe "basic functionality" do
|
177
194
|
it 'should set an ivar on an object and exit the repl' do
|
178
|
-
input_strings = ["@x = 10", "exit"]
|
195
|
+
input_strings = ["@x = 10", "exit-all"]
|
179
196
|
input = InputTester.new(*input_strings)
|
180
197
|
|
181
198
|
o = Object.new
|
@@ -198,7 +215,7 @@ describe Pry do
|
|
198
215
|
|
199
216
|
it 'sets out to an array with the result' do
|
200
217
|
res = {}
|
201
|
-
input = InputTester.new *[":foo", "42", "self[:res] =
|
218
|
+
input = InputTester.new *[":foo", "42", "self[:res] = _out_"]
|
202
219
|
pry = Pry.new(:input => input, :output => Pry::NullOutput)
|
203
220
|
pry.repl(res)
|
204
221
|
|
@@ -206,9 +223,9 @@ describe Pry do
|
|
206
223
|
res[:res][1..2].should == [:foo, 42]
|
207
224
|
end
|
208
225
|
|
209
|
-
it 'sets
|
226
|
+
it 'sets _in_ to an array with the entered lines' do
|
210
227
|
res = {}
|
211
|
-
input = InputTester.new *[":foo", "42", "self[:res] =
|
228
|
+
input = InputTester.new *[":foo", "42", "self[:res] = _in_"]
|
212
229
|
pry = Pry.new(:input => input, :output => Pry::NullOutput)
|
213
230
|
pry.repl(res)
|
214
231
|
|
@@ -216,9 +233,9 @@ describe Pry do
|
|
216
233
|
res[:res][1..2].should == [":foo\n", "42\n"]
|
217
234
|
end
|
218
235
|
|
219
|
-
it 'uses 100 as the size of
|
236
|
+
it 'uses 100 as the size of _in_ and _out_' do
|
220
237
|
res = []
|
221
|
-
input = InputTester.new *["self <<
|
238
|
+
input = InputTester.new *["self << _out_.max_size << _in_.max_size"]
|
222
239
|
pry = Pry.new(:input => input, :output => Pry::NullOutput)
|
223
240
|
pry.repl(res)
|
224
241
|
|
@@ -227,7 +244,7 @@ describe Pry do
|
|
227
244
|
|
228
245
|
it 'can change the size of the history arrays' do
|
229
246
|
res = []
|
230
|
-
input = InputTester.new *["self <<
|
247
|
+
input = InputTester.new *["self << _out_.max_size << _in_.max_size"]
|
231
248
|
pry = Pry.new(:input => input, :output => Pry::NullOutput,
|
232
249
|
:memory_size => 1000)
|
233
250
|
pry.repl(res)
|
@@ -237,7 +254,7 @@ describe Pry do
|
|
237
254
|
|
238
255
|
it 'store exceptions' do
|
239
256
|
res = []
|
240
|
-
input = InputTester.new *["foo!","self <<
|
257
|
+
input = InputTester.new *["foo!","self << _in_[-1] << _out_[-1]"]
|
241
258
|
pry = Pry.new(:input => input, :output => Pry::NullOutput,
|
242
259
|
:memory_size => 1000)
|
243
260
|
pry.repl(res)
|
@@ -262,10 +279,10 @@ describe Pry do
|
|
262
279
|
Pry.config.should_load_rc = true
|
263
280
|
Pry::RC_FILES << File.expand_path("../testrc", __FILE__)
|
264
281
|
|
265
|
-
Pry.start(self, :input => StringIO.new("exit\n"), :output => Pry::NullOutput)
|
282
|
+
Pry.start(self, :input => StringIO.new("exit-all\n"), :output => Pry::NullOutput)
|
266
283
|
TEST_RC.should == [0]
|
267
284
|
|
268
|
-
Pry.start(self, :input => StringIO.new("exit\n"), :output => Pry::NullOutput)
|
285
|
+
Pry.start(self, :input => StringIO.new("exit-all\n"), :output => Pry::NullOutput)
|
269
286
|
TEST_RC.should == [0]
|
270
287
|
|
271
288
|
Object.remove_const(:TEST_RC)
|
@@ -273,13 +290,13 @@ describe Pry do
|
|
273
290
|
|
274
291
|
it "should not run the rc file at all if Pry.config.should_load_rc is false" do
|
275
292
|
Pry.config.should_load_rc = false
|
276
|
-
Pry.start(self, :input => StringIO.new("exit\n"), :output => Pry::NullOutput)
|
293
|
+
Pry.start(self, :input => StringIO.new("exit-all\n"), :output => Pry::NullOutput)
|
277
294
|
Object.const_defined?(:TEST_RC).should == false
|
278
295
|
end
|
279
296
|
|
280
297
|
it "should not load the rc file if #repl method invoked" do
|
281
298
|
Pry.config.should_load_rc = true
|
282
|
-
Pry.new(:input => StringIO.new("exit\n"), :output => Pry::NullOutput).repl(self)
|
299
|
+
Pry.new(:input => StringIO.new("exit-all\n"), :output => Pry::NullOutput).repl(self)
|
283
300
|
Object.const_defined?(:TEST_RC).should == false
|
284
301
|
Pry.config.should_load_rc = false
|
285
302
|
end
|
@@ -292,7 +309,7 @@ describe Pry do
|
|
292
309
|
end
|
293
310
|
|
294
311
|
it 'should nest properly' do
|
295
|
-
Pry.input = InputTester.new("
|
312
|
+
Pry.input = InputTester.new("cd 1", "cd 2", "cd 3", "\"nest:\#\{(_pry_.binding_stack.size - 1)\}\"", "exit-all")
|
296
313
|
|
297
314
|
str_output = StringIO.new
|
298
315
|
Pry.output = str_output
|
@@ -343,7 +360,7 @@ describe Pry do
|
|
343
360
|
it 'should run a command with no parameter' do
|
344
361
|
pry_tester = Pry.new
|
345
362
|
pry_tester.commands = CommandTester
|
346
|
-
pry_tester.input = InputTester.new("command1", "
|
363
|
+
pry_tester.input = InputTester.new("command1", "exit-all")
|
347
364
|
pry_tester.commands = CommandTester
|
348
365
|
|
349
366
|
str_output = StringIO.new
|
@@ -357,7 +374,7 @@ describe Pry do
|
|
357
374
|
it 'should run a command with one parameter' do
|
358
375
|
pry_tester = Pry.new
|
359
376
|
pry_tester.commands = CommandTester
|
360
|
-
pry_tester.input = InputTester.new("command2 horsey", "
|
377
|
+
pry_tester.input = InputTester.new("command2 horsey", "exit-all")
|
361
378
|
pry_tester.commands = CommandTester
|
362
379
|
|
363
380
|
str_output = StringIO.new
|
@@ -377,7 +394,7 @@ describe Pry do
|
|
377
394
|
end
|
378
395
|
|
379
396
|
it "should start a pry session on the receiver (first form)" do
|
380
|
-
Pry.input = InputTester.new("self", "exit")
|
397
|
+
Pry.input = InputTester.new("self", "exit-all")
|
381
398
|
|
382
399
|
str_output = StringIO.new
|
383
400
|
Pry.output = str_output
|
@@ -388,7 +405,7 @@ describe Pry do
|
|
388
405
|
end
|
389
406
|
|
390
407
|
it "should start a pry session on the receiver (second form)" do
|
391
|
-
Pry.input = InputTester.new("self", "exit")
|
408
|
+
Pry.input = InputTester.new("self", "exit-all")
|
392
409
|
|
393
410
|
str_output = StringIO.new
|
394
411
|
Pry.output = str_output
|
@@ -446,7 +463,7 @@ describe Pry do
|
|
446
463
|
attr_accessor :prompt
|
447
464
|
def readline(prompt)
|
448
465
|
@prompt = prompt
|
449
|
-
"exit"
|
466
|
+
"exit-all"
|
450
467
|
end
|
451
468
|
end.new
|
452
469
|
|
@@ -459,7 +476,7 @@ describe Pry do
|
|
459
476
|
|
460
477
|
arity_zero_input = Class.new do
|
461
478
|
def readline
|
462
|
-
"exit"
|
479
|
+
"exit-all"
|
463
480
|
end
|
464
481
|
end.new
|
465
482
|
|
@@ -474,7 +491,7 @@ describe Pry do
|
|
474
491
|
|
475
492
|
def readline(*args)
|
476
493
|
@prompt = args.first
|
477
|
-
"exit"
|
494
|
+
"exit-all"
|
478
495
|
end
|
479
496
|
end.new
|
480
497
|
|
@@ -517,7 +534,7 @@ describe Pry do
|
|
517
534
|
$test_interpolation = nil
|
518
535
|
end
|
519
536
|
|
520
|
-
# bug fix for https://github.com/
|
537
|
+
# bug fix for https://github.com/pry/pry/issues/170
|
521
538
|
it 'should not choke on complex string interpolation when checking if ruby code is a command' do
|
522
539
|
redirect_pry_io(InputTester.new('/#{Regexp.escape(File.expand_path("."))}/'), str_output = StringIO.new) do
|
523
540
|
pry
|
@@ -672,15 +689,13 @@ describe Pry do
|
|
672
689
|
end
|
673
690
|
|
674
691
|
it 'should create a command in a nested context and that command should be accessible from the parent' do
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
Pry.
|
679
|
-
obj = Object.new
|
680
|
-
Pry.new(:output => str_output).repl(obj)
|
681
|
-
Pry.input = Readline
|
682
|
-
str_output.string.should =~ /@x/
|
692
|
+
str_output = StringIO.new
|
693
|
+
x = "@x=nil\ncd 7\n_pry_.commands.instance_eval {\ncommand('bing') { |arg| run arg }\n}\ncd ..\nbing ls\nexit-all"
|
694
|
+
redirect_pry_io(StringIO.new("@x=nil\ncd 7\n_pry_.commands.instance_eval {\ncommand('bing') { |arg| run arg }\n}\ncd ..\nbing ls\nexit-all"), str_output) do
|
695
|
+
Pry.new.repl(0)
|
683
696
|
end
|
697
|
+
|
698
|
+
str_output.string.should =~ /@x/
|
684
699
|
end
|
685
700
|
|
686
701
|
it 'should define a command that keeps its return value' do
|
@@ -707,6 +722,66 @@ describe Pry do
|
|
707
722
|
str_output.string !~ /=>/
|
708
723
|
end
|
709
724
|
|
725
|
+
it 'should define a command that keeps its return value even when nil' do
|
726
|
+
klass = Pry::CommandSet.new do
|
727
|
+
command "hello", "", :keep_retval => true do
|
728
|
+
nil
|
729
|
+
end
|
730
|
+
end
|
731
|
+
str_output = StringIO.new
|
732
|
+
Pry.new(:input => StringIO.new("hello\n"), :output => str_output, :commands => klass).rep
|
733
|
+
str_output.string.should =~ /nil/
|
734
|
+
str_output.string.should =~ /=>/
|
735
|
+
end
|
736
|
+
|
737
|
+
it 'should define a command that keeps its return value but does not return when value is void' do
|
738
|
+
klass = Pry::CommandSet.new do
|
739
|
+
command "hello", "", :keep_retval => true do
|
740
|
+
void
|
741
|
+
end
|
742
|
+
end
|
743
|
+
str_output = StringIO.new
|
744
|
+
Pry.new(:input => StringIO.new("hello\n"), :output => str_output, :commands => klass).rep
|
745
|
+
str_output.string.empty?.should == true
|
746
|
+
end
|
747
|
+
|
748
|
+
it 'a command (with :keep_retval => false) that replaces eval_string with a valid expression should not have the expression value suppressed' do
|
749
|
+
klass = Pry::CommandSet.new do
|
750
|
+
command "hello", "" do
|
751
|
+
eval_string.replace("6")
|
752
|
+
end
|
753
|
+
end
|
754
|
+
str_output = StringIO.new
|
755
|
+
Pry.new(:input => StringIO.new("def yo\nhello\n"), :output => str_output, :commands => klass).rep
|
756
|
+
str_output.string.should =~ /6/
|
757
|
+
end
|
758
|
+
|
759
|
+
|
760
|
+
it 'a command (with :keep_retval => true) that replaces eval_string with a valid expression should overwrite the eval_string with the return value' do
|
761
|
+
klass = Pry::CommandSet.new do
|
762
|
+
command "hello", "", :keep_retval => true do
|
763
|
+
eval_string.replace("6")
|
764
|
+
7
|
765
|
+
end
|
766
|
+
end
|
767
|
+
str_output = StringIO.new
|
768
|
+
Pry.new(:input => StringIO.new("def yo\nhello\n"), :output => str_output, :commands => klass).rep
|
769
|
+
str_output.string.should =~ /7/
|
770
|
+
str_output.string.should.not =~ /6/
|
771
|
+
end
|
772
|
+
|
773
|
+
it 'a command that return a value in a multi-line expression should clear the expression and return the value' do
|
774
|
+
klass = Pry::CommandSet.new do
|
775
|
+
command "hello", "", :keep_retval => true do
|
776
|
+
5
|
777
|
+
end
|
778
|
+
end
|
779
|
+
str_output = StringIO.new
|
780
|
+
Pry.new(:input => StringIO.new("def yo\nhello\n"), :output => str_output, :commands => klass).rep
|
781
|
+
str_output.string.should =~ /5/
|
782
|
+
end
|
783
|
+
|
784
|
+
|
710
785
|
it 'should set the commands default, and the default should be overridable' do
|
711
786
|
klass = Pry::CommandSet.new do
|
712
787
|
command "hello" do
|
@@ -926,23 +1001,23 @@ describe Pry do
|
|
926
1001
|
|
927
1002
|
describe "pry return values" do
|
928
1003
|
it 'should return the target object' do
|
929
|
-
Pry.start(self, :input => StringIO.new("exit"), :output => Pry::NullOutput).should == self
|
1004
|
+
Pry.start(self, :input => StringIO.new("exit-all"), :output => Pry::NullOutput).should == self
|
930
1005
|
end
|
931
1006
|
|
932
|
-
it 'should return the parameter given to exit' do
|
933
|
-
Pry.start(self, :input => StringIO.new("exit 10"), :output => Pry::NullOutput).should == 10
|
1007
|
+
it 'should return the parameter given to exit-all' do
|
1008
|
+
Pry.start(self, :input => StringIO.new("exit-all 10"), :output => Pry::NullOutput).should == 10
|
934
1009
|
end
|
935
1010
|
|
936
|
-
it 'should return the parameter (multi word string) given to exit' do
|
937
|
-
Pry.start(self, :input => StringIO.new("exit \"john mair\""), :output => Pry::NullOutput).should == "john mair"
|
1011
|
+
it 'should return the parameter (multi word string) given to exit-all' do
|
1012
|
+
Pry.start(self, :input => StringIO.new("exit-all \"john mair\""), :output => Pry::NullOutput).should == "john mair"
|
938
1013
|
end
|
939
1014
|
|
940
|
-
it 'should return the parameter (function call) given to exit' do
|
941
|
-
Pry.start(self, :input => StringIO.new("exit 'abc'.reverse"), :output => Pry::NullOutput).should == 'cba'
|
1015
|
+
it 'should return the parameter (function call) given to exit-all' do
|
1016
|
+
Pry.start(self, :input => StringIO.new("exit-all 'abc'.reverse"), :output => Pry::NullOutput).should == 'cba'
|
942
1017
|
end
|
943
1018
|
|
944
|
-
it 'should return the parameter (self) given to exit' do
|
945
|
-
Pry.start("carl", :input => StringIO.new("exit self"), :output => Pry::NullOutput).should == "carl"
|
1019
|
+
it 'should return the parameter (self) given to exit-all' do
|
1020
|
+
Pry.start("carl", :input => StringIO.new("exit-all self"), :output => Pry::NullOutput).should == "carl"
|
946
1021
|
end
|
947
1022
|
end
|
948
1023
|
|
@@ -1047,11 +1122,106 @@ describe Pry do
|
|
1047
1122
|
end
|
1048
1123
|
end
|
1049
1124
|
|
1125
|
+
describe "view_clip used for displaying an object in a truncated format" do
|
1126
|
+
|
1127
|
+
VC_MAX_LENGTH = 60
|
1128
|
+
|
1129
|
+
describe "given an object with an #inspect string" do
|
1130
|
+
it "returns the #<> format of the object (never use inspect)" do
|
1131
|
+
o = Object.new
|
1132
|
+
def o.inspect; "a" * VC_MAX_LENGTH; end
|
1133
|
+
|
1134
|
+
Pry.view_clip(o, VC_MAX_LENGTH).should =~ /#<Object/
|
1135
|
+
end
|
1136
|
+
end
|
1137
|
+
|
1138
|
+
describe "given the 'main' object" do
|
1139
|
+
it "returns the #inspect of main (special case)" do
|
1140
|
+
o = TOPLEVEL_BINDING.eval('self')
|
1141
|
+
Pry.view_clip(o, VC_MAX_LENGTH).should == o.inspect
|
1142
|
+
end
|
1143
|
+
end
|
1144
|
+
|
1145
|
+
describe "given the a Numeric, String or Symbol object" do
|
1146
|
+
[1, 2.0, -5, "hello", :test].each do |o|
|
1147
|
+
it "returns the #inspect of the special-cased immediate object: #{o}" do
|
1148
|
+
Pry.view_clip(o, VC_MAX_LENGTH).should == o.inspect
|
1149
|
+
end
|
1150
|
+
end
|
1151
|
+
|
1152
|
+
# only testing with String here :)
|
1153
|
+
it "returns #<> format of the special-cased immediate object if #inspect is longer than maximum" do
|
1154
|
+
o = "o" * (VC_MAX_LENGTH + 1)
|
1155
|
+
Pry.view_clip(o, VC_MAX_LENGTH).should =~ /#<String/
|
1156
|
+
end
|
1157
|
+
end
|
1158
|
+
|
1159
|
+
describe "given an object with an #inspect string as long as the maximum specified" do
|
1160
|
+
it "returns the #<> format of the object (never use inspect)" do
|
1161
|
+
o = Object.new
|
1162
|
+
def o.inspect; "a" * VC_MAX_LENGTH; end
|
1163
|
+
|
1164
|
+
Pry.view_clip(o, VC_MAX_LENGTH).should =~ /#<Object/
|
1165
|
+
end
|
1166
|
+
end
|
1167
|
+
|
1168
|
+
describe "given a regular object with an #inspect string longer than the maximum specified" do
|
1169
|
+
|
1170
|
+
describe "when the object is a regular one" do
|
1171
|
+
it "returns a string of the #<class name:object idish> format" do
|
1172
|
+
o = Object.new
|
1173
|
+
def o.inspect; "a" * (VC_MAX_LENGTH + 1); end
|
1174
|
+
|
1175
|
+
Pry.view_clip(o, VC_MAX_LENGTH).should =~ /#<Object/
|
1176
|
+
end
|
1177
|
+
end
|
1178
|
+
|
1179
|
+
describe "when the object is a Class or a Module" do
|
1180
|
+
describe "without a name (usually a c = Class.new)" do
|
1181
|
+
it "returns a string of the #<class name:object idish> format" do
|
1182
|
+
c, m = Class.new, Module.new
|
1183
|
+
|
1184
|
+
Pry.view_clip(c, VC_MAX_LENGTH).should =~ /#<Class/
|
1185
|
+
Pry.view_clip(m, VC_MAX_LENGTH).should =~ /#<Module/
|
1186
|
+
end
|
1187
|
+
end
|
1188
|
+
|
1189
|
+
describe "with a #name longer than the maximum specified" do
|
1190
|
+
it "returns a string of the #<class name:object idish> format" do
|
1191
|
+
c, m = Class.new, Module.new
|
1192
|
+
|
1193
|
+
|
1194
|
+
def c.name; "a" * (VC_MAX_LENGTH + 1); end
|
1195
|
+
def m.name; "a" * (VC_MAX_LENGTH + 1); end
|
1196
|
+
|
1197
|
+
Pry.view_clip(c, VC_MAX_LENGTH).should =~ /#<Class/
|
1198
|
+
Pry.view_clip(m, VC_MAX_LENGTH).should =~ /#<Module/
|
1199
|
+
end
|
1200
|
+
end
|
1201
|
+
|
1202
|
+
describe "with a #name shorter than or equal to the maximum specified" do
|
1203
|
+
it "returns a string of the #<class name:object idish> format" do
|
1204
|
+
c, m = Class.new, Module.new
|
1205
|
+
|
1206
|
+
def c.name; "a" * VC_MAX_LENGTH; end
|
1207
|
+
def m.name; "a" * VC_MAX_LENGTH; end
|
1208
|
+
|
1209
|
+
Pry.view_clip(c, VC_MAX_LENGTH).should == c.name
|
1210
|
+
Pry.view_clip(m, VC_MAX_LENGTH).should == m.name
|
1211
|
+
end
|
1212
|
+
end
|
1213
|
+
|
1214
|
+
end
|
1215
|
+
|
1216
|
+
end
|
1217
|
+
|
1218
|
+
end
|
1219
|
+
|
1050
1220
|
it 'should set the hooks default, and the default should be overridable' do
|
1051
|
-
Pry.input = InputTester.new("exit")
|
1221
|
+
Pry.input = InputTester.new("exit-all")
|
1052
1222
|
Pry.hooks = {
|
1053
|
-
:before_session => proc { |out,_| out.puts "HELLO" },
|
1054
|
-
:after_session => proc { |out,_| out.puts "BYE" }
|
1223
|
+
:before_session => proc { |out,_,_| out.puts "HELLO" },
|
1224
|
+
:after_session => proc { |out,_,_| out.puts "BYE" }
|
1055
1225
|
}
|
1056
1226
|
|
1057
1227
|
str_output = StringIO.new
|
@@ -1064,8 +1234,8 @@ describe Pry do
|
|
1064
1234
|
str_output = StringIO.new
|
1065
1235
|
Pry.new(:output => str_output,
|
1066
1236
|
:hooks => {
|
1067
|
-
:before_session => proc { |out,_| out.puts "MORNING" },
|
1068
|
-
:after_session => proc { |out,_| out.puts "EVENING" }
|
1237
|
+
:before_session => proc { |out,_,_| out.puts "MORNING" },
|
1238
|
+
:after_session => proc { |out,_,_| out.puts "EVENING" }
|
1069
1239
|
}
|
1070
1240
|
).repl
|
1071
1241
|
|
@@ -1077,7 +1247,7 @@ describe Pry do
|
|
1077
1247
|
str_output = StringIO.new
|
1078
1248
|
Pry.new(:output => str_output,
|
1079
1249
|
:hooks => {
|
1080
|
-
:before_session => proc { |out,_| out.puts "OPEN" }
|
1250
|
+
:before_session => proc { |out,_,_| out.puts "OPEN" }
|
1081
1251
|
}
|
1082
1252
|
).repl
|
1083
1253
|
|
@@ -1087,7 +1257,7 @@ describe Pry do
|
|
1087
1257
|
str_output = StringIO.new
|
1088
1258
|
Pry.new(:output => str_output,
|
1089
1259
|
:hooks => {
|
1090
|
-
:after_session => proc { |out,_| out.puts "CLOSE" }
|
1260
|
+
:after_session => proc { |out,_,_| out.puts "CLOSE" }
|
1091
1261
|
}
|
1092
1262
|
).repl
|
1093
1263
|
|