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.
- data/lib/pry/commands/show_info.rb +39 -7
- data/lib/pry/module_candidate.rb +9 -5
- data/lib/pry/version.rb +1 -1
- data/lib/pry/wrapped_module.rb +12 -0
- data/spec/commands/show_doc_spec.rb +107 -0
- data/spec/commands/show_source_spec.rb +360 -247
- metadata +2 -2
@@ -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
|
-
|
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)
|
48
|
-
|
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
|
77
|
-
|
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 <<
|
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",
|
data/lib/pry/module_candidate.rb
CHANGED
@@ -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
|
24
|
-
|
25
|
-
|
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
|
-
|
28
|
-
|
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
|
data/lib/pry/version.rb
CHANGED
data/lib/pry/wrapped_module.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
223
|
-
|
222
|
+
EOS
|
223
|
+
end
|
224
224
|
|
225
|
-
|
226
|
-
|
227
|
-
|
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
|
-
|
235
|
+
it "source of method being shadowed should take precedence over variable
|
236
236
|
if given self.meth_name syntax" do
|
237
|
-
|
237
|
+
@t.eval('show-source self.hello').should =~ /def hello/
|
238
|
+
end
|
238
239
|
end
|
239
240
|
end
|
240
241
|
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
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
|
-
|
253
|
-
|
254
|
-
|
251
|
+
after do
|
252
|
+
Object.remove_const(:TestHost)
|
253
|
+
end
|
255
254
|
|
256
|
-
|
257
|
-
|
258
|
-
|
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
|
-
|
259
|
+
end
|
261
260
|
|
262
|
-
|
263
|
-
|
264
|
-
|
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
|
-
|
265
|
+
Object.remove_const(:TEST_HOST)
|
266
|
+
end
|
267
267
|
end
|
268
|
-
end
|
269
268
|
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
269
|
+
describe "on modules" do
|
270
|
+
before do
|
271
|
+
class ShowSourceTestSuperClass
|
272
|
+
def alpha
|
273
|
+
end
|
274
274
|
end
|
275
|
-
end
|
276
275
|
|
277
|
-
|
278
|
-
|
276
|
+
class ShowSourceTestClass<ShowSourceTestSuperClass
|
277
|
+
def alpha
|
278
|
+
end
|
279
279
|
end
|
280
|
-
end
|
281
280
|
|
282
|
-
|
283
|
-
|
281
|
+
module ShowSourceTestSuperModule
|
282
|
+
def alpha
|
283
|
+
end
|
284
284
|
end
|
285
|
-
end
|
286
285
|
|
287
|
-
|
288
|
-
|
289
|
-
|
286
|
+
module ShowSourceTestModule
|
287
|
+
include ShowSourceTestSuperModule
|
288
|
+
def alpha
|
289
|
+
end
|
290
290
|
end
|
291
|
-
end
|
292
291
|
|
293
|
-
|
294
|
-
|
292
|
+
ShowSourceTestClassWeirdSyntax = Class.new do
|
293
|
+
def beta
|
294
|
+
end
|
295
295
|
end
|
296
|
-
end
|
297
296
|
|
298
|
-
|
299
|
-
|
297
|
+
ShowSourceTestModuleWeirdSyntax = Module.new do
|
298
|
+
def beta
|
299
|
+
end
|
300
300
|
end
|
301
301
|
end
|
302
|
-
end
|
303
302
|
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
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
|
-
|
314
|
-
|
315
|
-
|
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
|
-
|
316
|
+
end
|
318
317
|
|
319
|
-
|
320
|
-
|
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
|
-
|
321
|
+
end
|
323
322
|
|
324
|
-
|
325
|
-
|
323
|
+
it 'should show source for a module' do
|
324
|
+
pry_eval('show-source ShowSourceTestModule').
|
326
325
|
should =~ /module ShowSourceTestModule/
|
327
|
-
|
326
|
+
end
|
328
327
|
|
329
|
-
|
330
|
-
|
328
|
+
it 'should show source for an ancestor module' do
|
329
|
+
pry_eval('show-source -s ShowSourceTestModule').
|
331
330
|
should =~ /module ShowSourceTestSuperModule/
|
332
|
-
|
331
|
+
end
|
333
332
|
|
334
|
-
|
335
|
-
|
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
|
-
|
336
|
+
end
|
338
337
|
|
339
|
-
|
340
|
-
|
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
|
-
|
341
|
+
end
|
343
342
|
|
344
|
-
|
345
|
-
|
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
|
-
|
351
|
-
|
352
|
-
|
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
|
-
|
363
|
-
|
364
|
-
|
365
|
-
after do
|
366
|
-
Object.remove_const :Dog
|
367
|
-
Object.remove_const :TobinaMyDog
|
368
|
-
end
|
361
|
+
EOS
|
362
|
+
end
|
369
363
|
|
370
|
-
|
371
|
-
|
372
|
-
|
364
|
+
after do
|
365
|
+
Object.remove_const :Dog
|
366
|
+
Object.remove_const :TobinaMyDog
|
373
367
|
end
|
374
|
-
|
375
|
-
|
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
|
-
|
383
|
-
|
384
|
-
|
381
|
+
constant_scope(:AlphaClass, :BetaClass) do
|
382
|
+
class BetaClass
|
383
|
+
def alpha
|
384
|
+
end
|
385
385
|
end
|
386
|
-
end
|
387
386
|
|
388
|
-
|
389
|
-
|
390
|
-
|
387
|
+
class AlphaClass
|
388
|
+
class BetaClass
|
389
|
+
def beta
|
390
|
+
end
|
391
391
|
end
|
392
392
|
end
|
393
|
-
end
|
394
393
|
|
395
|
-
|
394
|
+
pry_eval(AlphaClass, 'show-source BetaClass').should =~ /def beta/
|
395
|
+
end
|
396
396
|
end
|
397
|
-
end
|
398
397
|
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
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
|
-
|
407
|
+
pry_eval('show-source AlphaClass::BetaClass').should =~ /class Beta/
|
408
|
+
end
|
409
409
|
end
|
410
|
-
end
|
411
410
|
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
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
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
421
|
+
result = pry_eval('show-source TestClassForShowSource -a')
|
422
|
+
result.should =~ /def alpha/
|
423
|
+
result.should =~ /def beta/
|
424
|
+
end
|
426
425
|
|
427
|
-
|
428
|
-
|
429
|
-
|
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
|
-
|
434
|
-
|
435
|
-
|
432
|
+
result = pry_eval('show-source TestClassForShowSourceClassEval -a')
|
433
|
+
result.should =~ /def class_eval_method/
|
434
|
+
end
|
436
435
|
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
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
|
-
|
445
|
-
|
446
|
-
|
443
|
+
result = pry_eval('show-source TestClassForShowSourceClassEval#class_eval_method -a')
|
444
|
+
result.should =~ /bing/
|
445
|
+
end
|
447
446
|
|
448
|
-
|
449
|
-
|
450
|
-
|
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
|
-
|
455
|
-
|
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
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
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
|
-
|
468
|
-
|
466
|
+
module C
|
467
|
+
end
|
469
468
|
|
470
|
-
|
471
|
-
|
472
|
-
|
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
|
-
|
483
|
-
|
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
|
-
|
491
|
-
|
492
|
-
pry_eval(TestHost::
|
493
|
-
|
494
|
-
|
495
|
-
|
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
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
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
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
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
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
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
|
-
|
518
|
-
|
519
|
-
|
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
|
-
|
522
|
-
|
523
|
-
|
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
|
-
|
528
|
-
|
529
|
-
|
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
|
-
|
535
|
-
|
536
|
-
|
533
|
+
after do
|
534
|
+
Object.remove_const(:BabyDuck)
|
535
|
+
end
|
537
536
|
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
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
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
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
|
-
|
557
|
-
|
558
|
-
|
555
|
+
after do
|
556
|
+
Pry.config.commands = @oldset
|
557
|
+
end
|
559
558
|
|
560
|
-
|
561
|
-
|
562
|
-
|
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
|
-
|
565
|
-
|
563
|
+
pry_eval('show-source foo').should =~ /:body_of_foo/
|
564
|
+
end
|
566
565
|
|
567
|
-
|
568
|
-
|
566
|
+
it "should output source of commands using special characters" do
|
567
|
+
@set.command "!%$", "I gots the yellow fever" do; end
|
569
568
|
|
570
|
-
|
571
|
-
|
569
|
+
pry_eval('show-source !%$').should =~ /yellow fever/
|
570
|
+
end
|
572
571
|
|
573
|
-
|
574
|
-
|
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
|
-
|
577
|
-
|
575
|
+
pry_eval('show-source foo bar').should =~ /:body_of_foo_bar/
|
576
|
+
end
|
578
577
|
|
579
|
-
|
580
|
-
|
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
|
-
|
581
|
+
pry_eval('show-source bar').should =~ /:body_of_foo_bar_regex/
|
582
|
+
end
|
583
583
|
end
|
584
|
-
end
|
585
584
|
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
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
|
-
|
595
|
-
|
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.
|
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-
|
14
|
+
date: 2013-02-07 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: coderay
|