pry 0.9.11.4-java → 0.9.12-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 (47) hide show
  1. data/.travis.yml +2 -0
  2. data/CHANGELOG +19 -0
  3. data/Rakefile +4 -0
  4. data/lib/pry.rb +1 -1
  5. data/lib/pry/cli.rb +14 -8
  6. data/lib/pry/code.rb +3 -3
  7. data/lib/pry/command.rb +20 -5
  8. data/lib/pry/command_set.rb +3 -3
  9. data/lib/pry/commands.rb +1 -1
  10. data/lib/pry/commands/disabled_commands.rb +2 -0
  11. data/lib/pry/commands/ls.rb +1 -2
  12. data/lib/pry/commands/reload_code.rb +8 -1
  13. data/lib/pry/commands/show_info.rb +66 -5
  14. data/lib/pry/commands/show_source.rb +2 -1
  15. data/lib/pry/commands/whereami.rb +87 -19
  16. data/lib/pry/completion.rb +13 -4
  17. data/lib/pry/helpers/base_helpers.rb +5 -2
  18. data/lib/pry/helpers/command_helpers.rb +3 -1
  19. data/lib/pry/helpers/documentation_helpers.rb +18 -7
  20. data/lib/pry/helpers/table.rb +4 -4
  21. data/lib/pry/indent.rb +2 -7
  22. data/lib/pry/method.rb +89 -129
  23. data/lib/pry/method/disowned.rb +53 -0
  24. data/lib/pry/method/weird_method_locator.rb +186 -0
  25. data/lib/pry/module_candidate.rb +13 -8
  26. data/lib/pry/pager.rb +12 -11
  27. data/lib/pry/plugins.rb +2 -0
  28. data/lib/pry/pry_class.rb +19 -3
  29. data/lib/pry/pry_instance.rb +3 -0
  30. data/lib/pry/terminal.rb +78 -0
  31. data/lib/pry/version.rb +1 -1
  32. data/lib/pry/wrapped_module.rb +63 -1
  33. data/spec/Procfile +3 -0
  34. data/spec/command_helpers_spec.rb +21 -1
  35. data/spec/commands/ls_spec.rb +4 -0
  36. data/spec/commands/show_doc_spec.rb +255 -123
  37. data/spec/commands/show_source_spec.rb +421 -236
  38. data/spec/commands/whereami_spec.rb +60 -11
  39. data/spec/completion_spec.rb +6 -0
  40. data/spec/documentation_helper_spec.rb +73 -0
  41. data/spec/fixtures/whereami_helper.rb +6 -0
  42. data/spec/helpers/table_spec.rb +19 -0
  43. data/spec/method_spec.rb +24 -7
  44. metadata +12 -5
  45. data/.gemtest +0 -0
  46. data/lib/pry/commands/deprecated_commands.rb +0 -2
  47. data/lib/pry/terminal_info.rb +0 -48
data/lib/pry/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Pry
2
- VERSION = "0.9.11.4"
2
+ VERSION = "0.9.12"
3
3
  end
@@ -65,6 +65,30 @@ class Pry
65
65
  @doc = nil
66
66
  end
67
67
 
68
+ # Returns an array of the names of the constants accessible in the wrapped
69
+ # module. This provides a consistent interface between 1.8 and 1.9 and also
70
+ # avoids the problem of accidentally calling the singleton method
71
+ # `Module.constants`.
72
+ # @param [Boolean] inherit (true) Include the names of constants from
73
+ # included modules?
74
+ def constants(inherit = true)
75
+ method = Module.instance_method(:constants).bind(@wrapped)
76
+
77
+ # If we're on 1.8, we have to manually remove ancestors' constants. If
78
+ # we're on 1.9, though, it's better to use the built-in `inherit` param,
79
+ # since it doesn't do things like incorrectly remove Pry::Config.
80
+ if method.arity == 0
81
+ consts = method.call
82
+ if !inherit
83
+ consts -= (@wrapped.ancestors - [@wrapped]).map(&:constants).flatten
84
+ end
85
+ else
86
+ consts = method.call(inherit)
87
+ end
88
+
89
+ consts
90
+ end
91
+
68
92
  # The prefix that would appear before methods defined on this class.
69
93
  #
70
94
  # i.e. the "String." or "String#" in String.new and String#initialize.
@@ -99,6 +123,18 @@ class Pry
99
123
  wrapped != wrapped.ancestors.first
100
124
  end
101
125
 
126
+ # Is this strictly a module? (does not match classes)
127
+ # @return [Boolean]
128
+ def module?
129
+ wrapped.instance_of?(Module)
130
+ end
131
+
132
+ # Is this strictly a class?
133
+ # @return [Boolean]
134
+ def class?
135
+ wrapped.instance_of?(Class)
136
+ end
137
+
102
138
  # Get the instance associated with this singleton class.
103
139
  #
104
140
  # @raise ArgumentError: tried to get instance of non singleton class
@@ -205,13 +241,27 @@ class Pry
205
241
  @memoized_candidates[rank] ||= Candidate.new(self, rank)
206
242
  end
207
243
 
208
-
209
244
  # @return [Fixnum] The number of candidate definitions for the
210
245
  # current module.
211
246
  def number_of_candidates
212
247
  method_candidates.count
213
248
  end
214
249
 
250
+ # @note On JRuby 1.9 and higher, in certain conditions, this method chucks
251
+ # away its ability to be quick (when there are lots of monkey patches,
252
+ # like in Rails). However, it should be efficient enough on other rubies.
253
+ # @see https://github.com/jruby/jruby/issues/525
254
+ # @return [Enumerator, Array] on JRuby 1.9 and higher returns Array, on
255
+ # other rubies returns Enumerator
256
+ def candidates
257
+ enum = generator.new do |y|
258
+ (0...number_of_candidates).each do |num|
259
+ y.yield candidate(num)
260
+ end
261
+ end
262
+ Pry::Helpers::BaseHelpers.jruby_19? ? enum.to_a : enum
263
+ end
264
+
215
265
  # @return [Boolean] Whether YARD docs are available for this module.
216
266
  def yard_docs?
217
267
  !!(defined?(YARD) && YARD::Registry.at(name))
@@ -237,6 +287,18 @@ class Pry
237
287
 
238
288
  private
239
289
 
290
+ # Ruby 1.8 doesn't support `Enumerator` (it's called Generator instead)
291
+ #
292
+ # @return [Object] Return the appropriate generator class.
293
+ def generator
294
+ @generator ||= if defined?(Enumerator)
295
+ Enumerator
296
+ else
297
+ require 'generator'
298
+ Generator
299
+ end
300
+ end
301
+
240
302
  # @return [Pry::WrappedModule::Candidate] The candidate of rank 0,
241
303
  # that is the 'monkey patch' of this module with the highest
242
304
  # number of methods. It is considered the 'canonical' definition
data/spec/Procfile ADDED
@@ -0,0 +1,3 @@
1
+ # Run this with:
2
+ # gem install foreman && foreman start -f spec/Procfile
3
+ pryhere: sh -c '(cd ..; rake pry)'
@@ -5,5 +5,25 @@ describe Pry::Helpers::CommandHelpers do
5
5
  @helper = Pry::Helpers::CommandHelpers
6
6
  end
7
7
 
8
- # FIXME: currently no tests
8
+ describe "unindent" do
9
+ it "should remove the same prefix from all lines" do
10
+ @helper.unindent(" one\n two\n").should == "one\ntwo\n"
11
+ end
12
+
13
+ it "should not be phased by empty lines" do
14
+ @helper.unindent(" one\n\n two\n").should == "one\n\ntwo\n"
15
+ end
16
+
17
+ it "should only remove a common prefix" do
18
+ @helper.unindent(" one\n two\n").should == " one\ntwo\n"
19
+ end
20
+
21
+ it "should also remove tabs if present" do
22
+ @helper.unindent("\tone\n\ttwo\n").should == "one\ntwo\n"
23
+ end
24
+
25
+ it "should ignore lines starting with --" do
26
+ @helper.unindent(" one\n--\n two\n").should == "one\n--\ntwo\n"
27
+ end
28
+ end
9
29
  end
@@ -93,6 +93,10 @@ describe "ls" do
93
93
  "ls Module.new{ def shinanagarns; 4; end; public :shinanagarns }")
94
94
  output.should =~ /shinanagarns/
95
95
  end
96
+
97
+ it "should behave normally when invoked on Module itself" do
98
+ pry_eval("ls Module").should.not =~ /Pry/
99
+ end
96
100
  end
97
101
 
98
102
  describe "constants" do
@@ -200,179 +200,311 @@ if !PryTestHelpers.mri18_and_no_real_source_location?
200
200
  def woof
201
201
  end
202
202
  end
203
- RUBY
204
- t.eval('show-doc TobinaMyDog').should =~ /hello tobina/
205
- Object.remove_const :TobinaMyDog
203
+ RUBY
204
+ t.eval('show-doc TobinaMyDog').should =~ /hello tobina/
205
+ Object.remove_const :TobinaMyDog
206
+ end
206
207
  end
207
208
  end
208
- end
209
209
 
210
- it 'should lookup module name with respect to current context' do
211
- constant_scope(:AlphaClass, :BetaClass) do
212
- # top-level beta
213
- class BetaClass
214
- def alpha
210
+ it 'should lookup module name with respect to current context' do
211
+ constant_scope(:AlphaClass, :BetaClass) do
212
+ # top-level beta
213
+ class BetaClass
214
+ def alpha
215
+ end
216
+ end
217
+
218
+ class AlphaClass
219
+ # nested beta
220
+ class BetaClass
221
+ def beta
222
+ end
223
+ end
215
224
  end
225
+
226
+ pry_eval(AlphaClass, "show-doc BetaClass").should =~ /nested beta/
216
227
  end
228
+ end
217
229
 
218
- class AlphaClass
219
- # nested beta
220
- class BetaClass
230
+ it 'should look up nested modules' do
231
+ constant_scope(:AlphaClass) do
232
+ class AlphaClass
233
+ # nested beta
234
+ class BetaClass
235
+ def beta
236
+ end
237
+ end
238
+ end
239
+
240
+ pry_eval("show-doc AlphaClass::BetaClass").should =~
241
+ /nested beta/
242
+ end
243
+ end
244
+
245
+ describe "show-doc -a" do
246
+ it 'should show the docs for all monkeypatches defined in different files' do
247
+ # local monkeypatch
248
+ class TestClassForShowSource
221
249
  def beta
222
250
  end
223
251
  end
252
+
253
+ result = pry_eval("show-doc TestClassForShowSource -a")
254
+ result.should =~ /used by/
255
+ result.should =~ /local monkeypatch/
224
256
  end
225
257
 
226
- pry_eval(AlphaClass, "show-doc BetaClass").should =~ /nested beta/
258
+ describe "messages relating to -a" do
259
+ it 'indicates all available monkeypatches can be shown with -a when (when -a not used and more than one candidate exists for class)' do
260
+ class TestClassForShowSource
261
+ def beta
262
+ end
263
+ end
264
+
265
+ result = pry_eval('show-doc TestClassForShowSource')
266
+ result.should =~ /available monkeypatches/
267
+ end
268
+
269
+ it 'shouldnt say anything about monkeypatches when only one candidate exists for selected class' do
270
+ class Aarrrrrghh
271
+ def o;end
272
+ end
273
+
274
+ result = pry_eval('show-doc Aarrrrrghh')
275
+ result.should.not =~ /available monkeypatches/
276
+ Object.remove_const(:Aarrrrrghh)
277
+ end
278
+ end
227
279
  end
228
- end
229
280
 
230
- it 'should look up nested modules' do
231
- constant_scope(:AlphaClass) do
232
- class AlphaClass
233
- # nested beta
234
- class BetaClass
235
- def beta
281
+ describe "when no class/module arg is given" do
282
+ before do
283
+ module TestHost
284
+
285
+ # hello there froggy
286
+ module M
287
+ def d; end
288
+ def e; end
236
289
  end
237
290
  end
238
291
  end
239
292
 
240
- pry_eval("show-doc AlphaClass::BetaClass").should =~
241
- /nested beta/
293
+ after do
294
+ Object.remove_const(:TestHost)
295
+ end
296
+
297
+ it 'should return doc for current module' do
298
+ pry_eval(TestHost::M, "show-doc").should =~ /hello there froggy/
299
+ end
242
300
  end
243
- end
244
301
 
245
- describe "show-doc -a" do
246
- it 'should show the docs for all monkeypatches defined in different files' do
247
- # local monkeypatch
248
- class TestClassForShowSource
249
- def beta
302
+ # FIXME: THis is nto a good spec anyway, because i dont think it
303
+ # SHOULD skip!
304
+ describe "should skip over broken modules" do
305
+ before do
306
+ module TestHost
307
+ # hello
308
+ module M
309
+ binding.eval("def a; end", "dummy.rb", 1)
310
+ binding.eval("def b; end", "dummy.rb", 2)
311
+ binding.eval("def c; end", "dummy.rb", 3)
312
+ end
313
+
314
+ # goodbye
315
+ module M
316
+ def d; end
317
+ def e; end
318
+ end
250
319
  end
251
320
  end
252
321
 
253
- result = pry_eval("show-doc TestClassForShowSource -a")
254
- result.should =~ /used by/
255
- result.should =~ /local monkeypatch/
322
+ after do
323
+ Object.remove_const(:TestHost)
324
+ end
325
+
326
+ it 'should return doc for first valid module' do
327
+ result = pry_eval("show-doc TestHost::M")
328
+ result.should =~ /goodbye/
329
+ result.should.not =~ /hello/
330
+ end
256
331
  end
257
332
  end
258
333
 
259
- describe "when no class/module arg is given" do
334
+ describe "on commands" do
335
+ # mostly copied & modified from test_help.rb
260
336
  before do
261
- module TestHost
262
-
263
- # hello there froggy
264
- module M
265
- def d; end
266
- def e; end
267
- end
337
+ @oldset = Pry.config.commands
338
+ @set = Pry.config.commands = Pry::CommandSet.new do
339
+ import Pry::Commands
268
340
  end
269
341
  end
270
342
 
271
343
  after do
272
- Object.remove_const(:TestHost)
344
+ Pry.config.commands = @oldset
273
345
  end
274
346
 
275
- it 'should return doc for current module' do
276
- pry_eval(TestHost::M, "show-doc").should =~ /hello there froggy/
347
+ it 'should display help for a specific command' do
348
+ pry_eval('show-doc ls').should =~ /Usage: ls/
277
349
  end
278
- end
279
350
 
280
- # FIXME: THis is nto a good spec anyway, because i dont think it
281
- # SHOULD skip!
282
- # describe "should skip over broken modules" do
283
- # before do
284
- # module TestHost
285
- # # hello
286
- # module M
287
- # binding.eval("def a; end", "dummy.rb", 1)
288
- # binding.eval("def b; end", "dummy.rb", 2)
289
- # binding.eval("def c; end", "dummy.rb", 3)
290
- # end
291
-
292
- # # goodbye
293
- # module M
294
- # def d; end
295
- # def e; end
296
- # end
297
- # end
298
- # end
299
-
300
- # after do
301
- # Object.remove_const(:TestHost)
302
- # end
303
-
304
- # it 'should return doc for first valid module' do
305
- # result = pry_eval("show-doc TestHost::M")
306
- # result.should =~ /goodbye/
307
- # result.should.not =~ /hello/
308
- # end
309
- # end
310
- end
351
+ it 'should display help for a regex command with a "listing"' do
352
+ @set.command /bar(.*)/, "Test listing", :listing => "foo" do; end
353
+ pry_eval('show-doc foo').should =~ /Test listing/
354
+ end
311
355
 
312
- describe "on commands" do
313
- # mostly copied & modified from test_help.rb
314
- before do
315
- @oldset = Pry.config.commands
316
- @set = Pry.config.commands = Pry::CommandSet.new do
317
- import Pry::Commands
356
+ it 'should display help for a command with a spaces in its name' do
357
+ @set.command "command with spaces", "description of a command with spaces" do; end
358
+ pry_eval('show-doc command with spaces').should =~ /description of a command with spaces/
318
359
  end
319
- end
320
360
 
321
- after do
322
- Pry.config.commands = @oldset
323
- end
361
+ describe "class commands" do
362
+ before do
363
+ # pretty pink pincers
364
+ class LobsterLady < Pry::ClassCommand
365
+ match "lobster-lady"
366
+ description "nada."
367
+ def process
368
+ "lobster"
369
+ end
370
+ end
324
371
 
325
- it 'should display help for a specific command' do
326
- pry_eval('show-doc ls').should =~ /Usage: ls/
327
- end
372
+ Pry.commands.add_command(LobsterLady)
373
+ end
374
+
375
+ after do
376
+ Object.remove_const(:LobsterLady)
377
+ end
328
378
 
329
- it 'should display help for a regex command with a "listing"' do
330
- @set.command /bar(.*)/, "Test listing", :listing => "foo" do; end
331
- pry_eval('show-doc foo').should =~ /Test listing/
379
+ it 'should display "help" when looking up by command name' do
380
+ pry_eval('show-doc lobster-lady').should =~ /nada/
381
+ Pry.commands.delete("lobster-lady")
382
+ end
383
+
384
+ it 'should display actual preceding comment for a class command, when class is used (rather than command name) when looking up' do
385
+ pry_eval('show-doc LobsterLady').should =~ /pretty pink pincers/
386
+ Pry.commands.delete("lobster-lady")
387
+ end
388
+ end
332
389
  end
333
390
 
334
- it 'should display help for a command with a spaces in its name' do
335
- @set.command "command with spaces", "description of a command with spaces" do; end
336
- pry_eval('show-doc command with spaces').should =~ /description of a command with spaces/
391
+ describe "should set _file_ and _dir_" do
392
+ it 'should set _file_ and _dir_ to file containing method source' do
393
+ t = pry_tester
394
+ t.process_command "show-doc TestClassForShowSource#alpha"
395
+ t.pry.last_file.should =~ /show_source_doc_examples/
396
+ t.pry.last_dir.should =~ /fixtures/
397
+ end
337
398
  end
338
399
 
339
- describe "class commands" do
340
- before do
341
- # pretty pink pincers
342
- class LobsterLady < Pry::ClassCommand
343
- match "lobster-lady"
344
- description "nada."
345
- def process
346
- "lobster"
400
+ unless Pry::Helpers::BaseHelpers.rbx?
401
+ describe "can't find class docs" do
402
+ describe "for classes" do
403
+ before do
404
+ module Jesus
405
+ class Brian; end
406
+
407
+ # doink-doc
408
+ class Jingle
409
+ def a; :doink; end
410
+ end
411
+
412
+ class Jangle < Jingle; end
413
+ class Bangle < Jangle; end
414
+ end
415
+ end
416
+
417
+ after do
418
+ Object.remove_const(:Jesus)
419
+ end
420
+
421
+ it 'shows superclass doc' do
422
+ t = pry_tester
423
+ t.process_command "show-doc Jesus::Jangle"
424
+ t.last_output.should =~ /doink-doc/
425
+ end
426
+
427
+ it 'errors when class has no superclass to show' do
428
+ t = pry_tester
429
+ lambda { t.process_command "show-doc Jesus::Brian" }.should.raise(Pry::CommandError).message.
430
+ should =~ /Couldn't locate/
431
+ end
432
+
433
+ it 'shows warning when reverting to superclass docs' do
434
+ t = pry_tester
435
+ t.process_command "show-doc Jesus::Jangle"
436
+ t.last_output.should =~ /Warning.*?Cannot find.*?Jesus::Jangle.*Showing.*Jesus::Jingle instead/
437
+ end
438
+
439
+ it 'shows nth level superclass docs (when no intermediary superclasses have code either)' do
440
+ t = pry_tester
441
+ t.process_command "show-doc Jesus::Bangle"
442
+ t.last_output.should =~ /doink-doc/
443
+ end
444
+
445
+ it 'shows correct warning when reverting to nth level superclass' do
446
+ t = pry_tester
447
+ t.process_command "show-doc Jesus::Bangle"
448
+ t.last_output.should =~ /Warning.*?Cannot find.*?Jesus::Bangle.*Showing.*Jesus::Jingle instead/
347
449
  end
348
450
  end
349
451
 
350
- Pry.commands.add_command(LobsterLady)
351
- end
452
+ describe "for modules" do
453
+ before do
454
+ module Jesus
352
455
 
353
- after do
354
- Object.remove_const(:LobsterLady)
355
- end
456
+ # alpha-doc
457
+ module Alpha
458
+ def alpha; :alpha; end
459
+ end
356
460
 
357
- it 'should display "help" when looking up by command name' do
358
- pry_eval('show-doc lobster-lady').should =~ /nada/
359
- Pry.commands.delete("lobster-lady")
360
- end
461
+ module Zeta; end
361
462
 
362
- it 'should display actual preceding comment for a class command, when class is used (rather than command name) when looking up' do
363
- pry_eval('show-doc LobsterLady').should =~ /pretty pink pincers/
364
- Pry.commands.delete("lobster-lady")
365
- end
366
- end
367
- end
463
+ module Beta
464
+ include Alpha
465
+ end
466
+
467
+ module Gamma
468
+ include Beta
469
+ end
470
+ end
471
+ end
368
472
 
369
- describe "should set _file_ and _dir_" do
370
- it 'should set _file_ and _dir_ to file containing method source' do
371
- t = pry_tester
372
- t.process_command "show-doc TestClassForShowSource#alpha"
373
- t.pry.last_file.should =~ /show_source_doc_examples/
374
- t.pry.last_dir.should =~ /fixtures/
473
+ after do
474
+ Object.remove_const(:Jesus)
475
+ end
476
+
477
+ it 'shows included module doc' do
478
+ t = pry_tester
479
+ t.process_command "show-doc Jesus::Beta"
480
+ t.last_output.should =~ /alpha-doc/
481
+ end
482
+
483
+ it 'shows warning when reverting to included module doc' do
484
+ t = pry_tester
485
+ t.process_command "show-doc Jesus::Beta"
486
+ t.last_output.should =~ /Warning.*?Cannot find.*?Jesus::Beta.*Showing.*Jesus::Alpha instead/
487
+ end
488
+
489
+ it 'errors when module has no included module to show' do
490
+ t = pry_tester
491
+ lambda { t.process_command "show-source Jesus::Zeta" }.should.raise(Pry::CommandError).message.
492
+ should =~ /Couldn't locate/
493
+ end
494
+
495
+ it 'shows nth level included module doc (when no intermediary modules have code either)' do
496
+ t = pry_tester
497
+ t.process_command "show-doc Jesus::Gamma"
498
+ t.last_output.should =~ /alpha-doc/
499
+ end
500
+
501
+ it 'shows correct warning when reverting to nth level included module' do
502
+ t = pry_tester
503
+ t.process_command "show-source Jesus::Gamma"
504
+ t.last_output.should =~ /Warning.*?Cannot find.*?Jesus::Gamma.*Showing.*Jesus::Alpha instead/
505
+ end
506
+ end
507
+ end
375
508
  end
376
509
  end
377
510
  end
378
- end