pry 0.9.12pre1-java → 0.9.12pre2-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.
@@ -18,7 +18,8 @@ class Pry
18
18
 
19
19
  def process
20
20
  code_object = Pry::CodeObject.lookup(obj_name, _pry_, :super => opts[:super])
21
- cannot_locate_source_error if !code_object
21
+ raise CommandError, no_definition_message if !code_object
22
+ @original_code_object = code_object
22
23
 
23
24
  if show_all_modules?(code_object)
24
25
  # show all monkey patches for a module
@@ -26,7 +27,6 @@ class Pry
26
27
  result = content_and_headers_for_all_module_candidates(code_object)
27
28
  else
28
29
  # show a specific code object
29
-
30
30
  co = code_object_with_accessible_source(code_object)
31
31
  result = content_and_header_for_code_object(co)
32
32
  end
@@ -44,14 +44,24 @@ class Pry
44
44
  # @return [Pry::WrappedModule, Pry::Method, Pry::Command]
45
45
  def code_object_with_accessible_source(code_object)
46
46
  if code_object.is_a?(WrappedModule)
47
- code_object.candidates.find(&:source).tap do |candidate|
48
- cannot_locate_source_error if !candidate
47
+ candidate = code_object.candidates.find(&:source)
48
+ if candidate
49
+ return candidate
50
+ else
51
+ raise CommandError, no_definition_message if !valid_superclass?(code_object)
52
+
53
+ @used_super = true
54
+ code_object_with_accessible_source(code_object.super)
49
55
  end
50
56
  else
51
57
  code_object
52
58
  end
53
59
  end
54
60
 
61
+ def valid_superclass?(code_object)
62
+ code_object.super && code_object.super.wrapped != Object
63
+ end
64
+
55
65
  def content_and_header_for_code_object(code_object)
56
66
  header(code_object) + content_for(code_object)
57
67
  end
@@ -73,8 +83,8 @@ class Pry
73
83
  result
74
84
  end
75
85
 
76
- def cannot_locate_source_error
77
- raise CommandError, "Couldn't locate a definition for #{obj_name}!"
86
+ def no_definition_message
87
+ "Couldn't locate a definition for #{obj_name}!"
78
88
  end
79
89
 
80
90
  # Generate a header (meta-data information) for all the code
@@ -82,9 +92,24 @@ class Pry
82
92
  def header(code_object)
83
93
  file_name, line_num = file_and_line_for(code_object)
84
94
  h = "\n#{Pry::Helpers::Text.bold('From:')} #{file_name} "
85
- h << method_header(code_object, line_num) if code_object.real_method_object?
95
+ h << code_object_header(code_object, line_num)
86
96
  h << "\n#{Pry::Helpers::Text.bold('Number of lines:')} " <<
87
97
  "#{content_for(code_object).lines.count}\n\n"
98
+ h << Helpers::Text.bold('** Warning:') + " Cannot find code for #{@original_code_object.nonblank_name}. Showing superclass #{code_object.nonblank_name} instead. **\n\n" if @used_super
99
+ h
100
+ end
101
+
102
+ def code_object_header(code_object, line_num)
103
+ if code_object.real_method_object?
104
+ method_header(code_object, line_num)
105
+
106
+ # It sucks we have to test for both Pry::WrappedModule and WrappedModule::Candidate,
107
+ # probably indicates a deep refactor needs to happen in those classes.
108
+ elsif code_object.is_a?(Pry::WrappedModule) || code_object.is_a?(Pry::WrappedModule::Candidate)
109
+ module_header(code_object, line_num)
110
+ else
111
+ ""
112
+ end
88
113
  end
89
114
 
90
115
  def method_header(code_object, line_num)
@@ -96,6 +121,13 @@ class Pry
96
121
  h
97
122
  end
98
123
 
124
+ def module_header(code_object, line_num)
125
+ h = ""
126
+ h << "@ line #{line_num}:\n"
127
+ h << text.bold(code_object.module? ? "Module" : "Class")
128
+ h << " #{text.bold('name:')} #{code_object.nonblank_name}"
129
+ end
130
+
99
131
  def method_sections(code_object)
100
132
  {
101
133
  :owner => "\n#{text.bold("Owner:")} #{code_object.owner || "N/A"}\n",
@@ -20,12 +20,16 @@ class Pry
20
20
  attr_reader :line
21
21
  alias_method :source_line, :line
22
22
 
23
- # Methods to delegate to associated `Pry::WrappedModule instance`.
24
- to_delegate = [:lines_for_file, :method_candidates, :name, :wrapped,
25
- :yard_docs?, :number_of_candidates]
23
+ # Methods to delegate to associated `Pry::WrappedModule
24
+ # instance`.
25
+ private_delegates = [:lines_for_file, :method_candidates,
26
+ :yard_docs?, :number_of_candidates]
26
27
 
27
- def_delegators :@wrapper, *to_delegate
28
- private(*to_delegate)
28
+ public_delegates = [:wrapped, :module?, :class?, :name, :nonblank_name]
29
+
30
+ def_delegators :@wrapper, *(private_delegates + public_delegates)
31
+ private *private_delegates
32
+ public *public_delegates
29
33
 
30
34
  # @raise [Pry::CommandError] If `rank` is out of bounds.
31
35
  # @param [Pry::WrappedModule] wrapper The associated
@@ -1,3 +1,3 @@
1
1
  class Pry
2
- VERSION = "0.9.12pre1"
2
+ VERSION = "0.9.12pre2"
3
3
  end
@@ -123,6 +123,18 @@ class Pry
123
123
  wrapped != wrapped.ancestors.first
124
124
  end
125
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
+
126
138
  # Get the instance associated with this singleton class.
127
139
  #
128
140
  # @raise ArgumentError: tried to get instance of non singleton class
@@ -374,5 +374,112 @@ if !PryTestHelpers.mri18_and_no_real_source_location?
374
374
  t.pry.last_dir.should =~ /fixtures/
375
375
  end
376
376
  end
377
+
378
+ describe "can't find class docs" do
379
+ describe "for classes" do
380
+ before do
381
+ module Jesus
382
+ class Brian; end
383
+
384
+ # doink-doc
385
+ class Jingle
386
+ def a; :doink; end
387
+ end
388
+
389
+ class Jangle < Jingle; end
390
+ class Bangle < Jangle; end
391
+ end
392
+ end
393
+
394
+ after do
395
+ Object.remove_const(:Jesus)
396
+ end
397
+
398
+ it 'shows superclass doc' do
399
+ t = pry_tester
400
+ t.process_command "show-doc Jesus::Jangle"
401
+ t.last_output.should =~ /doink-doc/
402
+ end
403
+
404
+ it 'errors when class has no superclass to show' do
405
+ t = pry_tester
406
+ lambda { t.process_command "show-doc Jesus::Brian" }.should.raise(Pry::CommandError).message.
407
+ should =~ /Couldn't locate/
408
+ end
409
+
410
+ it 'shows warning when reverting to superclass docs' do
411
+ t = pry_tester
412
+ t.process_command "show-doc Jesus::Jangle"
413
+ t.last_output.should =~ /Warning.*?Cannot find.*?Jesus::Jangle.*Showing.*Jesus::Jingle instead/
414
+ end
415
+
416
+ it 'shows nth level superclass docs (when no intermediary superclasses have code either)' do
417
+ t = pry_tester
418
+ t.process_command "show-doc Jesus::Bangle"
419
+ t.last_output.should =~ /doink-doc/
420
+ end
421
+
422
+ it 'shows correct warning when reverting to nth level superclass' do
423
+ t = pry_tester
424
+ t.process_command "show-doc Jesus::Bangle"
425
+ t.last_output.should =~ /Warning.*?Cannot find.*?Jesus::Bangle.*Showing.*Jesus::Jingle instead/
426
+ end
427
+ end
428
+ describe "for modules" do
429
+ before do
430
+ module Jesus
431
+
432
+ # alpha-doc
433
+ module Alpha
434
+ def alpha; :alpha; end
435
+ end
436
+
437
+ module Zeta; end
438
+
439
+ module Beta
440
+ include Alpha
441
+ end
442
+
443
+ module Gamma
444
+ include Beta
445
+ end
446
+ end
447
+ end
448
+
449
+ after do
450
+ Object.remove_const(:Jesus)
451
+ end
452
+
453
+ it 'shows included module doc' do
454
+ t = pry_tester
455
+ t.process_command "show-doc Jesus::Beta"
456
+ t.last_output.should =~ /alpha-doc/
457
+ end
458
+
459
+ it 'shows warning when reverting to included module doc' do
460
+ t = pry_tester
461
+ t.process_command "show-doc Jesus::Beta"
462
+ t.last_output.should =~ /Warning.*?Cannot find.*?Jesus::Beta.*Showing.*Jesus::Alpha instead/
463
+ end
464
+
465
+ it 'errors when module has no included module to show' do
466
+ t = pry_tester
467
+ lambda { t.process_command "show-source Jesus::Zeta" }.should.raise(Pry::CommandError).message.
468
+ should =~ /Couldn't locate/
469
+ end
470
+
471
+ it 'shows nth level included module doc (when no intermediary modules have code either)' do
472
+ t = pry_tester
473
+ t.process_command "show-doc Jesus::Gamma"
474
+ t.last_output.should =~ /alpha-doc/
475
+ end
476
+
477
+ it 'shows correct warning when reverting to nth level included module' do
478
+ t = pry_tester
479
+ t.process_command "show-source Jesus::Gamma"
480
+ t.last_output.should =~ /Warning.*?Cannot find.*?Jesus::Gamma.*Showing.*Jesus::Alpha instead/
481
+ end
482
+ end
483
+ end
377
484
  end
378
485
  end
@@ -136,7 +136,7 @@ if !PryTestHelpers.mri18_and_no_real_source_location?
136
136
  end
137
137
 
138
138
  pry_eval(binding, "show-source --super o.foo").
139
- should =~ /:super_wibble/
139
+ should =~ /:super_wibble/
140
140
  end
141
141
 
142
142
  it "should raise a CommandError when super method doesn't exist" do
@@ -219,12 +219,12 @@ if !PryTestHelpers.mri18_and_no_real_source_location?
219
219
  end
220
220
  end
221
221
  ::TestHost.new.hello
222
- EOS
223
- end
222
+ EOS
223
+ end
224
224
 
225
- after do
226
- Object.remove_const(:TestHost)
227
- end
225
+ after do
226
+ Object.remove_const(:TestHost)
227
+ end
228
228
 
229
229
  it "source of variable should take precedence over method that is being shadowed" do
230
230
  source = @t.eval('show-source hello')
@@ -232,124 +232,123 @@ if !PryTestHelpers.mri18_and_no_real_source_location?
232
232
  source.should =~ /proc \{ ' smile ' \}/
233
233
  end
234
234
 
235
- it "source of method being shadowed should take precedence over variable
235
+ it "source of method being shadowed should take precedence over variable
236
236
  if given self.meth_name syntax" do
237
- @t.eval('show-source self.hello').should =~ /def hello/
237
+ @t.eval('show-source self.hello').should =~ /def hello/
238
+ end
238
239
  end
239
240
  end
240
241
 
241
- end
242
-
243
- describe "on variable or constant" do
244
- before do
245
- class TestHost
246
- def hello
247
- "hi there"
242
+ describe "on variable or constant" do
243
+ before do
244
+ class TestHost
245
+ def hello
246
+ "hi there"
247
+ end
248
248
  end
249
249
  end
250
- end
251
250
 
252
- after do
253
- Object.remove_const(:TestHost)
254
- end
251
+ after do
252
+ Object.remove_const(:TestHost)
253
+ end
255
254
 
256
- it "should output source of its class if variable doesn't respond to source_location" do
257
- test_host = TestHost.new
258
- pry_eval(binding, 'show-source test_host').
255
+ it "should output source of its class if variable doesn't respond to source_location" do
256
+ test_host = TestHost.new
257
+ pry_eval(binding, 'show-source test_host').
259
258
  should =~ /class TestHost\n.*def hello/
260
- end
259
+ end
261
260
 
262
- it "should output source of its class if constant doesn't respond to source_location" do
263
- TEST_HOST = TestHost.new
264
- pry_eval(binding, 'show-source TEST_HOST').
261
+ it "should output source of its class if constant doesn't respond to source_location" do
262
+ TEST_HOST = TestHost.new
263
+ pry_eval(binding, 'show-source TEST_HOST').
265
264
  should =~ /class TestHost\n.*def hello/
266
- Object.remove_const(:TEST_HOST)
265
+ Object.remove_const(:TEST_HOST)
266
+ end
267
267
  end
268
- end
269
268
 
270
- describe "on modules" do
271
- before do
272
- class ShowSourceTestSuperClass
273
- def alpha
269
+ describe "on modules" do
270
+ before do
271
+ class ShowSourceTestSuperClass
272
+ def alpha
273
+ end
274
274
  end
275
- end
276
275
 
277
- class ShowSourceTestClass<ShowSourceTestSuperClass
278
- def alpha
276
+ class ShowSourceTestClass<ShowSourceTestSuperClass
277
+ def alpha
278
+ end
279
279
  end
280
- end
281
280
 
282
- module ShowSourceTestSuperModule
283
- def alpha
281
+ module ShowSourceTestSuperModule
282
+ def alpha
283
+ end
284
284
  end
285
- end
286
285
 
287
- module ShowSourceTestModule
288
- include ShowSourceTestSuperModule
289
- def alpha
286
+ module ShowSourceTestModule
287
+ include ShowSourceTestSuperModule
288
+ def alpha
289
+ end
290
290
  end
291
- end
292
291
 
293
- ShowSourceTestClassWeirdSyntax = Class.new do
294
- def beta
292
+ ShowSourceTestClassWeirdSyntax = Class.new do
293
+ def beta
294
+ end
295
295
  end
296
- end
297
296
 
298
- ShowSourceTestModuleWeirdSyntax = Module.new do
299
- def beta
297
+ ShowSourceTestModuleWeirdSyntax = Module.new do
298
+ def beta
299
+ end
300
300
  end
301
301
  end
302
- end
303
302
 
304
- after do
305
- Object.remove_const :ShowSourceTestSuperClass
306
- Object.remove_const :ShowSourceTestClass
307
- Object.remove_const :ShowSourceTestClassWeirdSyntax
308
- Object.remove_const :ShowSourceTestSuperModule
309
- Object.remove_const :ShowSourceTestModule
310
- Object.remove_const :ShowSourceTestModuleWeirdSyntax
311
- end
303
+ after do
304
+ Object.remove_const :ShowSourceTestSuperClass
305
+ Object.remove_const :ShowSourceTestClass
306
+ Object.remove_const :ShowSourceTestClassWeirdSyntax
307
+ Object.remove_const :ShowSourceTestSuperModule
308
+ Object.remove_const :ShowSourceTestModule
309
+ Object.remove_const :ShowSourceTestModuleWeirdSyntax
310
+ end
312
311
 
313
- describe "basic functionality, should find top-level module definitions" do
314
- it 'should show source for a class' do
315
- pry_eval('show-source ShowSourceTestClass').
312
+ describe "basic functionality, should find top-level module definitions" do
313
+ it 'should show source for a class' do
314
+ pry_eval('show-source ShowSourceTestClass').
316
315
  should =~ /class ShowSourceTestClass.*?def alpha/m
317
- end
316
+ end
318
317
 
319
- it 'should show source for a super class' do
320
- pry_eval('show-source -s ShowSourceTestClass').
318
+ it 'should show source for a super class' do
319
+ pry_eval('show-source -s ShowSourceTestClass').
321
320
  should =~ /class ShowSourceTestSuperClass.*?def alpha/m
322
- end
321
+ end
323
322
 
324
- it 'should show source for a module' do
325
- pry_eval('show-source ShowSourceTestModule').
323
+ it 'should show source for a module' do
324
+ pry_eval('show-source ShowSourceTestModule').
326
325
  should =~ /module ShowSourceTestModule/
327
- end
326
+ end
328
327
 
329
- it 'should show source for an ancestor module' do
330
- pry_eval('show-source -s ShowSourceTestModule').
328
+ it 'should show source for an ancestor module' do
329
+ pry_eval('show-source -s ShowSourceTestModule').
331
330
  should =~ /module ShowSourceTestSuperModule/
332
- end
331
+ end
333
332
 
334
- it 'should show source for a class when Const = Class.new syntax is used' do
335
- pry_eval('show-source ShowSourceTestClassWeirdSyntax').
333
+ it 'should show source for a class when Const = Class.new syntax is used' do
334
+ pry_eval('show-source ShowSourceTestClassWeirdSyntax').
336
335
  should =~ /ShowSourceTestClassWeirdSyntax = Class.new/
337
- end
336
+ end
338
337
 
339
- it 'should show source for a super class when Const = Class.new syntax is used' do
340
- pry_eval('show-source -s ShowSourceTestClassWeirdSyntax').
338
+ it 'should show source for a super class when Const = Class.new syntax is used' do
339
+ pry_eval('show-source -s ShowSourceTestClassWeirdSyntax').
341
340
  should =~ /class Object/
342
- end
341
+ end
343
342
 
344
- it 'should show source for a module when Const = Module.new syntax is used' do
345
- pry_eval('show-source ShowSourceTestModuleWeirdSyntax').
343
+ it 'should show source for a module when Const = Module.new syntax is used' do
344
+ pry_eval('show-source ShowSourceTestModuleWeirdSyntax').
346
345
  should =~ /ShowSourceTestModuleWeirdSyntax = Module.new/
346
+ end
347
347
  end
348
- end
349
348
 
350
- if !Pry::Helpers::BaseHelpers.mri_18?
351
- before do
352
- pry_eval unindent(<<-EOS)
349
+ if !Pry::Helpers::BaseHelpers.mri_18?
350
+ before do
351
+ pry_eval unindent(<<-EOS)
353
352
  class Dog
354
353
  def woof
355
354
  end
@@ -359,240 +358,240 @@ if !PryTestHelpers.mri18_and_no_real_source_location?
359
358
  def woof
360
359
  end
361
360
  end
362
- EOS
363
- end
364
-
365
- after do
366
- Object.remove_const :Dog
367
- Object.remove_const :TobinaMyDog
368
- end
361
+ EOS
362
+ end
369
363
 
370
- describe "in REPL" do
371
- it 'should find class defined in repl' do
372
- pry_eval('show-source TobinaMyDog').should =~ /class TobinaMyDog/
364
+ after do
365
+ Object.remove_const :Dog
366
+ Object.remove_const :TobinaMyDog
373
367
  end
374
- it 'should find superclass defined in repl' do
375
- pry_eval('show-source -s TobinaMyDog').should =~ /class Dog/
368
+
369
+ describe "in REPL" do
370
+ it 'should find class defined in repl' do
371
+ pry_eval('show-source TobinaMyDog').should =~ /class TobinaMyDog/
372
+ end
373
+ it 'should find superclass defined in repl' do
374
+ pry_eval('show-source -s TobinaMyDog').should =~ /class Dog/
375
+ end
376
376
  end
377
377
  end
378
- end
379
378
 
380
379
  it 'should lookup module name with respect to current context' do
381
380
 
382
- constant_scope(:AlphaClass, :BetaClass) do
383
- class BetaClass
384
- def alpha
381
+ constant_scope(:AlphaClass, :BetaClass) do
382
+ class BetaClass
383
+ def alpha
384
+ end
385
385
  end
386
- end
387
386
 
388
- class AlphaClass
389
- class BetaClass
390
- def beta
387
+ class AlphaClass
388
+ class BetaClass
389
+ def beta
390
+ end
391
391
  end
392
392
  end
393
- end
394
393
 
395
- pry_eval(AlphaClass, 'show-source BetaClass').should =~ /def beta/
394
+ pry_eval(AlphaClass, 'show-source BetaClass').should =~ /def beta/
395
+ end
396
396
  end
397
- end
398
397
 
399
- it 'should lookup nested modules' do
400
- constant_scope(:AlphaClass) do
401
- class AlphaClass
402
- class BetaClass
403
- def beta
398
+ it 'should lookup nested modules' do
399
+ constant_scope(:AlphaClass) do
400
+ class AlphaClass
401
+ class BetaClass
402
+ def beta
403
+ end
404
404
  end
405
405
  end
406
- end
407
406
 
408
- pry_eval('show-source AlphaClass::BetaClass').should =~ /class Beta/
407
+ pry_eval('show-source AlphaClass::BetaClass').should =~ /class Beta/
408
+ end
409
409
  end
410
- end
411
410
 
412
- # note that pry assumes a class is only monkey-patched at most
413
- # ONCE per file, so will not find multiple monkeypatches in the
414
- # SAME file.
415
- describe "show-source -a" do
416
- it 'should show the source for all monkeypatches defined in different files' do
417
- class TestClassForShowSource
418
- def beta
411
+ # note that pry assumes a class is only monkey-patched at most
412
+ # ONCE per file, so will not find multiple monkeypatches in the
413
+ # SAME file.
414
+ describe "show-source -a" do
415
+ it 'should show the source for all monkeypatches defined in different files' do
416
+ class TestClassForShowSource
417
+ def beta
418
+ end
419
419
  end
420
- end
421
420
 
422
- result = pry_eval('show-source TestClassForShowSource -a')
423
- result.should =~ /def alpha/
424
- result.should =~ /def beta/
425
- end
421
+ result = pry_eval('show-source TestClassForShowSource -a')
422
+ result.should =~ /def alpha/
423
+ result.should =~ /def beta/
424
+ end
426
425
 
427
- it 'should show the source for a class_eval-based monkeypatch' do
428
- TestClassForShowSourceClassEval.class_eval do
429
- def class_eval_method
426
+ it 'should show the source for a class_eval-based monkeypatch' do
427
+ TestClassForShowSourceClassEval.class_eval do
428
+ def class_eval_method
429
+ end
430
430
  end
431
- end
432
431
 
433
- result = pry_eval('show-source TestClassForShowSourceClassEval -a')
434
- result.should =~ /def class_eval_method/
435
- end
432
+ result = pry_eval('show-source TestClassForShowSourceClassEval -a')
433
+ result.should =~ /def class_eval_method/
434
+ end
436
435
 
437
- it 'should ignore -a when object is not a module' do
438
- TestClassForShowSourceClassEval.class_eval do
439
- def class_eval_method
440
- :bing
436
+ it 'should ignore -a when object is not a module' do
437
+ TestClassForShowSourceClassEval.class_eval do
438
+ def class_eval_method
439
+ :bing
440
+ end
441
441
  end
442
- end
443
442
 
444
- result = pry_eval('show-source TestClassForShowSourceClassEval#class_eval_method -a')
445
- result.should =~ /bing/
446
- end
443
+ result = pry_eval('show-source TestClassForShowSourceClassEval#class_eval_method -a')
444
+ result.should =~ /bing/
445
+ end
447
446
 
448
- it 'should show the source for an instance_eval-based monkeypatch' do
449
- TestClassForShowSourceInstanceEval.instance_eval do
450
- def instance_eval_method
447
+ it 'should show the source for an instance_eval-based monkeypatch' do
448
+ TestClassForShowSourceInstanceEval.instance_eval do
449
+ def instance_eval_method
450
+ end
451
451
  end
452
- end
453
452
 
454
- result = pry_eval('show-source TestClassForShowSourceInstanceEval -a')
455
- result.should =~ /def instance_eval_method/
453
+ result = pry_eval('show-source TestClassForShowSourceInstanceEval -a')
454
+ result.should =~ /def instance_eval_method/
455
+ end
456
456
  end
457
- end
458
457
 
459
- describe "when show-source is invoked without a method or class argument" do
460
- before do
461
- module TestHost
462
- class M
463
- def alpha; end
464
- def beta; end
465
- end
458
+ describe "when show-source is invoked without a method or class argument" do
459
+ before do
460
+ module TestHost
461
+ class M
462
+ def alpha; end
463
+ def beta; end
464
+ end
466
465
 
467
- module C
468
- end
466
+ module C
467
+ end
469
468
 
470
- module D
471
- def self.invoked_in_method
472
- pry_eval(binding, 'show-source')
469
+ module D
470
+ def self.invoked_in_method
471
+ pry_eval(binding, 'show-source')
472
+ end
473
473
  end
474
474
  end
475
475
  end
476
- end
477
-
478
- after do
479
- Object.remove_const(:TestHost)
480
- end
481
476
 
482
- describe "inside a module" do
483
- it 'should display module source by default' do
484
- out = pry_eval(TestHost::M, 'show-source')
485
- out.should =~ /class M/
486
- out.should =~ /def alpha/
487
- out.should =~ /def beta/
477
+ after do
478
+ Object.remove_const(:TestHost)
488
479
  end
489
480
 
490
- it 'should be unable to find module source if no methods defined' do
491
- proc {
492
- pry_eval(TestHost::C, 'show-source')
493
- }.should.raise(Pry::CommandError).
494
- message.should =~ /Couldn't locate/
495
- end
481
+ describe "inside a module" do
482
+ it 'should display module source by default' do
483
+ out = pry_eval(TestHost::M, 'show-source')
484
+ out.should =~ /class M/
485
+ out.should =~ /def alpha/
486
+ out.should =~ /def beta/
487
+ end
496
488
 
497
- it 'should display method code (rather than class) if Pry started inside method binding' do
498
- out = TestHost::D.invoked_in_method
499
- out.should =~ /invoked_in_method/
500
- out.should.not =~ /module D/
501
- end
489
+ it 'should be unable to find module source if no methods defined' do
490
+ proc {
491
+ pry_eval(TestHost::C, 'show-source')
492
+ }.should.raise(Pry::CommandError).
493
+ message.should =~ /Couldn't locate/
494
+ end
502
495
 
503
- it 'should display class source when inside instance' do
504
- out = pry_eval(TestHost::M.new, 'show-source')
505
- out.should =~ /class M/
506
- out.should =~ /def alpha/
507
- out.should =~ /def beta/
508
- end
496
+ it 'should display method code (rather than class) if Pry started inside method binding' do
497
+ out = TestHost::D.invoked_in_method
498
+ out.should =~ /invoked_in_method/
499
+ out.should.not =~ /module D/
500
+ end
509
501
 
510
- it 'should allow options to be passed' do
511
- out = pry_eval(TestHost::M, 'show-source -b')
512
- out.should =~ /\d:\s*class M/
513
- out.should =~ /\d:\s*def alpha/
514
- out.should =~ /\d:\s*def beta/
515
- end
502
+ it 'should display class source when inside instance' do
503
+ out = pry_eval(TestHost::M.new, 'show-source')
504
+ out.should =~ /class M/
505
+ out.should =~ /def alpha/
506
+ out.should =~ /def beta/
507
+ end
516
508
 
517
- describe "should skip over broken modules" do
518
- before do
519
- module BabyDuck
509
+ it 'should allow options to be passed' do
510
+ out = pry_eval(TestHost::M, 'show-source -b')
511
+ out.should =~ /\d:\s*class M/
512
+ out.should =~ /\d:\s*def alpha/
513
+ out.should =~ /\d:\s*def beta/
514
+ end
520
515
 
521
- module Muesli
522
- binding.eval("def a; end", "dummy.rb", 1)
523
- binding.eval("def b; end", "dummy.rb", 2)
524
- binding.eval("def c; end", "dummy.rb", 3)
525
- end
516
+ describe "should skip over broken modules" do
517
+ before do
518
+ module BabyDuck
526
519
 
527
- module Muesli
528
- def d; end
529
- def e; end
520
+ module Muesli
521
+ binding.eval("def a; end", "dummy.rb", 1)
522
+ binding.eval("def b; end", "dummy.rb", 2)
523
+ binding.eval("def c; end", "dummy.rb", 3)
524
+ end
525
+
526
+ module Muesli
527
+ def d; end
528
+ def e; end
529
+ end
530
530
  end
531
531
  end
532
- end
533
532
 
534
- after do
535
- Object.remove_const(:BabyDuck)
536
- end
533
+ after do
534
+ Object.remove_const(:BabyDuck)
535
+ end
537
536
 
538
- it 'should return source for first valid module' do
539
- out = pry_eval('show-source BabyDuck::Muesli')
540
- out.should =~ /def d; end/
541
- out.should.not =~ /def a; end/
537
+ it 'should return source for first valid module' do
538
+ out = pry_eval('show-source BabyDuck::Muesli')
539
+ out.should =~ /def d; end/
540
+ out.should.not =~ /def a; end/
541
+ end
542
542
  end
543
543
  end
544
544
  end
545
545
  end
546
- end
547
546
 
548
- describe "on commands" do
549
- before do
550
- @oldset = Pry.config.commands
551
- @set = Pry.config.commands = Pry::CommandSet.new do
552
- import Pry::Commands
547
+ describe "on commands" do
548
+ before do
549
+ @oldset = Pry.config.commands
550
+ @set = Pry.config.commands = Pry::CommandSet.new do
551
+ import Pry::Commands
552
+ end
553
553
  end
554
- end
555
554
 
556
- after do
557
- Pry.config.commands = @oldset
558
- end
555
+ after do
556
+ Pry.config.commands = @oldset
557
+ end
559
558
 
560
- describe "block commands" do
561
- it 'should show source for an ordinary command' do
562
- @set.command "foo", :body_of_foo do; end
559
+ describe "block commands" do
560
+ it 'should show source for an ordinary command' do
561
+ @set.command "foo", :body_of_foo do; end
563
562
 
564
- pry_eval('show-source foo').should =~ /:body_of_foo/
565
- end
563
+ pry_eval('show-source foo').should =~ /:body_of_foo/
564
+ end
566
565
 
567
- it "should output source of commands using special characters" do
568
- @set.command "!%$", "I gots the yellow fever" do; end
566
+ it "should output source of commands using special characters" do
567
+ @set.command "!%$", "I gots the yellow fever" do; end
569
568
 
570
- pry_eval('show-source !%$').should =~ /yellow fever/
571
- end
569
+ pry_eval('show-source !%$').should =~ /yellow fever/
570
+ end
572
571
 
573
- it 'should show source for a command with spaces in its name' do
574
- @set.command "foo bar", :body_of_foo_bar do; end
572
+ it 'should show source for a command with spaces in its name' do
573
+ @set.command "foo bar", :body_of_foo_bar do; end
575
574
 
576
- pry_eval('show-source foo bar').should =~ /:body_of_foo_bar/
577
- end
575
+ pry_eval('show-source foo bar').should =~ /:body_of_foo_bar/
576
+ end
578
577
 
579
- it 'should show source for a command by listing name' do
580
- @set.command /foo(.*)/, :body_of_foo_bar_regex, :listing => "bar" do; end
578
+ it 'should show source for a command by listing name' do
579
+ @set.command /foo(.*)/, :body_of_foo_bar_regex, :listing => "bar" do; end
581
580
 
582
- pry_eval('show-source bar').should =~ /:body_of_foo_bar_regex/
581
+ pry_eval('show-source bar').should =~ /:body_of_foo_bar_regex/
582
+ end
583
583
  end
584
- end
585
584
 
586
- describe "create_command commands" do
587
- it 'should show source for a command' do
588
- @set.create_command "foo", "babble" do
589
- def process() :body_of_foo end
585
+ describe "create_command commands" do
586
+ it 'should show source for a command' do
587
+ @set.create_command "foo", "babble" do
588
+ def process() :body_of_foo end
589
+ end
590
+ pry_eval('show-source foo').should =~ /:body_of_foo/
590
591
  end
591
- pry_eval('show-source foo').should =~ /:body_of_foo/
592
- end
593
592
 
594
- it 'should show source for a command defined inside pry' do
595
- pry_eval %{
593
+ it 'should show source for a command defined inside pry' do
594
+ pry_eval %{
596
595
  _pry_.commands.create_command "foo", "babble" do
597
596
  def process() :body_of_foo end
598
597
  end
@@ -641,5 +640,119 @@ if !PryTestHelpers.mri18_and_no_real_source_location?
641
640
  t.pry.last_dir.should =~ /fixtures/
642
641
  end
643
642
  end
643
+
644
+ describe "can't find class/module code" do
645
+ describe "for classes" do
646
+ before do
647
+ module Jesus
648
+ module Pig
649
+ def lillybing; :lillybing; end
650
+ end
651
+
652
+ class Brian; end
653
+ class Jingle
654
+ def a; :doink; end
655
+ end
656
+
657
+ class Jangle < Jingle; include Pig; end
658
+ class Bangle < Jangle; end
659
+ end
660
+ end
661
+
662
+ after do
663
+ Object.remove_const(:Jesus)
664
+ end
665
+
666
+ it 'shows superclass code' do
667
+ t = pry_tester
668
+ t.process_command "show-source Jesus::Jangle"
669
+ t.last_output.should =~ /doink/
670
+ end
671
+
672
+ it 'ignores included modules' do
673
+ t = pry_tester
674
+ t.process_command "show-source Jesus::Jangle"
675
+ t.last_output.should.not =~ /lillybing/
676
+ end
677
+
678
+ it 'errors when class has no superclass to show' do
679
+ t = pry_tester
680
+ lambda { t.process_command "show-source Jesus::Brian" }.should.raise(Pry::CommandError).message.
681
+ should =~ /Couldn't locate/
682
+ end
683
+
684
+ it 'shows warning when reverting to superclass code' do
685
+ t = pry_tester
686
+ t.process_command "show-source Jesus::Jangle"
687
+ t.last_output.should =~ /Warning.*?Cannot find.*?Jesus::Jangle.*Showing.*Jesus::Jingle instead/
688
+ end
689
+
690
+ it 'shows nth level superclass code (when no intermediary superclasses have code either)' do
691
+ t = pry_tester
692
+ t.process_command "show-source Jesus::Bangle"
693
+ t.last_output.should =~ /doink/
694
+ end
695
+
696
+ it 'shows correct warning when reverting to nth level superclass' do
697
+ t = pry_tester
698
+ t.process_command "show-source Jesus::Bangle"
699
+ t.last_output.should =~ /Warning.*?Cannot find.*?Jesus::Bangle.*Showing.*Jesus::Jingle instead/
700
+ end
701
+ end
702
+
703
+ describe "for modules" do
704
+ before do
705
+ module Jesus
706
+ module Alpha
707
+ def alpha; :alpha; end
708
+ end
709
+
710
+ module Zeta; end
711
+
712
+ module Beta
713
+ include Alpha
714
+ end
715
+
716
+ module Gamma
717
+ include Beta
718
+ end
719
+ end
720
+ end
721
+
722
+ after do
723
+ Object.remove_const(:Jesus)
724
+ end
725
+
726
+ it 'shows included module code' do
727
+ t = pry_tester
728
+ t.process_command "show-source Jesus::Beta"
729
+ t.last_output.should =~ /alpha/
730
+ end
731
+
732
+ it 'shows warning when reverting to included module code' do
733
+ t = pry_tester
734
+ t.process_command "show-source Jesus::Beta"
735
+ t.last_output.should =~ /Warning.*?Cannot find.*?Jesus::Beta.*Showing.*Jesus::Alpha instead/
736
+ end
737
+
738
+ it 'errors when module has no included module to show' do
739
+ t = pry_tester
740
+ lambda { t.process_command "show-source Jesus::Zeta" }.should.raise(Pry::CommandError).message.
741
+ should =~ /Couldn't locate/
742
+ end
743
+
744
+ it 'shows nth level included module code (when no intermediary modules have code either)' do
745
+ t = pry_tester
746
+ t.process_command "show-source Jesus::Gamma"
747
+ t.last_output.should =~ /alpha/
748
+ end
749
+
750
+ it 'shows correct warning when reverting to nth level included module' do
751
+ t = pry_tester
752
+ t.process_command "show-source Jesus::Gamma"
753
+ t.last_output.should =~ /Warning.*?Cannot find.*?Jesus::Gamma.*Showing.*Jesus::Alpha instead/
754
+ end
755
+ end
756
+ end
644
757
  end
645
758
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.12pre1
4
+ version: 0.9.12pre2
5
5
  prerelease: 6
6
6
  platform: java
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-02-05 00:00:00.000000000 Z
14
+ date: 2013-02-07 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: coderay