pry 0.9.10pre1-java → 0.9.11-java

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.
Files changed (194) hide show
  1. data/.travis.yml +3 -1
  2. data/CHANGELOG +63 -2
  3. data/CONTRIBUTORS +43 -25
  4. data/Gemfile +7 -0
  5. data/Guardfile +62 -0
  6. data/README.markdown +4 -4
  7. data/Rakefile +34 -35
  8. data/lib/pry.rb +107 -54
  9. data/lib/pry/cli.rb +34 -11
  10. data/lib/pry/code.rb +165 -182
  11. data/lib/pry/code/code_range.rb +70 -0
  12. data/lib/pry/code/loc.rb +92 -0
  13. data/lib/pry/code_object.rb +153 -0
  14. data/lib/pry/command.rb +160 -22
  15. data/lib/pry/command_set.rb +37 -26
  16. data/lib/pry/commands.rb +4 -27
  17. data/lib/pry/commands/amend_line.rb +99 -0
  18. data/lib/pry/commands/bang.rb +20 -0
  19. data/lib/pry/commands/bang_pry.rb +17 -0
  20. data/lib/pry/commands/cat.rb +53 -0
  21. data/lib/pry/commands/cat/abstract_formatter.rb +27 -0
  22. data/lib/pry/commands/cat/exception_formatter.rb +78 -0
  23. data/lib/pry/commands/cat/file_formatter.rb +84 -0
  24. data/lib/pry/commands/cat/input_expression_formatter.rb +43 -0
  25. data/lib/pry/commands/cd.rb +30 -0
  26. data/lib/pry/commands/code_collector.rb +165 -0
  27. data/lib/pry/commands/deprecated_commands.rb +2 -0
  28. data/lib/pry/commands/disable_pry.rb +27 -0
  29. data/lib/pry/commands/easter_eggs.rb +112 -0
  30. data/lib/pry/commands/edit.rb +206 -0
  31. data/lib/pry/commands/edit/exception_patcher.rb +25 -0
  32. data/lib/pry/commands/edit/file_and_line_locator.rb +38 -0
  33. data/lib/pry/commands/edit/method_patcher.rb +122 -0
  34. data/lib/pry/commands/exit.rb +42 -0
  35. data/lib/pry/commands/exit_all.rb +29 -0
  36. data/lib/pry/commands/exit_program.rb +24 -0
  37. data/lib/pry/commands/find_method.rb +199 -0
  38. data/lib/pry/commands/fix_indent.rb +19 -0
  39. data/lib/pry/commands/gem_cd.rb +26 -0
  40. data/lib/pry/commands/gem_install.rb +29 -0
  41. data/lib/pry/commands/gem_list.rb +33 -0
  42. data/lib/pry/commands/gem_open.rb +29 -0
  43. data/lib/pry/commands/gist.rb +95 -0
  44. data/lib/pry/commands/help.rb +164 -0
  45. data/lib/pry/commands/hist.rb +161 -0
  46. data/lib/pry/commands/import_set.rb +22 -0
  47. data/lib/pry/commands/install_command.rb +51 -0
  48. data/lib/pry/commands/jump_to.rb +29 -0
  49. data/lib/pry/commands/ls.rb +339 -0
  50. data/lib/pry/commands/nesting.rb +25 -0
  51. data/lib/pry/commands/play.rb +69 -0
  52. data/lib/pry/commands/pry_backtrace.rb +26 -0
  53. data/lib/pry/commands/pry_version.rb +17 -0
  54. data/lib/pry/commands/raise_up.rb +32 -0
  55. data/lib/pry/commands/reload_code.rb +39 -0
  56. data/lib/pry/commands/reset.rb +18 -0
  57. data/lib/pry/commands/ri.rb +56 -0
  58. data/lib/pry/commands/save_file.rb +61 -0
  59. data/lib/pry/commands/shell_command.rb +43 -0
  60. data/lib/pry/commands/shell_mode.rb +27 -0
  61. data/lib/pry/commands/show_doc.rb +78 -0
  62. data/lib/pry/commands/show_info.rb +139 -0
  63. data/lib/pry/commands/show_input.rb +17 -0
  64. data/lib/pry/commands/show_source.rb +37 -0
  65. data/lib/pry/commands/simple_prompt.rb +22 -0
  66. data/lib/pry/commands/stat.rb +40 -0
  67. data/lib/pry/commands/switch_to.rb +23 -0
  68. data/lib/pry/commands/toggle_color.rb +20 -0
  69. data/lib/pry/commands/whereami.rb +114 -0
  70. data/lib/pry/commands/wtf.rb +57 -0
  71. data/lib/pry/completion.rb +120 -46
  72. data/lib/pry/config.rb +11 -0
  73. data/lib/pry/core_extensions.rb +30 -19
  74. data/lib/pry/editor.rb +129 -0
  75. data/lib/pry/helpers.rb +1 -0
  76. data/lib/pry/helpers/base_helpers.rb +89 -119
  77. data/lib/pry/helpers/command_helpers.rb +7 -122
  78. data/lib/pry/helpers/table.rb +100 -0
  79. data/lib/pry/helpers/text.rb +4 -4
  80. data/lib/pry/history_array.rb +5 -0
  81. data/lib/pry/hooks.rb +1 -3
  82. data/lib/pry/indent.rb +104 -30
  83. data/lib/pry/method.rb +66 -22
  84. data/lib/pry/module_candidate.rb +26 -15
  85. data/lib/pry/pager.rb +70 -0
  86. data/lib/pry/plugins.rb +1 -2
  87. data/lib/pry/pry_class.rb +63 -22
  88. data/lib/pry/pry_instance.rb +58 -37
  89. data/lib/pry/rubygem.rb +74 -0
  90. data/lib/pry/terminal_info.rb +43 -0
  91. data/lib/pry/test/helper.rb +185 -0
  92. data/lib/pry/version.rb +1 -1
  93. data/lib/pry/wrapped_module.rb +58 -24
  94. data/pry.gemspec +21 -37
  95. data/{test/test_cli.rb → spec/cli_spec.rb} +0 -0
  96. data/spec/code_object_spec.rb +277 -0
  97. data/{test/test_code.rb → spec/code_spec.rb} +19 -1
  98. data/{test/test_command_helpers.rb → spec/command_helpers_spec.rb} +0 -0
  99. data/{test/test_command_integration.rb → spec/command_integration_spec.rb} +38 -46
  100. data/{test/test_command_set.rb → spec/command_set_spec.rb} +18 -1
  101. data/{test/test_command.rb → spec/command_spec.rb} +250 -149
  102. data/spec/commands/amend_line_spec.rb +247 -0
  103. data/spec/commands/bang_spec.rb +19 -0
  104. data/spec/commands/cat_spec.rb +164 -0
  105. data/spec/commands/cd_spec.rb +250 -0
  106. data/spec/commands/disable_pry_spec.rb +25 -0
  107. data/spec/commands/edit_spec.rb +727 -0
  108. data/spec/commands/exit_all_spec.rb +34 -0
  109. data/spec/commands/exit_program_spec.rb +19 -0
  110. data/spec/commands/exit_spec.rb +34 -0
  111. data/{test/test_default_commands/test_find_method.rb → spec/commands/find_method_spec.rb} +27 -7
  112. data/spec/commands/gem_list_spec.rb +26 -0
  113. data/spec/commands/gist_spec.rb +75 -0
  114. data/{test/test_default_commands/test_help.rb → spec/commands/help_spec.rb} +8 -9
  115. data/spec/commands/hist_spec.rb +181 -0
  116. data/spec/commands/jump_to_spec.rb +15 -0
  117. data/spec/commands/ls_spec.rb +177 -0
  118. data/spec/commands/play_spec.rb +140 -0
  119. data/spec/commands/raise_up_spec.rb +56 -0
  120. data/spec/commands/save_file_spec.rb +177 -0
  121. data/spec/commands/show_doc_spec.rb +378 -0
  122. data/spec/commands/show_input_spec.rb +17 -0
  123. data/spec/commands/show_source_spec.rb +597 -0
  124. data/spec/commands/whereami_spec.rb +154 -0
  125. data/spec/completion_spec.rb +233 -0
  126. data/spec/control_d_handler_spec.rb +58 -0
  127. data/spec/editor_spec.rb +79 -0
  128. data/{test/test_exception_whitelist.rb → spec/exception_whitelist_spec.rb} +0 -0
  129. data/{test → spec/fixtures}/candidate_helper1.rb +0 -0
  130. data/{test → spec/fixtures}/candidate_helper2.rb +0 -0
  131. data/{test/test_default_commands → spec/fixtures}/example.erb +0 -0
  132. data/spec/fixtures/example_nesting.rb +33 -0
  133. data/spec/fixtures/show_source_doc_examples.rb +15 -0
  134. data/{test → spec/fixtures}/testrc +0 -0
  135. data/{test → spec/fixtures}/testrcbad +0 -0
  136. data/spec/helper.rb +34 -0
  137. data/spec/helpers/bacon.rb +86 -0
  138. data/spec/helpers/mock_pry.rb +43 -0
  139. data/spec/helpers/table_spec.rb +83 -0
  140. data/{test/test_history_array.rb → spec/history_array_spec.rb} +21 -19
  141. data/{test/test_hooks.rb → spec/hooks_spec.rb} +0 -0
  142. data/{test/test_indent.rb → spec/indent_spec.rb} +24 -0
  143. data/{test/test_input_stack.rb → spec/input_stack_spec.rb} +4 -0
  144. data/{test/test_method.rb → spec/method_spec.rb} +65 -1
  145. data/{test/test_prompt.rb → spec/prompt_spec.rb} +0 -0
  146. data/{test/test_pry_defaults.rb → spec/pry_defaults_spec.rb} +14 -14
  147. data/{test/test_pry_history.rb → spec/pry_history_spec.rb} +15 -0
  148. data/spec/pry_output_spec.rb +95 -0
  149. data/{test/test_pry.rb → spec/pry_spec.rb} +74 -32
  150. data/{test/test_sticky_locals.rb → spec/sticky_locals_spec.rb} +27 -25
  151. data/{test/test_syntax_checking.rb → spec/syntax_checking_spec.rb} +17 -1
  152. data/{test/test_wrapped_module.rb → spec/wrapped_module_spec.rb} +92 -5
  153. metadata +239 -115
  154. data/examples/example_basic.rb +0 -15
  155. data/examples/example_command_override.rb +0 -32
  156. data/examples/example_commands.rb +0 -36
  157. data/examples/example_hooks.rb +0 -9
  158. data/examples/example_image_edit.rb +0 -67
  159. data/examples/example_input.rb +0 -7
  160. data/examples/example_input2.rb +0 -29
  161. data/examples/example_output.rb +0 -11
  162. data/examples/example_print.rb +0 -6
  163. data/examples/example_prompt.rb +0 -9
  164. data/examples/helper.rb +0 -6
  165. data/lib/pry/default_commands/cd.rb +0 -81
  166. data/lib/pry/default_commands/commands.rb +0 -62
  167. data/lib/pry/default_commands/context.rb +0 -98
  168. data/lib/pry/default_commands/easter_eggs.rb +0 -95
  169. data/lib/pry/default_commands/editing.rb +0 -420
  170. data/lib/pry/default_commands/find_method.rb +0 -169
  171. data/lib/pry/default_commands/gems.rb +0 -84
  172. data/lib/pry/default_commands/gist.rb +0 -187
  173. data/lib/pry/default_commands/help.rb +0 -127
  174. data/lib/pry/default_commands/hist.rb +0 -120
  175. data/lib/pry/default_commands/input_and_output.rb +0 -306
  176. data/lib/pry/default_commands/introspection.rb +0 -410
  177. data/lib/pry/default_commands/ls.rb +0 -272
  178. data/lib/pry/default_commands/misc.rb +0 -38
  179. data/lib/pry/default_commands/navigating_pry.rb +0 -110
  180. data/lib/pry/default_commands/whereami.rb +0 -92
  181. data/lib/pry/extended_commands/experimental.rb +0 -7
  182. data/test/helper.rb +0 -223
  183. data/test/test_completion.rb +0 -62
  184. data/test/test_control_d_handler.rb +0 -45
  185. data/test/test_default_commands/test_cd.rb +0 -321
  186. data/test/test_default_commands/test_context.rb +0 -288
  187. data/test/test_default_commands/test_documentation.rb +0 -315
  188. data/test/test_default_commands/test_gems.rb +0 -18
  189. data/test/test_default_commands/test_input.rb +0 -428
  190. data/test/test_default_commands/test_introspection.rb +0 -511
  191. data/test/test_default_commands/test_ls.rb +0 -151
  192. data/test/test_default_commands/test_shell.rb +0 -343
  193. data/test/test_default_commands/test_show_source.rb +0 -432
  194. 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{ import Pry::DefaultCommands::Help }
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::DefaultCommands::Help
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
- def options(opt)
216
- opt.on :f, :four, "A numeric four", :as => Integer, :optional_argument => true
217
- end
218
+ def options(opt)
219
+ opt.on :f, :four, "A numeric four", :as => Integer, :optional_argument => true
220
+ end
218
221
 
219
- def process
220
- args.should == ['four']
221
- opts[:f].should == 4
222
- end
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
- redirect_pry_io(InputTester.new("walking-spanish | do",
356
- " :jesus",
357
- "end",
358
- "exit-all"), out = StringIO.new) do
359
- Pry.start @context, :commands => @set
360
- end
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", "litella's been screeching for a blind pig.", :takes_block => true do |x, y|
366
- inject_var(:@x, x, target)
367
- inject_var(:@y, y, target)
368
- inject_var(:@block_var, command_block.call, target)
369
- end
370
- redirect_pry_io(InputTester.new("walking-spanish john carl| { :jesus }",
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
- redirect_pry_io(InputTester.new("walking-spanish | do ; :jesus; end",
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
- redirect_pry_io(InputTester.new("walking-spanish | do; :jesus; end",
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
- redirect_pry_io(InputTester.new("walking-spanish | { :jesus }",
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
- redirect_pry_io(InputTester.new("walking-spanish | { :jesus }",
484
- "exit-all"), out = StringIO.new) do
485
- Pry.start @context, :commands => @set
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
- redirect_pry_io(InputTester.new("walking-spanish | { :jesus }",
499
- "exit-all")) do
500
- Pry.start @context, :commands => @set
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
- redirect_pry_io(InputTester.new("walking-spanish | { |x, y| [x, y] }",
517
- "exit-all")) do
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
- redirect_pry_io(InputTester.new("walking-spanish | do |x, y|",
533
- " [x, y]",
534
- "end",
535
- "exit-all")) do
536
- Pry.start @context, :commands => @set
537
- end
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
- redirect_pry_io(InputTester.new("var = :hello",
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
- inject_var(:@x, block.call, target)
617
+ block.call
573
618
  end
574
619
  end
575
- redirect_pry_io(InputTester.new("walking-spanish | { :jesus }",
576
- "exit-all")) do
577
- Pry.start @context, :commands => @set
578
- end
579
- @context.instance_variable_get(:@x).should == nil
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
- redirect_pry_io(InputTester.new("walking-spanish | { :jesus }",
589
- "exit-all"), out = StringIO.new) do
590
- Pry.start @context, :commands => @set
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 "commands made with custom sub-classes" do
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 "So just how many sound technicians does it take to change a lightbulb? 1? 2? 3? 1-2-3? Testing?"
604
- options :shellwords => false, :listing => "my-test"
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 "should allow creating custom sub-classes of Pry::Command" do
619
- mock_pry("my---test").should =~ /my-testmy-test/
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
- it "should show the source of the process method" do
623
- mock_pry("show-command my-test").should =~ /output.puts command_name/
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
- instance = nil
655
- redirect_pry_io(InputTester.new("litella",
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
- instance = nil
666
- redirect_pry_io(InputTester.new("litella", "litella",
667
- "exit-all")) do
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
- instance = nil
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
- instance.command_state["litella"].my_state.should == 1
683
- instance.command_state["sanders"].my_state.should =="wood"
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
- instance = nil
688
- redirect_pry_io(InputTester.new("hello-world", "Hello-world", "exit-all")) do
689
- instance = Pry.new(:commands => @set)
690
- instance.repl
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
- instance.command_state[/[Hh]ello-world/].my_state.should == 4
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