pry 0.9.10pre1-i386-mingw32 → 0.9.11-i386-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +3 -1
- data/CHANGELOG +63 -2
- data/CONTRIBUTORS +43 -25
- data/Gemfile +7 -0
- data/Guardfile +62 -0
- data/README.markdown +4 -4
- data/Rakefile +34 -35
- data/lib/pry.rb +107 -54
- data/lib/pry/cli.rb +34 -11
- data/lib/pry/code.rb +165 -182
- data/lib/pry/code/code_range.rb +70 -0
- data/lib/pry/code/loc.rb +92 -0
- data/lib/pry/code_object.rb +153 -0
- data/lib/pry/command.rb +160 -22
- data/lib/pry/command_set.rb +37 -26
- data/lib/pry/commands.rb +4 -27
- data/lib/pry/commands/amend_line.rb +99 -0
- data/lib/pry/commands/bang.rb +20 -0
- data/lib/pry/commands/bang_pry.rb +17 -0
- data/lib/pry/commands/cat.rb +53 -0
- data/lib/pry/commands/cat/abstract_formatter.rb +27 -0
- data/lib/pry/commands/cat/exception_formatter.rb +78 -0
- data/lib/pry/commands/cat/file_formatter.rb +84 -0
- data/lib/pry/commands/cat/input_expression_formatter.rb +43 -0
- data/lib/pry/commands/cd.rb +30 -0
- data/lib/pry/commands/code_collector.rb +165 -0
- data/lib/pry/commands/deprecated_commands.rb +2 -0
- data/lib/pry/commands/disable_pry.rb +27 -0
- data/lib/pry/commands/easter_eggs.rb +112 -0
- data/lib/pry/commands/edit.rb +206 -0
- data/lib/pry/commands/edit/exception_patcher.rb +25 -0
- data/lib/pry/commands/edit/file_and_line_locator.rb +38 -0
- data/lib/pry/commands/edit/method_patcher.rb +122 -0
- data/lib/pry/commands/exit.rb +42 -0
- data/lib/pry/commands/exit_all.rb +29 -0
- data/lib/pry/commands/exit_program.rb +24 -0
- data/lib/pry/commands/find_method.rb +199 -0
- data/lib/pry/commands/fix_indent.rb +19 -0
- data/lib/pry/commands/gem_cd.rb +26 -0
- data/lib/pry/commands/gem_install.rb +29 -0
- data/lib/pry/commands/gem_list.rb +33 -0
- data/lib/pry/commands/gem_open.rb +29 -0
- data/lib/pry/commands/gist.rb +95 -0
- data/lib/pry/commands/help.rb +164 -0
- data/lib/pry/commands/hist.rb +161 -0
- data/lib/pry/commands/import_set.rb +22 -0
- data/lib/pry/commands/install_command.rb +51 -0
- data/lib/pry/commands/jump_to.rb +29 -0
- data/lib/pry/commands/ls.rb +339 -0
- data/lib/pry/commands/nesting.rb +25 -0
- data/lib/pry/commands/play.rb +69 -0
- data/lib/pry/commands/pry_backtrace.rb +26 -0
- data/lib/pry/commands/pry_version.rb +17 -0
- data/lib/pry/commands/raise_up.rb +32 -0
- data/lib/pry/commands/reload_code.rb +39 -0
- data/lib/pry/commands/reset.rb +18 -0
- data/lib/pry/commands/ri.rb +56 -0
- data/lib/pry/commands/save_file.rb +61 -0
- data/lib/pry/commands/shell_command.rb +43 -0
- data/lib/pry/commands/shell_mode.rb +27 -0
- data/lib/pry/commands/show_doc.rb +78 -0
- data/lib/pry/commands/show_info.rb +139 -0
- data/lib/pry/commands/show_input.rb +17 -0
- data/lib/pry/commands/show_source.rb +37 -0
- data/lib/pry/commands/simple_prompt.rb +22 -0
- data/lib/pry/commands/stat.rb +40 -0
- data/lib/pry/commands/switch_to.rb +23 -0
- data/lib/pry/commands/toggle_color.rb +20 -0
- data/lib/pry/commands/whereami.rb +114 -0
- data/lib/pry/commands/wtf.rb +57 -0
- data/lib/pry/completion.rb +120 -46
- data/lib/pry/config.rb +11 -0
- data/lib/pry/core_extensions.rb +30 -19
- data/lib/pry/editor.rb +129 -0
- data/lib/pry/helpers.rb +1 -0
- data/lib/pry/helpers/base_helpers.rb +89 -119
- data/lib/pry/helpers/command_helpers.rb +7 -122
- data/lib/pry/helpers/table.rb +100 -0
- data/lib/pry/helpers/text.rb +4 -4
- data/lib/pry/history_array.rb +5 -0
- data/lib/pry/hooks.rb +1 -3
- data/lib/pry/indent.rb +104 -30
- data/lib/pry/method.rb +66 -22
- data/lib/pry/module_candidate.rb +26 -15
- data/lib/pry/pager.rb +70 -0
- data/lib/pry/plugins.rb +1 -2
- data/lib/pry/pry_class.rb +63 -22
- data/lib/pry/pry_instance.rb +58 -37
- data/lib/pry/rubygem.rb +74 -0
- data/lib/pry/terminal_info.rb +43 -0
- data/lib/pry/test/helper.rb +185 -0
- data/lib/pry/version.rb +1 -1
- data/lib/pry/wrapped_module.rb +58 -24
- data/pry.gemspec +21 -37
- data/{test/test_cli.rb → spec/cli_spec.rb} +0 -0
- data/spec/code_object_spec.rb +277 -0
- data/{test/test_code.rb → spec/code_spec.rb} +19 -1
- data/{test/test_command_helpers.rb → spec/command_helpers_spec.rb} +0 -0
- data/{test/test_command_integration.rb → spec/command_integration_spec.rb} +38 -46
- data/{test/test_command_set.rb → spec/command_set_spec.rb} +18 -1
- data/{test/test_command.rb → spec/command_spec.rb} +250 -149
- data/spec/commands/amend_line_spec.rb +247 -0
- data/spec/commands/bang_spec.rb +19 -0
- data/spec/commands/cat_spec.rb +164 -0
- data/spec/commands/cd_spec.rb +250 -0
- data/spec/commands/disable_pry_spec.rb +25 -0
- data/spec/commands/edit_spec.rb +727 -0
- data/spec/commands/exit_all_spec.rb +34 -0
- data/spec/commands/exit_program_spec.rb +19 -0
- data/spec/commands/exit_spec.rb +34 -0
- data/{test/test_default_commands/test_find_method.rb → spec/commands/find_method_spec.rb} +27 -7
- data/spec/commands/gem_list_spec.rb +26 -0
- data/spec/commands/gist_spec.rb +75 -0
- data/{test/test_default_commands/test_help.rb → spec/commands/help_spec.rb} +8 -9
- data/spec/commands/hist_spec.rb +181 -0
- data/spec/commands/jump_to_spec.rb +15 -0
- data/spec/commands/ls_spec.rb +177 -0
- data/spec/commands/play_spec.rb +140 -0
- data/spec/commands/raise_up_spec.rb +56 -0
- data/spec/commands/save_file_spec.rb +177 -0
- data/spec/commands/show_doc_spec.rb +378 -0
- data/spec/commands/show_input_spec.rb +17 -0
- data/spec/commands/show_source_spec.rb +597 -0
- data/spec/commands/whereami_spec.rb +154 -0
- data/spec/completion_spec.rb +233 -0
- data/spec/control_d_handler_spec.rb +58 -0
- data/spec/editor_spec.rb +79 -0
- data/{test/test_exception_whitelist.rb → spec/exception_whitelist_spec.rb} +0 -0
- data/{test → spec/fixtures}/candidate_helper1.rb +0 -0
- data/{test → spec/fixtures}/candidate_helper2.rb +0 -0
- data/{test/test_default_commands → spec/fixtures}/example.erb +0 -0
- data/spec/fixtures/example_nesting.rb +33 -0
- data/spec/fixtures/show_source_doc_examples.rb +15 -0
- data/{test → spec/fixtures}/testrc +0 -0
- data/{test → spec/fixtures}/testrcbad +0 -0
- data/spec/helper.rb +34 -0
- data/spec/helpers/bacon.rb +86 -0
- data/spec/helpers/mock_pry.rb +43 -0
- data/spec/helpers/table_spec.rb +83 -0
- data/{test/test_history_array.rb → spec/history_array_spec.rb} +21 -19
- data/{test/test_hooks.rb → spec/hooks_spec.rb} +0 -0
- data/{test/test_indent.rb → spec/indent_spec.rb} +24 -0
- data/{test/test_input_stack.rb → spec/input_stack_spec.rb} +4 -0
- data/{test/test_method.rb → spec/method_spec.rb} +65 -1
- data/{test/test_prompt.rb → spec/prompt_spec.rb} +0 -0
- data/{test/test_pry_defaults.rb → spec/pry_defaults_spec.rb} +14 -14
- data/{test/test_pry_history.rb → spec/pry_history_spec.rb} +15 -0
- data/spec/pry_output_spec.rb +95 -0
- data/{test/test_pry.rb → spec/pry_spec.rb} +74 -32
- data/{test/test_sticky_locals.rb → spec/sticky_locals_spec.rb} +27 -25
- data/{test/test_syntax_checking.rb → spec/syntax_checking_spec.rb} +17 -1
- data/{test/test_wrapped_module.rb → spec/wrapped_module_spec.rb} +92 -5
- metadata +239 -115
- data/examples/example_basic.rb +0 -15
- data/examples/example_command_override.rb +0 -32
- data/examples/example_commands.rb +0 -36
- data/examples/example_hooks.rb +0 -9
- data/examples/example_image_edit.rb +0 -67
- data/examples/example_input.rb +0 -7
- data/examples/example_input2.rb +0 -29
- data/examples/example_output.rb +0 -11
- data/examples/example_print.rb +0 -6
- data/examples/example_prompt.rb +0 -9
- data/examples/helper.rb +0 -6
- data/lib/pry/default_commands/cd.rb +0 -81
- data/lib/pry/default_commands/commands.rb +0 -62
- data/lib/pry/default_commands/context.rb +0 -98
- data/lib/pry/default_commands/easter_eggs.rb +0 -95
- data/lib/pry/default_commands/editing.rb +0 -420
- data/lib/pry/default_commands/find_method.rb +0 -169
- data/lib/pry/default_commands/gems.rb +0 -84
- data/lib/pry/default_commands/gist.rb +0 -187
- data/lib/pry/default_commands/help.rb +0 -127
- data/lib/pry/default_commands/hist.rb +0 -120
- data/lib/pry/default_commands/input_and_output.rb +0 -306
- data/lib/pry/default_commands/introspection.rb +0 -410
- data/lib/pry/default_commands/ls.rb +0 -272
- data/lib/pry/default_commands/misc.rb +0 -38
- data/lib/pry/default_commands/navigating_pry.rb +0 -110
- data/lib/pry/default_commands/whereami.rb +0 -92
- data/lib/pry/extended_commands/experimental.rb +0 -7
- data/test/helper.rb +0 -223
- data/test/test_completion.rb +0 -62
- data/test/test_control_d_handler.rb +0 -45
- data/test/test_default_commands/test_cd.rb +0 -321
- data/test/test_default_commands/test_context.rb +0 -288
- data/test/test_default_commands/test_documentation.rb +0 -315
- data/test/test_default_commands/test_gems.rb +0 -18
- data/test/test_default_commands/test_input.rb +0 -428
- data/test/test_default_commands/test_introspection.rb +0 -511
- data/test/test_default_commands/test_ls.rb +0 -151
- data/test/test_default_commands/test_shell.rb +0 -343
- data/test/test_default_commands/test_show_source.rb +0 -432
- data/test/test_pry_output.rb +0 -41
@@ -2,7 +2,10 @@ require 'helper'
|
|
2
2
|
|
3
3
|
describe Pry::CommandSet do
|
4
4
|
before do
|
5
|
-
@set = Pry::CommandSet.new
|
5
|
+
@set = Pry::CommandSet.new do
|
6
|
+
import Pry::Commands
|
7
|
+
end
|
8
|
+
|
6
9
|
@ctx = {
|
7
10
|
:target => binding,
|
8
11
|
:command_set => @set
|
@@ -607,4 +610,18 @@ describe Pry::CommandSet do
|
|
607
610
|
@set.process_line('nannnnnny oggggg')
|
608
611
|
end
|
609
612
|
end
|
613
|
+
|
614
|
+
if defined?(Bond)
|
615
|
+
describe '.complete' do
|
616
|
+
it "should list all command names" do
|
617
|
+
@set.create_command('susan'){ }
|
618
|
+
@set.complete('sus').should.include 'susan '
|
619
|
+
end
|
620
|
+
|
621
|
+
it "should delegate to commands" do
|
622
|
+
@set.create_command('susan'){ def complete(search); ['--foo']; end }
|
623
|
+
@set.complete('susan ').should == ['--foo']
|
624
|
+
end
|
625
|
+
end
|
626
|
+
end
|
610
627
|
end
|
@@ -4,7 +4,7 @@ describe "Pry::Command" do
|
|
4
4
|
|
5
5
|
before do
|
6
6
|
@set = Pry::CommandSet.new
|
7
|
-
@set.import Pry::
|
7
|
+
@set.import Pry::Commands
|
8
8
|
end
|
9
9
|
|
10
10
|
describe 'call_safely' do
|
@@ -138,7 +138,6 @@ describe "Pry::Command" do
|
|
138
138
|
end
|
139
139
|
end
|
140
140
|
|
141
|
-
|
142
141
|
describe 'context' do
|
143
142
|
context = {
|
144
143
|
:target => binding,
|
@@ -170,12 +169,16 @@ describe "Pry::Command" do
|
|
170
169
|
|
171
170
|
describe 'classy api' do
|
172
171
|
|
173
|
-
it 'should call setup, then options, then process' do
|
172
|
+
it 'should call setup, then subcommands, then options, then process' do
|
174
173
|
cmd = @set.create_command 'rooster', "Has a tasty towel" do
|
175
174
|
def setup
|
176
175
|
output.puts "setup"
|
177
176
|
end
|
178
177
|
|
178
|
+
def subcommands(cmd)
|
179
|
+
output.puts "subcommands"
|
180
|
+
end
|
181
|
+
|
179
182
|
def options(opt)
|
180
183
|
output.puts "options"
|
181
184
|
end
|
@@ -185,7 +188,7 @@ describe "Pry::Command" do
|
|
185
188
|
end
|
186
189
|
end
|
187
190
|
|
188
|
-
mock_command(cmd).output.should == "setup\noptions\nprocess\n"
|
191
|
+
mock_command(cmd).output.should == "setup\nsubcommands\noptions\nprocess\n"
|
189
192
|
end
|
190
193
|
|
191
194
|
it 'should raise a command error if process is not overridden' do
|
@@ -212,14 +215,14 @@ describe "Pry::Command" do
|
|
212
215
|
|
213
216
|
it 'should provide opts and args as provided by slop' do
|
214
217
|
cmd = @set.create_command 'lintilla', "One of 800,000,000 clones" do
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
+
def options(opt)
|
219
|
+
opt.on :f, :four, "A numeric four", :as => Integer, :optional_argument => true
|
220
|
+
end
|
218
221
|
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
222
|
+
def process
|
223
|
+
args.should == ['four']
|
224
|
+
opts[:f].should == 4
|
225
|
+
end
|
223
226
|
end
|
224
227
|
|
225
228
|
mock_command(cmd, %w(--four 4 four))
|
@@ -234,6 +237,70 @@ describe "Pry::Command" do
|
|
234
237
|
cmd.command_options[:shellwords].should == false
|
235
238
|
cmd.command_options[:listing].should == 'number-one'
|
236
239
|
end
|
240
|
+
|
241
|
+
it "should create subcommands" do
|
242
|
+
cmd = @set.create_command 'mum', 'Your mum' do
|
243
|
+
def subcommands(cmd)
|
244
|
+
cmd.command :yell
|
245
|
+
end
|
246
|
+
|
247
|
+
def process
|
248
|
+
opts.fetch_command(:blahblah).should == nil
|
249
|
+
opts.fetch_command(:yell).present?.should == true
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
mock_command(cmd, ['yell'])
|
254
|
+
end
|
255
|
+
|
256
|
+
it "should create subcommand options" do
|
257
|
+
cmd = @set.create_command 'mum', 'Your mum' do
|
258
|
+
def subcommands(cmd)
|
259
|
+
cmd.command :yell do
|
260
|
+
on :p, :person
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
def process
|
265
|
+
args.should == ['papa']
|
266
|
+
opts.fetch_command(:yell).present?.should == true
|
267
|
+
opts.fetch_command(:yell).person?.should == true
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
mock_command(cmd, %w|yell --person papa|)
|
272
|
+
end
|
273
|
+
|
274
|
+
it "should accept top-level arguments" do
|
275
|
+
cmd = @set.create_command 'mum', 'Your mum' do
|
276
|
+
def subcommands(cmd)
|
277
|
+
cmd.on :yell
|
278
|
+
end
|
279
|
+
|
280
|
+
def process
|
281
|
+
args.should == ['yell', 'papa', 'sonny', 'daughter']
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
mock_command(cmd, %w|yell papa sonny daughter|)
|
286
|
+
end
|
287
|
+
|
288
|
+
describe "explicit classes" do
|
289
|
+
before do
|
290
|
+
@x = Class.new(Pry::ClassCommand) do
|
291
|
+
options :baby => :pig
|
292
|
+
match /goat/
|
293
|
+
description "waaaninngggiiigygygygygy"
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
it 'subclasses should inherit options, match and description from superclass' do
|
298
|
+
k = Class.new(@x)
|
299
|
+
k.options.should == @x.options
|
300
|
+
k.match.should == @x.match
|
301
|
+
k.description.should == @x.description
|
302
|
+
end
|
303
|
+
end
|
237
304
|
end
|
238
305
|
|
239
306
|
describe 'tokenize' do
|
@@ -346,32 +413,34 @@ describe "Pry::Command" do
|
|
346
413
|
before do
|
347
414
|
@context = Object.new
|
348
415
|
@set.command "walking-spanish", "down the hall", :takes_block => true do
|
349
|
-
inject_var(:@x, command_block.call, target)
|
416
|
+
PryTestHelpers.inject_var(:@x, command_block.call, target)
|
350
417
|
end
|
351
418
|
@set.import Pry::Commands
|
419
|
+
|
420
|
+
@t = pry_tester(@context, :commands => @set)
|
352
421
|
end
|
353
422
|
|
354
423
|
it 'should accept multiline blocks' do
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
424
|
+
@t.eval <<-EOS
|
425
|
+
walking-spanish | do
|
426
|
+
:jesus
|
427
|
+
end
|
428
|
+
EOS
|
429
|
+
|
361
430
|
@context.instance_variable_get(:@x).should == :jesus
|
362
431
|
end
|
363
432
|
|
364
433
|
it 'should accept normal parameters along with block' do
|
365
|
-
@set.block_command "walking-spanish",
|
366
|
-
|
367
|
-
|
368
|
-
inject_var(:@
|
369
|
-
|
370
|
-
|
371
|
-
"exit-all")) do
|
372
|
-
Pry.start @context, :commands => @set
|
434
|
+
@set.block_command "walking-spanish",
|
435
|
+
"litella's been screeching for a blind pig.",
|
436
|
+
:takes_block => true do |x, y|
|
437
|
+
PryTestHelpers.inject_var(:@x, x, target)
|
438
|
+
PryTestHelpers.inject_var(:@y, y, target)
|
439
|
+
PryTestHelpers.inject_var(:@block_var, command_block.call, target)
|
373
440
|
end
|
374
441
|
|
442
|
+
@t.eval 'walking-spanish john carl| { :jesus }'
|
443
|
+
|
375
444
|
@context.instance_variable_get(:@x).should == "john"
|
376
445
|
@context.instance_variable_get(:@y).should == "carl"
|
377
446
|
@context.instance_variable_get(:@block_var).should == :jesus
|
@@ -379,29 +448,19 @@ describe "Pry::Command" do
|
|
379
448
|
|
380
449
|
describe "single line blocks" do
|
381
450
|
it 'should accept blocks with do ; end' do
|
382
|
-
|
383
|
-
"exit-all"), out = StringIO.new) do
|
384
|
-
Pry.start @context, :commands => @set
|
385
|
-
end
|
451
|
+
@t.eval 'walking-spanish | do ; :jesus; end'
|
386
452
|
@context.instance_variable_get(:@x).should == :jesus
|
387
453
|
end
|
388
454
|
|
389
455
|
it 'should accept blocks with do; end' do
|
390
|
-
|
391
|
-
"exit-all"), out = StringIO.new) do
|
392
|
-
Pry.start @context, :commands => @set
|
393
|
-
end
|
456
|
+
@t.eval 'walking-spanish | do; :jesus; end'
|
394
457
|
@context.instance_variable_get(:@x).should == :jesus
|
395
458
|
end
|
396
459
|
|
397
460
|
it 'should accept blocks with { }' do
|
398
|
-
|
399
|
-
"exit-all"), out = StringIO.new) do
|
400
|
-
Pry.start @context, :commands => @set
|
401
|
-
end
|
461
|
+
@t.eval 'walking-spanish | { :jesus }'
|
402
462
|
@context.instance_variable_get(:@x).should == :jesus
|
403
463
|
end
|
404
|
-
|
405
464
|
end
|
406
465
|
|
407
466
|
describe "block-related content removed from arguments" do
|
@@ -409,36 +468,33 @@ describe "Pry::Command" do
|
|
409
468
|
describe "arg_string" do
|
410
469
|
it 'should remove block-related content from arg_string (with one normal arg)' do
|
411
470
|
@set.block_command "walking-spanish", "down the hall", :takes_block => true do |x, y|
|
412
|
-
inject_var(:@arg_string, arg_string, target)
|
413
|
-
inject_var(:@x, x, target)
|
414
|
-
end
|
415
|
-
redirect_pry_io(InputTester.new("walking-spanish john| { :jesus }",
|
416
|
-
"exit-all")) do
|
417
|
-
Pry.start @context, :commands => @set
|
471
|
+
PryTestHelpers.inject_var(:@arg_string, arg_string, target)
|
472
|
+
PryTestHelpers.inject_var(:@x, x, target)
|
418
473
|
end
|
474
|
+
|
475
|
+
@t.eval 'walking-spanish john| { :jesus }'
|
476
|
+
|
419
477
|
@context.instance_variable_get(:@arg_string).should == @context.instance_variable_get(:@x)
|
420
478
|
end
|
421
479
|
|
422
480
|
it 'should remove block-related content from arg_string (with no normal args)' do
|
423
481
|
@set.block_command "walking-spanish", "down the hall", :takes_block => true do
|
424
|
-
inject_var(:@arg_string, arg_string, target)
|
425
|
-
end
|
426
|
-
redirect_pry_io(InputTester.new("walking-spanish | { :jesus }",
|
427
|
-
"exit-all")) do
|
428
|
-
Pry.start @context, :commands => @set
|
482
|
+
PryTestHelpers.inject_var(:@arg_string, arg_string, target)
|
429
483
|
end
|
484
|
+
|
485
|
+
@t.eval 'walking-spanish | { :jesus }'
|
486
|
+
|
430
487
|
@context.instance_variable_get(:@arg_string).should == ""
|
431
488
|
end
|
432
489
|
|
433
490
|
it 'should NOT remove block-related content from arg_string when :takes_block => false' do
|
434
491
|
block_string = "| { :jesus }"
|
435
492
|
@set.block_command "walking-spanish", "homemade special", :takes_block => false do
|
436
|
-
inject_var(:@arg_string, arg_string, target)
|
437
|
-
end
|
438
|
-
redirect_pry_io(InputTester.new("walking-spanish #{block_string}",
|
439
|
-
"exit-all")) do
|
440
|
-
Pry.start @context, :commands => @set
|
493
|
+
PryTestHelpers.inject_var(:@arg_string, arg_string, target)
|
441
494
|
end
|
495
|
+
|
496
|
+
@t.eval "walking-spanish #{block_string}"
|
497
|
+
|
442
498
|
@context.instance_variable_get(:@arg_string).should == block_string
|
443
499
|
end
|
444
500
|
end
|
@@ -447,26 +503,24 @@ describe "Pry::Command" do
|
|
447
503
|
describe "block_command" do
|
448
504
|
it "should remove block-related content from arguments" do
|
449
505
|
@set.block_command "walking-spanish", "glass is full of sand", :takes_block => true do |x, y|
|
450
|
-
inject_var(:@x, x, target)
|
451
|
-
inject_var(:@y, y, target)
|
452
|
-
end
|
453
|
-
redirect_pry_io(InputTester.new("walking-spanish | { :jesus }",
|
454
|
-
"exit-all"), out = StringIO.new) do
|
455
|
-
Pry.start @context, :commands => @set
|
506
|
+
PryTestHelpers.inject_var(:@x, x, target)
|
507
|
+
PryTestHelpers.inject_var(:@y, y, target)
|
456
508
|
end
|
509
|
+
|
510
|
+
@t.eval 'walking-spanish | { :jesus }'
|
511
|
+
|
457
512
|
@context.instance_variable_get(:@x).should == nil
|
458
513
|
@context.instance_variable_get(:@y).should == nil
|
459
514
|
end
|
460
515
|
|
461
516
|
it "should NOT remove block-related content from arguments if :takes_block => false" do
|
462
517
|
@set.block_command "walking-spanish", "litella screeching for a blind pig", :takes_block => false do |x, y|
|
463
|
-
inject_var(:@x, x, target)
|
464
|
-
inject_var(:@y, y, target)
|
465
|
-
end
|
466
|
-
redirect_pry_io(InputTester.new("walking-spanish | { :jesus }",
|
467
|
-
"exit-all"), out = StringIO.new) do
|
468
|
-
Pry.start @context, :commands => @set
|
518
|
+
PryTestHelpers.inject_var(:@x, x, target)
|
519
|
+
PryTestHelpers.inject_var(:@y, y, target)
|
469
520
|
end
|
521
|
+
|
522
|
+
@t.eval 'walking-spanish | { :jesus }'
|
523
|
+
|
470
524
|
@context.instance_variable_get(:@x).should == "|"
|
471
525
|
@context.instance_variable_get(:@y).should == "{"
|
472
526
|
end
|
@@ -476,14 +530,13 @@ describe "Pry::Command" do
|
|
476
530
|
it "should remove block-related content from arguments" do
|
477
531
|
@set.create_command "walking-spanish", "punk sanders carved one out of wood", :takes_block => true do
|
478
532
|
def process(x, y)
|
479
|
-
inject_var(:@x, x, target)
|
480
|
-
inject_var(:@y, y, target)
|
533
|
+
PryTestHelpers.inject_var(:@x, x, target)
|
534
|
+
PryTestHelpers.inject_var(:@y, y, target)
|
481
535
|
end
|
482
536
|
end
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
end
|
537
|
+
|
538
|
+
@t.eval 'walking-spanish | { :jesus }'
|
539
|
+
|
487
540
|
@context.instance_variable_get(:@x).should == nil
|
488
541
|
@context.instance_variable_get(:@y).should == nil
|
489
542
|
end
|
@@ -491,14 +544,13 @@ describe "Pry::Command" do
|
|
491
544
|
it "should NOT remove block-related content from arguments if :takes_block => false" do
|
492
545
|
@set.create_command "walking-spanish", "down the hall", :takes_block => false do
|
493
546
|
def process(x, y)
|
494
|
-
inject_var(:@x, x, target)
|
495
|
-
inject_var(:@y, y, target)
|
547
|
+
PryTestHelpers.inject_var(:@x, x, target)
|
548
|
+
PryTestHelpers.inject_var(:@y, y, target)
|
496
549
|
end
|
497
550
|
end
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
end
|
551
|
+
|
552
|
+
@t.eval 'walking-spanish | { :jesus }'
|
553
|
+
|
502
554
|
@context.instance_variable_get(:@x).should == "|"
|
503
555
|
@context.instance_variable_get(:@y).should == "{"
|
504
556
|
end
|
@@ -510,13 +562,11 @@ describe "Pry::Command" do
|
|
510
562
|
describe "{} style blocks" do
|
511
563
|
it 'should accept multiple parameters' do
|
512
564
|
@set.block_command "walking-spanish", "down the hall", :takes_block => true do
|
513
|
-
inject_var(:@x, command_block.call(1, 2), target)
|
565
|
+
PryTestHelpers.inject_var(:@x, command_block.call(1, 2), target)
|
514
566
|
end
|
515
567
|
|
516
|
-
|
517
|
-
|
518
|
-
Pry.start @context, :commands => @set
|
519
|
-
end
|
568
|
+
@t.eval 'walking-spanish | { |x, y| [x, y] }'
|
569
|
+
|
520
570
|
@context.instance_variable_get(:@x).should == [1, 2]
|
521
571
|
end
|
522
572
|
end
|
@@ -525,16 +575,16 @@ describe "Pry::Command" do
|
|
525
575
|
it 'should accept multiple parameters' do
|
526
576
|
@set.create_command "walking-spanish", "litella", :takes_block => true do
|
527
577
|
def process
|
528
|
-
inject_var(:@x, command_block.call(1, 2), target)
|
578
|
+
PryTestHelpers.inject_var(:@x, command_block.call(1, 2), target)
|
529
579
|
end
|
530
580
|
end
|
531
581
|
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
582
|
+
@t.eval <<-EOS
|
583
|
+
walking-spanish | do |x, y|
|
584
|
+
[x, y]
|
585
|
+
end
|
586
|
+
EOS
|
587
|
+
|
538
588
|
@context.instance_variable_get(:@x).should == [1, 2]
|
539
589
|
end
|
540
590
|
end
|
@@ -542,11 +592,7 @@ describe "Pry::Command" do
|
|
542
592
|
|
543
593
|
describe "closure behaviour" do
|
544
594
|
it 'should close over locals in the definition context' do
|
545
|
-
|
546
|
-
"walking-spanish | { var }",
|
547
|
-
"exit-all")) do
|
548
|
-
Pry.start @context, :commands => @set
|
549
|
-
end
|
595
|
+
@t.eval 'var = :hello', 'walking-spanish | { var }'
|
550
596
|
@context.instance_variable_get(:@x).should == :hello
|
551
597
|
end
|
552
598
|
end
|
@@ -555,12 +601,11 @@ describe "Pry::Command" do
|
|
555
601
|
describe "block_command" do
|
556
602
|
it "should expose block in command_block method" do
|
557
603
|
@set.block_command "walking-spanish", "glass full of sand", :takes_block => true do
|
558
|
-
inject_var(:@x, command_block.call, target)
|
559
|
-
end
|
560
|
-
redirect_pry_io(InputTester.new("walking-spanish | { :jesus }",
|
561
|
-
"exit-all")) do
|
562
|
-
Pry.start @context, :commands => @set
|
604
|
+
PryTestHelpers.inject_var(:@x, command_block.call, target)
|
563
605
|
end
|
606
|
+
|
607
|
+
@t.eval 'walking-spanish | { :jesus }'
|
608
|
+
|
564
609
|
@context.instance_variable_get(:@x).should == :jesus
|
565
610
|
end
|
566
611
|
end
|
@@ -569,39 +614,39 @@ describe "Pry::Command" do
|
|
569
614
|
it "should NOT expose &block in create_command's process method" do
|
570
615
|
@set.create_command "walking-spanish", "down the hall", :takes_block => true do
|
571
616
|
def process(&block)
|
572
|
-
|
617
|
+
block.call
|
573
618
|
end
|
574
619
|
end
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
620
|
+
@out = StringIO.new
|
621
|
+
|
622
|
+
proc {
|
623
|
+
@t.eval 'walking-spanish | { :jesus }'
|
624
|
+
}.should.raise(NoMethodError)
|
580
625
|
end
|
581
626
|
|
582
627
|
it "should expose block in command_block method" do
|
583
628
|
@set.create_command "walking-spanish", "homemade special", :takes_block => true do
|
584
629
|
def process
|
585
|
-
inject_var(:@x, command_block.call, target)
|
630
|
+
PryTestHelpers.inject_var(:@x, command_block.call, target)
|
586
631
|
end
|
587
632
|
end
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
end
|
633
|
+
|
634
|
+
@t.eval 'walking-spanish | { :jesus }'
|
635
|
+
|
592
636
|
@context.instance_variable_get(:@x).should == :jesus
|
593
637
|
end
|
594
638
|
end
|
595
639
|
end
|
596
640
|
end
|
597
641
|
|
598
|
-
describe "
|
599
|
-
before do
|
642
|
+
describe "a command made with a custom sub-class" do
|
600
643
|
|
644
|
+
before do
|
601
645
|
class MyTestCommand < Pry::ClassCommand
|
602
646
|
match /my-*test/
|
603
|
-
description
|
604
|
-
|
647
|
+
description 'So just how many sound technicians does it take to' \
|
648
|
+
'change a lightbulb? 1? 2? 3? 1-2-3? Testing?'
|
649
|
+
options :shellwords => false, :listing => 'my-test'
|
605
650
|
|
606
651
|
def process
|
607
652
|
output.puts command_name * 2
|
@@ -615,13 +660,71 @@ describe "Pry::Command" do
|
|
615
660
|
Pry.commands.delete 'my-test'
|
616
661
|
end
|
617
662
|
|
618
|
-
it "
|
619
|
-
|
663
|
+
it "allows creation of custom subclasses of Pry::Command" do
|
664
|
+
pry_eval('my---test').should =~ /my-testmy-test/
|
620
665
|
end
|
621
666
|
|
622
|
-
|
623
|
-
|
667
|
+
if !mri18_and_no_real_source_location?
|
668
|
+
it "shows the source of the process method" do
|
669
|
+
pry_eval('show-source my-test').should =~ /output.puts command_name/
|
670
|
+
end
|
624
671
|
end
|
672
|
+
|
673
|
+
describe "command options hash" do
|
674
|
+
it "is always present" do
|
675
|
+
options_hash = {
|
676
|
+
:requires_gem => [],
|
677
|
+
:keep_retval => false,
|
678
|
+
:argument_required => false,
|
679
|
+
:interpolate => true,
|
680
|
+
:shellwords => false,
|
681
|
+
:listing => 'my-test',
|
682
|
+
:use_prefix => true,
|
683
|
+
:takes_block => false
|
684
|
+
}
|
685
|
+
MyTestCommand.options.should == options_hash
|
686
|
+
end
|
687
|
+
|
688
|
+
describe ":listing option" do
|
689
|
+
it "defaults to :match if not set explicitly" do
|
690
|
+
class HappyNewYear < Pry::ClassCommand
|
691
|
+
match 'happy-new-year'
|
692
|
+
description 'Happy New Year 2013'
|
693
|
+
end
|
694
|
+
Pry.commands.add_command HappyNewYear
|
695
|
+
|
696
|
+
HappyNewYear.options[:listing].should == 'happy-new-year'
|
697
|
+
|
698
|
+
Pry.commands.delete 'happy-new-year'
|
699
|
+
end
|
700
|
+
|
701
|
+
it "can be set explicitly" do
|
702
|
+
class MerryChristmas < Pry::ClassCommand
|
703
|
+
match 'merry-christmas'
|
704
|
+
description 'Merry Christmas!'
|
705
|
+
command_options :listing => 'happy-holidays'
|
706
|
+
end
|
707
|
+
Pry.commands.add_command MerryChristmas
|
708
|
+
|
709
|
+
MerryChristmas.options[:listing].should == 'happy-holidays'
|
710
|
+
|
711
|
+
Pry.commands.delete 'merry-christmas'
|
712
|
+
end
|
713
|
+
|
714
|
+
it "equals to :match option's inspect, if :match is Regexp" do
|
715
|
+
class CoolWinter < Pry::ClassCommand
|
716
|
+
match /.*winter/
|
717
|
+
description 'Is winter cool or cool?'
|
718
|
+
end
|
719
|
+
Pry.commands.add_command CoolWinter
|
720
|
+
|
721
|
+
CoolWinter.options[:listing].should == '/.*winter/'
|
722
|
+
|
723
|
+
Pry.commands.delete /.*winter/
|
724
|
+
end
|
725
|
+
end
|
726
|
+
end
|
727
|
+
|
625
728
|
end
|
626
729
|
|
627
730
|
describe "commands can save state" do
|
@@ -648,49 +751,47 @@ describe "Pry::Command" do
|
|
648
751
|
end
|
649
752
|
|
650
753
|
end.import Pry::Commands
|
754
|
+
|
755
|
+
@t = pry_tester(:commands => @set)
|
651
756
|
end
|
652
757
|
|
653
758
|
it 'should save state for the command on the Pry#command_state hash' do
|
654
|
-
|
655
|
-
|
656
|
-
"exit-all")) do
|
657
|
-
instance = Pry.new(:commands => @set)
|
658
|
-
instance.repl
|
659
|
-
end
|
660
|
-
|
661
|
-
instance.command_state["litella"].my_state.should == 1
|
759
|
+
@t.eval 'litella'
|
760
|
+
@t.pry.command_state["litella"].my_state.should == 1
|
662
761
|
end
|
663
762
|
|
664
763
|
it 'should ensure state is maintained between multiple invocations of command' do
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
instance = Pry.new(:commands => @set)
|
669
|
-
instance.repl
|
670
|
-
end
|
671
|
-
|
672
|
-
instance.command_state["litella"].my_state.should == 2
|
764
|
+
@t.eval 'litella'
|
765
|
+
@t.eval 'litella'
|
766
|
+
@t.pry.command_state["litella"].my_state.should == 2
|
673
767
|
end
|
674
768
|
|
675
769
|
it 'should ensure state with same name stored seperately for each command' do
|
676
|
-
|
677
|
-
redirect_pry_io(InputTester.new("litella", "sanders", "exit-all")) do
|
678
|
-
instance = Pry.new(:commands => @set)
|
679
|
-
instance.repl
|
680
|
-
end
|
770
|
+
@t.eval 'litella', 'sanders'
|
681
771
|
|
682
|
-
|
683
|
-
|
772
|
+
@t.pry.command_state["litella"].my_state.should == 1
|
773
|
+
@t.pry.command_state["sanders"].my_state.should =="wood"
|
684
774
|
end
|
685
775
|
|
686
776
|
it 'should ensure state is properly saved for regex commands' do
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
end
|
777
|
+
@t.eval 'hello-world', 'Hello-world'
|
778
|
+
@t.pry.command_state[/[Hh]ello-world/].my_state.should == 4
|
779
|
+
end
|
780
|
+
end
|
692
781
|
|
693
|
-
|
782
|
+
if defined?(Bond)
|
783
|
+
describe 'complete' do
|
784
|
+
it 'should return the arguments that are defined' do
|
785
|
+
@set.create_command "torrid" do
|
786
|
+
def options(opt)
|
787
|
+
opt.on :test
|
788
|
+
opt.on :lest
|
789
|
+
opt.on :pests
|
790
|
+
end
|
791
|
+
end
|
792
|
+
|
793
|
+
@set.complete('torrid ').should.include('--test ')
|
794
|
+
end
|
694
795
|
end
|
695
796
|
end
|
696
797
|
|