pry 0.9.9.6pre2-i386-mswin32 → 0.9.10-i386-mswin32
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
@@ -1,5 +1,23 @@
|
|
1
1
|
require 'helper'
|
2
|
+
|
2
3
|
describe "commands" do
|
4
|
+
before do
|
5
|
+
@str_output = StringIO.new
|
6
|
+
@o = Object.new
|
7
|
+
|
8
|
+
# Shortcuts. They save a lot of typing.
|
9
|
+
@bs1 = "Pad.bs1 = _pry_.binding_stack.dup"
|
10
|
+
@bs2 = "Pad.bs2 = _pry_.binding_stack.dup"
|
11
|
+
@bs3 = "Pad.bs3 = _pry_.binding_stack.dup"
|
12
|
+
|
13
|
+
@self = "Pad.self = self"
|
14
|
+
|
15
|
+
Pad.bong = "bong"
|
16
|
+
end
|
17
|
+
|
18
|
+
after do
|
19
|
+
Pad.clear
|
20
|
+
end
|
3
21
|
|
4
22
|
describe "alias_command" do
|
5
23
|
it 'should make an aliasd command behave like its original' do
|
@@ -112,56 +130,186 @@ describe "commands" do
|
|
112
130
|
end
|
113
131
|
end
|
114
132
|
|
133
|
+
describe "Pry::Command#run" do
|
134
|
+
it 'should allow running of commands with following whitespace' do
|
135
|
+
set = Pry::CommandSet.new do
|
136
|
+
import Pry::Commands
|
137
|
+
command "test-run" do
|
138
|
+
run "cd / "
|
139
|
+
end
|
140
|
+
end
|
141
|
+
redirect_pry_io(InputTester.new("cd 1/2/3/4/5/6", @bs1, "test-run",
|
142
|
+
@self, @bs2, "exit-all")) do
|
143
|
+
Pry.start(@o, :commands => set)
|
144
|
+
end
|
145
|
+
|
146
|
+
Pad.bs1.size.should == 7
|
147
|
+
Pad.self.should == @o
|
148
|
+
Pad.bs2.size.should == 1
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'should allow running of cd command when contained in a single string' do
|
152
|
+
set = Pry::CommandSet.new do
|
153
|
+
import Pry::Commands
|
154
|
+
command "test-run" do
|
155
|
+
run "cd /"
|
156
|
+
end
|
157
|
+
end
|
158
|
+
redirect_pry_io(InputTester.new("cd 1/2/3/4/5/6", @bs1, "test-run",
|
159
|
+
@self, @bs2, "exit-all")) do
|
160
|
+
Pry.start(@o, :commands => set)
|
161
|
+
end
|
162
|
+
|
163
|
+
Pad.bs1.size.should == 7
|
164
|
+
Pad.self.should == @o
|
165
|
+
Pad.bs2.size.should == 1
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'should allow running of cd command when split into array' do
|
169
|
+
set = Pry::CommandSet.new do
|
170
|
+
import Pry::Commands
|
171
|
+
command "test-run" do
|
172
|
+
run "cd", "/"
|
173
|
+
end
|
174
|
+
end
|
175
|
+
redirect_pry_io(InputTester.new("cd 1/2/3/4/5/6", @bs1, "test-run",
|
176
|
+
@self, @bs2, "exit-all")) do
|
177
|
+
Pry.start(@o, :commands => set)
|
178
|
+
end
|
179
|
+
|
180
|
+
Pad.bs1.size.should == 7
|
181
|
+
Pad.self.should == @o
|
182
|
+
Pad.bs2.size.should == 1
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'should run a command from within a command' do
|
186
|
+
klass = Pry::CommandSet.new do
|
187
|
+
command "v" do
|
188
|
+
output.puts "v command"
|
189
|
+
end
|
190
|
+
|
191
|
+
command "run_v" do
|
192
|
+
run "v"
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
Pry.new(:input => InputTester.new("run_v"), :output => @str_output, :commands => klass).rep
|
197
|
+
|
198
|
+
@str_output.string.should =~ /v command/
|
199
|
+
end
|
200
|
+
|
201
|
+
it 'should run a regex command from within a command' do
|
202
|
+
klass = Pry::CommandSet.new do
|
203
|
+
command /v(.*)?/ do |arg|
|
204
|
+
output.puts "v #{arg}"
|
205
|
+
end
|
206
|
+
|
207
|
+
command "run_v" do
|
208
|
+
run "vbaby"
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
redirect_pry_io(InputTester.new("run_v"), @str_output) do
|
213
|
+
Pry.new(:commands => klass).rep
|
214
|
+
end
|
215
|
+
|
216
|
+
@str_output.string.should =~ /v baby/
|
217
|
+
end
|
218
|
+
|
219
|
+
it 'should run a command from within a command with arguments' do
|
220
|
+
klass = Pry::CommandSet.new do
|
221
|
+
command /v(\w+)/ do |arg1, arg2|
|
222
|
+
output.puts "v #{arg1} #{arg2}"
|
223
|
+
end
|
224
|
+
|
225
|
+
command "run_v_explicit_parameter" do
|
226
|
+
run "vbaby", "param"
|
227
|
+
end
|
228
|
+
|
229
|
+
command "run_v_embedded_parameter" do
|
230
|
+
run "vbaby param"
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
["run_v_explicit_parameter", "run_v_embedded_parameter"].each do |cmd|
|
235
|
+
redirect_pry_io(InputTester.new(cmd), @str_output) do
|
236
|
+
Pry.new(:commands => klass).rep
|
237
|
+
end
|
238
|
+
@str_output.string.should =~ /v baby param/
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
describe "Pry#run_command" do
|
244
|
+
it 'should run a command in a specified context' do
|
245
|
+
b = Pry.binding_for(7)
|
246
|
+
p = Pry.new(:output => @str_output)
|
247
|
+
p.run_command("ls -m", "", b)
|
248
|
+
p.output.string.should =~ /divmod/
|
249
|
+
end
|
250
|
+
|
251
|
+
it 'should run a command that modifies the passed in eval_string' do
|
252
|
+
b = Pry.binding_for(7)
|
253
|
+
p = Pry.new(:output => @str_output)
|
254
|
+
eval_string = "def hello\npeter pan\n"
|
255
|
+
p.run_command("amend-line !", eval_string, b)
|
256
|
+
eval_string.should =~ /def hello/
|
257
|
+
eval_string.should.not =~ /peter pan/
|
258
|
+
end
|
259
|
+
|
260
|
+
it 'should run a command in the context of a session' do
|
261
|
+
mock_pry("@session_ivar = 10", "_pry_.run_command('ls')").should =~ /@session_ivar/
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
115
265
|
it 'should interpolate ruby code into commands' do
|
116
|
-
|
266
|
+
set = Pry::CommandSet.new do
|
117
267
|
command "hello", "", :keep_retval => true do |arg|
|
118
268
|
arg
|
119
269
|
end
|
120
270
|
end
|
121
271
|
|
122
|
-
|
123
|
-
str_output
|
124
|
-
|
125
|
-
str_output.string.should =~ /
|
126
|
-
$test_interpolation = nil
|
272
|
+
str_input = StringIO.new('hello #{Pad.bong}')
|
273
|
+
Pry.new(:input => str_input, :output => @str_output, :commands => set).rep
|
274
|
+
|
275
|
+
@str_output.string.should =~ /bong/
|
127
276
|
end
|
128
277
|
|
129
278
|
# bug fix for https://github.com/pry/pry/issues/170
|
130
279
|
it 'should not choke on complex string interpolation when checking if ruby code is a command' do
|
131
|
-
redirect_pry_io(InputTester.new('/#{Regexp.escape(File.expand_path("."))}/'), str_output
|
280
|
+
redirect_pry_io(InputTester.new('/#{Regexp.escape(File.expand_path("."))}/'), @str_output) do
|
132
281
|
pry
|
133
282
|
end
|
134
283
|
|
135
|
-
str_output.string.should.not =~ /SyntaxError/
|
284
|
+
@str_output.string.should.not =~ /SyntaxError/
|
136
285
|
end
|
137
286
|
|
138
287
|
it 'should NOT interpolate ruby code into commands if :interpolate => false' do
|
139
|
-
|
288
|
+
set = Pry::CommandSet.new do
|
140
289
|
command "hello", "", :keep_retval => true, :interpolate => false do |arg|
|
141
290
|
arg
|
142
291
|
end
|
143
292
|
end
|
144
293
|
|
145
|
-
|
146
|
-
str_output
|
147
|
-
|
148
|
-
str_output.string.should =~ /
|
149
|
-
$test_interpolation = nil
|
294
|
+
str_input = StringIO.new('hello #{Pad.bong}')
|
295
|
+
Pry.new(:input => str_input, :output => @str_output, :commands => set).rep
|
296
|
+
|
297
|
+
@str_output.string.should =~ /Pad\.bong/
|
150
298
|
end
|
151
299
|
|
152
300
|
it 'should NOT try to interpolate pure ruby code (no commands) ' do
|
153
|
-
|
154
|
-
|
155
|
-
str_output.string.should.not =~ /NameError/
|
301
|
+
Pry.new(:input => StringIO.new('format \'#{aggy}\''), :output => @str_output).rep
|
302
|
+
@str_output.string.should.not =~ /NameError/
|
156
303
|
|
157
|
-
|
158
|
-
|
304
|
+
@str_output = StringIO.new
|
305
|
+
Pry.new(:input => StringIO.new('format #{aggy}'), :output => @str_output).rep
|
306
|
+
@str_output.string.should.not =~ /NameError/
|
159
307
|
|
160
|
-
|
161
|
-
|
308
|
+
@str_output = StringIO.new
|
309
|
+
Pad.interp = "bong"
|
310
|
+
Pry.new(:input => StringIO.new('format \'#{Pad.interp}\''), :output => @str_output).rep
|
162
311
|
|
163
|
-
str_output.string.should.not =~ /
|
164
|
-
$test_interpolation = nil
|
312
|
+
@str_output.string.should.not =~ /bong/
|
165
313
|
end
|
166
314
|
|
167
315
|
it 'should create a command with a space in its name' do
|
@@ -171,12 +319,11 @@ describe "commands" do
|
|
171
319
|
end
|
172
320
|
end
|
173
321
|
|
174
|
-
str_output
|
175
|
-
redirect_pry_io(InputTester.new("hello baby", "exit-all"), str_output) do
|
322
|
+
redirect_pry_io(InputTester.new("hello baby", "exit-all"), @str_output) do
|
176
323
|
Pry.new(:commands => set).rep
|
177
324
|
end
|
178
325
|
|
179
|
-
str_output.string.should =~ /hello baby command/
|
326
|
+
@str_output.string.should =~ /hello baby command/
|
180
327
|
end
|
181
328
|
|
182
329
|
it 'should create a command with a space in its name and pass an argument' do
|
@@ -186,12 +333,11 @@ describe "commands" do
|
|
186
333
|
end
|
187
334
|
end
|
188
335
|
|
189
|
-
str_output
|
190
|
-
redirect_pry_io(InputTester.new("hello baby john"), str_output) do
|
336
|
+
redirect_pry_io(InputTester.new("hello baby john"), @str_output) do
|
191
337
|
Pry.new(:commands => set).rep
|
192
338
|
end
|
193
339
|
|
194
|
-
str_output.string.should =~ /hello baby command john/
|
340
|
+
@str_output.string.should =~ /hello baby command john/
|
195
341
|
end
|
196
342
|
|
197
343
|
it 'should create a regex command and be able to invoke it' do
|
@@ -202,12 +348,11 @@ describe "commands" do
|
|
202
348
|
end
|
203
349
|
end
|
204
350
|
|
205
|
-
str_output
|
206
|
-
redirect_pry_io(InputTester.new("hello1"), str_output) do
|
351
|
+
redirect_pry_io(InputTester.new("hello1"), @str_output) do
|
207
352
|
Pry.new(:commands => set).rep
|
208
353
|
end
|
209
354
|
|
210
|
-
str_output.string.should =~ /hello1/
|
355
|
+
@str_output.string.should =~ /hello1/
|
211
356
|
end
|
212
357
|
|
213
358
|
it 'should create a regex command and pass captures into the args list before regular arguments' do
|
@@ -217,12 +362,11 @@ describe "commands" do
|
|
217
362
|
end
|
218
363
|
end
|
219
364
|
|
220
|
-
str_output
|
221
|
-
redirect_pry_io(InputTester.new("hello1 baby"), str_output) do
|
365
|
+
redirect_pry_io(InputTester.new("hello1 baby"), @str_output) do
|
222
366
|
Pry.new(:commands => set).rep
|
223
367
|
end
|
224
368
|
|
225
|
-
str_output.string.should =~ /hello 1 baby/
|
369
|
+
@str_output.string.should =~ /hello 1 baby/
|
226
370
|
end
|
227
371
|
|
228
372
|
it 'should create a regex command and interpolate the captures' do
|
@@ -232,14 +376,11 @@ describe "commands" do
|
|
232
376
|
end
|
233
377
|
end
|
234
378
|
|
235
|
-
str_output
|
236
|
-
$obj = "bing"
|
237
|
-
redirect_pry_io(InputTester.new('hello #{$obj}'), str_output) do
|
379
|
+
redirect_pry_io(InputTester.new('hello #{Pad.bong}'), @str_output) do
|
238
380
|
Pry.new(:commands => set).rep
|
239
381
|
end
|
240
382
|
|
241
|
-
str_output.string.should =~ /hello
|
242
|
-
$obj = nil
|
383
|
+
@str_output.string.should =~ /hello bong/
|
243
384
|
end
|
244
385
|
|
245
386
|
it 'should create a regex command and arg_string should be interpolated' do
|
@@ -249,22 +390,16 @@ describe "commands" do
|
|
249
390
|
end
|
250
391
|
end
|
251
392
|
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
redirect_pry_io(InputTester.new('hellojohn #{$a1} #{$a2} #{$a3}'), str_output) do
|
393
|
+
Pad.bing = "bing"
|
394
|
+
Pad.bang = "bang"
|
395
|
+
redirect_pry_io(InputTester.new('hellojohn #{Pad.bing} #{Pad.bong} #{Pad.bang}'),
|
396
|
+
@str_output) do
|
257
397
|
Pry.new(:commands => set).rep
|
258
398
|
end
|
259
399
|
|
260
|
-
str_output.string.should =~ /hello john bing bong bang/
|
261
|
-
|
262
|
-
$a1 = nil
|
263
|
-
$a2 = nil
|
264
|
-
$a3 = nil
|
400
|
+
@str_output.string.should =~ /hello john bing bong bang/
|
265
401
|
end
|
266
402
|
|
267
|
-
|
268
403
|
it 'if a regex capture is missing it should be nil' do
|
269
404
|
set = Pry::CommandSet.new do
|
270
405
|
command /hello(.)?/, "" do |c1, a1|
|
@@ -272,22 +407,20 @@ describe "commands" do
|
|
272
407
|
end
|
273
408
|
end
|
274
409
|
|
275
|
-
str_output
|
276
|
-
redirect_pry_io(InputTester.new("hello baby"), str_output) do
|
410
|
+
redirect_pry_io(InputTester.new("hello baby"), @str_output) do
|
277
411
|
Pry.new(:commands => set).rep
|
278
412
|
end
|
279
413
|
|
280
|
-
str_output.string.should =~ /hello nil baby/
|
414
|
+
@str_output.string.should =~ /hello nil baby/
|
281
415
|
end
|
282
416
|
|
283
|
-
it 'should create a command in
|
284
|
-
str_output = StringIO.new
|
417
|
+
it 'should create a command in a nested context and that command should be accessible from the parent' do
|
285
418
|
x = "@x=nil\ncd 7\n_pry_.commands.instance_eval {\ncommand('bing') { |arg| run arg }\n}\ncd ..\nbing ls\nexit-all"
|
286
|
-
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
|
419
|
+
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
|
287
420
|
Pry.new.repl(0)
|
288
421
|
end
|
289
422
|
|
290
|
-
str_output.string.should =~ /@x/
|
423
|
+
@str_output.string.should =~ /@x/
|
291
424
|
end
|
292
425
|
|
293
426
|
it 'should define a command that keeps its return value' do
|
@@ -296,10 +429,10 @@ describe "commands" do
|
|
296
429
|
:kept_hello
|
297
430
|
end
|
298
431
|
end
|
299
|
-
|
300
|
-
Pry.new(:input => StringIO.new("hello\n"), :output => str_output, :commands => klass).rep
|
301
|
-
str_output.string.should =~ /:kept_hello/
|
302
|
-
str_output.string.should =~ /=>/
|
432
|
+
|
433
|
+
Pry.new(:input => StringIO.new("hello\n"), :output => @str_output, :commands => klass).rep
|
434
|
+
@str_output.string.should =~ /:kept_hello/
|
435
|
+
@str_output.string.should =~ /=>/
|
303
436
|
end
|
304
437
|
|
305
438
|
it 'should define a command that does NOT keep its return value' do
|
@@ -308,10 +441,10 @@ describe "commands" do
|
|
308
441
|
:kept_hello
|
309
442
|
end
|
310
443
|
end
|
311
|
-
|
312
|
-
Pry.new(:input => StringIO.new("hello\n"), :output => str_output, :commands => klass).rep
|
313
|
-
(str_output.string =~ /:kept_hello/).should == nil
|
314
|
-
str_output.string !~ /=>/
|
444
|
+
|
445
|
+
Pry.new(:input => StringIO.new("hello\n"), :output => @str_output, :commands => klass).rep
|
446
|
+
(@str_output.string =~ /:kept_hello/).should == nil
|
447
|
+
@str_output.string !~ /=>/
|
315
448
|
end
|
316
449
|
|
317
450
|
it 'should define a command that keeps its return value even when nil' do
|
@@ -320,10 +453,11 @@ str_output.string !~ /=>/
|
|
320
453
|
nil
|
321
454
|
end
|
322
455
|
end
|
323
|
-
|
324
|
-
Pry.new(:input => StringIO.new("hello\n"), :output => str_output, :commands => klass).rep
|
325
|
-
|
326
|
-
|
456
|
+
|
457
|
+
Pry.new(:input => StringIO.new("hello\n"), :output => @str_output, :commands => klass).rep
|
458
|
+
|
459
|
+
@str_output.string.should =~ /nil/
|
460
|
+
@str_output.string.should =~ /=>/
|
327
461
|
end
|
328
462
|
|
329
463
|
it 'should define a command that keeps its return value but does not return when value is void' do
|
@@ -332,9 +466,9 @@ str_output.string !~ /=>/
|
|
332
466
|
void
|
333
467
|
end
|
334
468
|
end
|
335
|
-
|
336
|
-
Pry.new(:input => StringIO.new("hello\n"), :output => str_output, :commands => klass).rep
|
337
|
-
str_output.string.empty?.should == true
|
469
|
+
|
470
|
+
Pry.new(:input => StringIO.new("hello\n"), :output => @str_output, :commands => klass).rep
|
471
|
+
@str_output.string.empty?.should == true
|
338
472
|
end
|
339
473
|
|
340
474
|
it 'a command (with :keep_retval => false) that replaces eval_string with a valid expression should not have the expression value suppressed' do
|
@@ -343,9 +477,9 @@ str_output.string !~ /=>/
|
|
343
477
|
eval_string.replace("6")
|
344
478
|
end
|
345
479
|
end
|
346
|
-
|
347
|
-
Pry.new(:input => StringIO.new("def yo\nhello\n"), :output => str_output, :commands => klass).rep
|
348
|
-
str_output.string.should =~ /6/
|
480
|
+
|
481
|
+
Pry.new(:input => StringIO.new("def yo\nhello\n"), :output => @str_output, :commands => klass).rep
|
482
|
+
@str_output.string.should =~ /6/
|
349
483
|
end
|
350
484
|
|
351
485
|
|
@@ -356,10 +490,11 @@ str_output.string !~ /=>/
|
|
356
490
|
7
|
357
491
|
end
|
358
492
|
end
|
359
|
-
|
360
|
-
Pry.new(:input => StringIO.new("def yo\nhello\n"), :output => str_output, :commands => klass).rep
|
361
|
-
|
362
|
-
str_output.string.should
|
493
|
+
|
494
|
+
Pry.new(:input => StringIO.new("def yo\nhello\n"), :output => @str_output, :commands => klass).rep
|
495
|
+
|
496
|
+
@str_output.string.should =~ /7/
|
497
|
+
@str_output.string.should.not =~ /6/
|
363
498
|
end
|
364
499
|
|
365
500
|
it 'a command that return a value in a multi-line expression should clear the expression and return the value' do
|
@@ -368,11 +503,11 @@ str_output.string !~ /=>/
|
|
368
503
|
5
|
369
504
|
end
|
370
505
|
end
|
371
|
-
str_output = StringIO.new
|
372
|
-
Pry.new(:input => StringIO.new("def yo\nhello\n"), :output => str_output, :commands => klass).rep
|
373
|
-
str_output.string.should =~ /5/
|
374
|
-
end
|
375
506
|
|
507
|
+
Pry.new(:input => StringIO.new("def yo\nhello\n"), :output => @str_output, :commands => klass).rep
|
508
|
+
|
509
|
+
@str_output.string.should =~ /5/
|
510
|
+
end
|
376
511
|
|
377
512
|
it 'should set the commands default, and the default should be overridable' do
|
378
513
|
klass = Pry::CommandSet.new do
|
@@ -383,9 +518,8 @@ str_output.string !~ /=>/
|
|
383
518
|
|
384
519
|
Pry.commands = klass
|
385
520
|
|
386
|
-
|
387
|
-
|
388
|
-
str_output.string.should =~ /hello world/
|
521
|
+
Pry.new(:input => InputTester.new("hello"), :output => @str_output).rep
|
522
|
+
@str_output.string.should =~ /hello world/
|
389
523
|
|
390
524
|
other_klass = Pry::CommandSet.new do
|
391
525
|
command "goodbye", "" do
|
@@ -393,10 +527,10 @@ str_output.string !~ /=>/
|
|
393
527
|
end
|
394
528
|
end
|
395
529
|
|
396
|
-
str_output = StringIO.new
|
530
|
+
@str_output = StringIO.new
|
397
531
|
|
398
|
-
Pry.new(:input => InputTester.new("goodbye"), :output => str_output, :commands => other_klass).rep
|
399
|
-
str_output.string.should =~ /goodbye world/
|
532
|
+
Pry.new(:input => InputTester.new("goodbye"), :output => @str_output, :commands => other_klass).rep
|
533
|
+
@str_output.string.should =~ /goodbye world/
|
400
534
|
end
|
401
535
|
|
402
536
|
it 'should inherit commands from Pry::Commands' do
|
@@ -421,144 +555,6 @@ str_output.string !~ /=>/
|
|
421
555
|
klass.commands["help"].description.should == "blah"
|
422
556
|
end
|
423
557
|
|
424
|
-
|
425
|
-
describe "Pry::Command#run" do
|
426
|
-
it 'should allow running of commands with following whitespace' do
|
427
|
-
$_scratch = Object.new
|
428
|
-
o = Object.new
|
429
|
-
|
430
|
-
set = Pry::CommandSet.new do
|
431
|
-
import Pry::Commands
|
432
|
-
command "test-run" do
|
433
|
-
run "cd / "
|
434
|
-
end
|
435
|
-
end
|
436
|
-
redirect_pry_io(InputTester.new("cd 1/2/3/4/5/6/$_scratch",
|
437
|
-
"@nesting1 = _pry_.binding_stack.size",
|
438
|
-
"test-run",
|
439
|
-
"@obj = self",
|
440
|
-
"@nesting2 = _pry_.binding_stack.size",
|
441
|
-
"exit-all")) do
|
442
|
-
Pry.start(o, :commands => set)
|
443
|
-
end
|
444
|
-
|
445
|
-
$_scratch.instance_variable_get(:@nesting1).should == 8
|
446
|
-
o.instance_variable_get(:@obj).should == o
|
447
|
-
o.instance_variable_get(:@nesting2).should == 1
|
448
|
-
$_scratch = nil
|
449
|
-
end
|
450
|
-
|
451
|
-
it 'should allow running of cd command when contained in a single string' do
|
452
|
-
$_scratch = Object.new
|
453
|
-
o = Object.new
|
454
|
-
|
455
|
-
set = Pry::CommandSet.new do
|
456
|
-
import Pry::Commands
|
457
|
-
command "test-run" do
|
458
|
-
run "cd /"
|
459
|
-
end
|
460
|
-
end
|
461
|
-
redirect_pry_io(InputTester.new("cd 1/2/3/4/5/6/$_scratch",
|
462
|
-
"@nesting1 = _pry_.binding_stack.size",
|
463
|
-
"test-run",
|
464
|
-
"@obj = self",
|
465
|
-
"@nesting2 = _pry_.binding_stack.size",
|
466
|
-
"exit-all")) do
|
467
|
-
Pry.start(o, :commands => set)
|
468
|
-
end
|
469
|
-
|
470
|
-
$_scratch.instance_variable_get(:@nesting1).should == 8
|
471
|
-
o.instance_variable_get(:@obj).should == o
|
472
|
-
o.instance_variable_get(:@nesting2).should == 1
|
473
|
-
$_scratch = nil
|
474
|
-
end
|
475
|
-
|
476
|
-
it 'should allow running of cd command when split into array' do
|
477
|
-
$_scratch = Object.new
|
478
|
-
o = Object.new
|
479
|
-
|
480
|
-
set = Pry::CommandSet.new do
|
481
|
-
import Pry::Commands
|
482
|
-
command "test-run" do
|
483
|
-
run "cd", "/"
|
484
|
-
end
|
485
|
-
end
|
486
|
-
redirect_pry_io(InputTester.new("cd 1/2/3/4/5/6/$_scratch",
|
487
|
-
"@nesting1 = _pry_.binding_stack.size",
|
488
|
-
"test-run",
|
489
|
-
"@obj = self",
|
490
|
-
"@nesting2 = _pry_.binding_stack.size",
|
491
|
-
"exit-all")) do
|
492
|
-
Pry.start(o, :commands => set)
|
493
|
-
end
|
494
|
-
|
495
|
-
$_scratch.instance_variable_get(:@nesting1).should == 8
|
496
|
-
o.instance_variable_get(:@obj).should == o
|
497
|
-
o.instance_variable_get(:@nesting2).should == 1
|
498
|
-
$_scratch = nil
|
499
|
-
end
|
500
|
-
|
501
|
-
it 'should run a command from within a command' do
|
502
|
-
klass = Pry::CommandSet.new do
|
503
|
-
command "v" do
|
504
|
-
output.puts "v command"
|
505
|
-
end
|
506
|
-
|
507
|
-
command "run_v" do
|
508
|
-
run "v"
|
509
|
-
end
|
510
|
-
end
|
511
|
-
|
512
|
-
str_output = StringIO.new
|
513
|
-
Pry.new(:input => InputTester.new("run_v"), :output => str_output, :commands => klass).rep
|
514
|
-
str_output.string.should =~ /v command/
|
515
|
-
end
|
516
|
-
|
517
|
-
it 'should run a regex command from within a command' do
|
518
|
-
klass = Pry::CommandSet.new do
|
519
|
-
command /v(.*)?/ do |arg|
|
520
|
-
output.puts "v #{arg}"
|
521
|
-
end
|
522
|
-
|
523
|
-
command "run_v" do
|
524
|
-
run "vbaby"
|
525
|
-
end
|
526
|
-
end
|
527
|
-
|
528
|
-
str_output = StringIO.new
|
529
|
-
redirect_pry_io(InputTester.new("run_v"), str_output) do
|
530
|
-
Pry.new(:commands => klass).rep
|
531
|
-
end
|
532
|
-
|
533
|
-
str_output.string.should =~ /v baby/
|
534
|
-
end
|
535
|
-
|
536
|
-
it 'should run a command from within a command with arguments' do
|
537
|
-
klass = Pry::CommandSet.new do
|
538
|
-
command /v(\w+)/ do |arg1, arg2|
|
539
|
-
output.puts "v #{arg1} #{arg2}"
|
540
|
-
end
|
541
|
-
|
542
|
-
command "run_v_explicit_parameter" do
|
543
|
-
run "vbaby", "param"
|
544
|
-
end
|
545
|
-
|
546
|
-
command "run_v_embedded_parameter" do
|
547
|
-
run "vbaby param"
|
548
|
-
end
|
549
|
-
end
|
550
|
-
|
551
|
-
["run_v_explicit_parameter", "run_v_embedded_parameter"].each do |cmd|
|
552
|
-
str_output = StringIO.new
|
553
|
-
redirect_pry_io(InputTester.new(cmd), str_output) do
|
554
|
-
Pry.new(:commands => klass).rep
|
555
|
-
end
|
556
|
-
str_output.string.should =~ /v baby param/
|
557
|
-
end
|
558
|
-
end
|
559
|
-
|
560
|
-
end
|
561
|
-
|
562
558
|
it 'should enable an inherited method to access opts and output and target, due to instance_exec' do
|
563
559
|
klass = Pry::CommandSet.new do
|
564
560
|
command "v" do
|
@@ -569,11 +565,10 @@ end
|
|
569
565
|
child_klass = Pry::CommandSet.new klass do
|
570
566
|
end
|
571
567
|
|
572
|
-
str_output = StringIO.new
|
573
568
|
Pry.new(:print => proc {}, :input => InputTester.new("v"),
|
574
|
-
:output => str_output, :commands => child_klass).rep("john")
|
569
|
+
:output => @str_output, :commands => child_klass).rep("john")
|
575
570
|
|
576
|
-
str_output.string.rstrip.should == "john"
|
571
|
+
@str_output.string.rstrip.should == "john"
|
577
572
|
end
|
578
573
|
|
579
574
|
it 'should import commands from another command object' do
|
@@ -617,13 +612,12 @@ end
|
|
617
612
|
# suppress evaluation output
|
618
613
|
Pry.print = proc {}
|
619
614
|
|
620
|
-
str_output
|
621
|
-
|
622
|
-
str_output.string.rstrip.should == "jump-to the music"
|
615
|
+
Pry.new(:input => InputTester.new("jump-to"), :output => @str_output, :commands => klass).rep
|
616
|
+
@str_output.string.rstrip.should == "jump-to the music"
|
623
617
|
|
624
|
-
str_output = StringIO.new
|
625
|
-
Pry.new(:input => InputTester.new("help"), :output => str_output, :commands => klass).rep
|
626
|
-
str_output.string.should == "help to the music\n"
|
618
|
+
@str_output = StringIO.new
|
619
|
+
Pry.new(:input => InputTester.new("help"), :output => @str_output, :commands => klass).rep
|
620
|
+
@str_output.string.should == "help to the music\n"
|
627
621
|
|
628
622
|
|
629
623
|
Pry.reset_defaults
|
@@ -636,12 +630,11 @@ end
|
|
636
630
|
pry_tester.input = InputTester.new("command1", "exit-all")
|
637
631
|
pry_tester.commands = CommandTester
|
638
632
|
|
639
|
-
|
640
|
-
pry_tester.output = str_output
|
633
|
+
pry_tester.output = @str_output
|
641
634
|
|
642
635
|
pry_tester.rep
|
643
636
|
|
644
|
-
str_output.string.should =~ /command1/
|
637
|
+
@str_output.string.should =~ /command1/
|
645
638
|
end
|
646
639
|
|
647
640
|
it 'should run a command with one parameter' do
|
@@ -650,35 +643,10 @@ end
|
|
650
643
|
pry_tester.input = InputTester.new("command2 horsey", "exit-all")
|
651
644
|
pry_tester.commands = CommandTester
|
652
645
|
|
653
|
-
|
654
|
-
pry_tester.output = str_output
|
646
|
+
pry_tester.output = @str_output
|
655
647
|
|
656
648
|
pry_tester.rep
|
657
649
|
|
658
|
-
str_output.string.should =~ /horsey/
|
650
|
+
@str_output.string.should =~ /horsey/
|
659
651
|
end
|
660
652
|
end
|
661
|
-
|
662
|
-
describe "Pry#run_command" do
|
663
|
-
it 'should run a command in a specified context' do
|
664
|
-
b = Pry.binding_for(7)
|
665
|
-
p = Pry.new(:output => StringIO.new)
|
666
|
-
p.run_command("ls -m", "", b)
|
667
|
-
p.output.string.should =~ /divmod/
|
668
|
-
end
|
669
|
-
|
670
|
-
it 'should run a command that modifies the passed in eval_string' do
|
671
|
-
b = Pry.binding_for(7)
|
672
|
-
p = Pry.new(:output => StringIO.new)
|
673
|
-
eval_string = "def hello\npeter pan\n"
|
674
|
-
p.run_command("amend-line !", eval_string, b)
|
675
|
-
eval_string.should =~ /def hello/
|
676
|
-
eval_string.should.not =~ /peter pan/
|
677
|
-
end
|
678
|
-
|
679
|
-
it 'should run a command in the context of a session' do
|
680
|
-
mock_pry("@session_ivar = 10", "_pry_.run_command('ls')").should =~ /@session_ivar/
|
681
|
-
end
|
682
|
-
end
|
683
|
-
|
684
|
-
|