pry-stack_explorer 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +26 -40
- data/lib/pry-stack_explorer/version.rb +1 -1
- data/lib/pry-stack_explorer/when_started_hook.rb +2 -0
- metadata +8 -27
- data/.gemtest +0 -0
- data/.gitignore +0 -9
- data/.travis.yml +0 -26
- data/.yardopts +0 -1
- data/CHANGELOG +0 -9
- data/Gemfile +0 -2
- data/Rakefile +0 -112
- data/examples/example.rb +0 -45
- data/examples/example2.rb +0 -18
- data/examples/example3.rb +0 -46
- data/pry-stack_explorer.gemspec +0 -29
- data/test/helper.rb +0 -85
- data/test/test_commands.rb +0 -358
- data/test/test_frame_manager.rb +0 -65
- data/test/test_stack_explorer.rb +0 -393
- data/tester.rb +0 -27
data/pry-stack_explorer.gemspec
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
require File.expand_path('../lib/pry-stack_explorer/version', __FILE__)
|
2
|
-
|
3
|
-
Gem::Specification.new do |s|
|
4
|
-
s.name = "pry-stack_explorer"
|
5
|
-
s.version = PryStackExplorer::VERSION
|
6
|
-
|
7
|
-
s.required_ruby_version = ">= 2.6.0"
|
8
|
-
|
9
|
-
s.authors = ["John Mair (banisterfiend)"]
|
10
|
-
s.email = "jrmair@gmail.com"
|
11
|
-
|
12
|
-
s.license = "MIT"
|
13
|
-
|
14
|
-
s.summary = "Walk the stack in a Pry session"
|
15
|
-
|
16
|
-
s.files = [".gemtest", ".gitignore", ".travis.yml", ".yardopts", "CHANGELOG", "Gemfile", "LICENSE", "README.md", "Rakefile", "examples/example.rb", "examples/example2.rb", "examples/example3.rb", "lib/pry-stack_explorer.rb", "lib/pry-stack_explorer/commands.rb", "lib/pry-stack_explorer/frame_manager.rb", "lib/pry-stack_explorer/version.rb", "lib/pry-stack_explorer/when_started_hook.rb", "pry-stack_explorer.gemspec", "test/helper.rb", "test/test_commands.rb", "test/test_frame_manager.rb", "test/test_stack_explorer.rb", "tester.rb"]
|
17
|
-
s.require_paths = ["lib"]
|
18
|
-
s.test_files = ["test/helper.rb", "test/test_commands.rb", "test/test_frame_manager.rb", "test/test_stack_explorer.rb"]
|
19
|
-
|
20
|
-
s.homepage = "https://github.com/pry/pry-stack_explorer"
|
21
|
-
|
22
|
-
s.specification_version = 4
|
23
|
-
|
24
|
-
s.add_runtime_dependency 'binding_of_caller', '~> 0.7'
|
25
|
-
s.add_runtime_dependency 'pry', '~> 0.13'
|
26
|
-
|
27
|
-
s.add_development_dependency 'bacon', '~> 1.1.0'
|
28
|
-
s.add_development_dependency 'rake', '~> 0.9'
|
29
|
-
end
|
data/test/helper.rb
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'ostruct'
|
3
|
-
require 'pry'
|
4
|
-
|
5
|
-
unless Object.const_defined? 'PryStackExplorer'
|
6
|
-
$:.unshift File.expand_path '../../lib', __FILE__
|
7
|
-
require 'pry-stack_explorer'
|
8
|
-
end
|
9
|
-
|
10
|
-
require 'bacon'
|
11
|
-
|
12
|
-
puts "Testing pry-stack_explorer version #{PryStackExplorer::VERSION}..."
|
13
|
-
puts "Ruby version: #{RUBY_VERSION}"
|
14
|
-
|
15
|
-
PE = PryStackExplorer
|
16
|
-
|
17
|
-
class << Pry
|
18
|
-
alias_method :orig_reset_defaults, :reset_defaults
|
19
|
-
def reset_defaults
|
20
|
-
orig_reset_defaults
|
21
|
-
|
22
|
-
Pry.color = false
|
23
|
-
Pry.pager = false
|
24
|
-
Pry.config.should_load_rc = false
|
25
|
-
Pry.config.should_load_plugins = false
|
26
|
-
Pry.config.auto_indent = false
|
27
|
-
Pry.config.hooks = Pry::Hooks.new
|
28
|
-
Pry.config.collision_warning = false
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
AfterSessionHook = Pry.config.hooks.get_hook(:after_session, :delete_frame_manager)
|
33
|
-
WhenStartedHook = Pry.config.hooks.get_hook(:when_started, :save_caller_bindings)
|
34
|
-
|
35
|
-
Pry.reset_defaults
|
36
|
-
|
37
|
-
class InputTester
|
38
|
-
def initialize(*actions)
|
39
|
-
if actions.last.is_a?(Hash) && actions.last.keys == [:history]
|
40
|
-
@hist = actions.pop[:history]
|
41
|
-
end
|
42
|
-
@orig_actions = actions.dup
|
43
|
-
@actions = actions
|
44
|
-
end
|
45
|
-
|
46
|
-
def readline(*)
|
47
|
-
@actions.shift.tap{ |line| @hist << line if @hist }
|
48
|
-
end
|
49
|
-
|
50
|
-
def rewind
|
51
|
-
@actions = @orig_actions.dup
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
# Set I/O streams.
|
56
|
-
#
|
57
|
-
# Out defaults to an anonymous StringIO.
|
58
|
-
#
|
59
|
-
def redirect_pry_io(new_in, new_out = StringIO.new)
|
60
|
-
old_in = Pry.input
|
61
|
-
old_out = Pry.output
|
62
|
-
|
63
|
-
Pry.input = new_in
|
64
|
-
Pry.output = new_out
|
65
|
-
begin
|
66
|
-
yield
|
67
|
-
ensure
|
68
|
-
Pry.input = old_in
|
69
|
-
Pry.output = old_out
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def mock_pry(*args)
|
74
|
-
|
75
|
-
binding = args.first.is_a?(Binding) ? args.shift : binding()
|
76
|
-
|
77
|
-
input = InputTester.new(*args)
|
78
|
-
output = StringIO.new
|
79
|
-
|
80
|
-
redirect_pry_io(input, output) do
|
81
|
-
binding.pry
|
82
|
-
end
|
83
|
-
|
84
|
-
output.string
|
85
|
-
end
|
data/test/test_commands.rb
DELETED
@@ -1,358 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
|
4
|
-
class Top
|
5
|
-
attr_accessor :method_list, :middle
|
6
|
-
def initialize method_list
|
7
|
-
@method_list = method_list
|
8
|
-
end
|
9
|
-
def bing
|
10
|
-
@middle = Middle.new method_list
|
11
|
-
@middle.bong
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
class Middle
|
16
|
-
attr_accessor :method_list, :bottom
|
17
|
-
def initialize method_list
|
18
|
-
@method_list = method_list
|
19
|
-
end
|
20
|
-
def bong
|
21
|
-
@bottom = Bottom.new method_list
|
22
|
-
@bottom.bang
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
class Bottom
|
27
|
-
attr_accessor :method_list
|
28
|
-
def initialize method_list
|
29
|
-
@method_list = method_list
|
30
|
-
end
|
31
|
-
def bang
|
32
|
-
Pry.start(binding)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
|
37
|
-
describe PryStackExplorer::Commands do
|
38
|
-
|
39
|
-
before do
|
40
|
-
Pry.config.hooks.add_hook(:when_started, :save_caller_bindings, WhenStartedHook)
|
41
|
-
Pry.config.hooks.add_hook(:after_session, :delete_frame_manager, AfterSessionHook)
|
42
|
-
|
43
|
-
@o = Object.new
|
44
|
-
class << @o; attr_accessor :first_method, :second_method, :third_method; end
|
45
|
-
def @o.bing() bong end
|
46
|
-
def @o.bong() bang end
|
47
|
-
def @o.bang() Pry.start(binding) end
|
48
|
-
|
49
|
-
method_list = []
|
50
|
-
@top = Top.new method_list
|
51
|
-
end
|
52
|
-
|
53
|
-
after do
|
54
|
-
Pry.config.hooks.delete_hook(:when_started, :save_caller_bindings)
|
55
|
-
Pry.config.hooks.delete_hook(:after_session, :delete_frame_manager)
|
56
|
-
end
|
57
|
-
|
58
|
-
describe "up" do
|
59
|
-
it 'should move up the call stack one frame at a time' do
|
60
|
-
redirect_pry_io(InputTester.new("@first_method = __method__",
|
61
|
-
"up",
|
62
|
-
"@second_method = __method__",
|
63
|
-
"up",
|
64
|
-
"@third_method = __method__",
|
65
|
-
"exit-all"), out=StringIO.new) do
|
66
|
-
@o.bing
|
67
|
-
end
|
68
|
-
|
69
|
-
@o.first_method.should == :bang
|
70
|
-
@o.second_method.should == :bong
|
71
|
-
@o.third_method.should == :bing
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'should move up the call stack two frames at a time' do
|
75
|
-
redirect_pry_io(InputTester.new("@first_method = __method__",
|
76
|
-
"up 2",
|
77
|
-
"@second_method = __method__",
|
78
|
-
"exit-all"), out=StringIO.new) do
|
79
|
-
@o.bing
|
80
|
-
end
|
81
|
-
|
82
|
-
@o.first_method.should == :bang
|
83
|
-
@o.second_method.should == :bing
|
84
|
-
end
|
85
|
-
|
86
|
-
describe "by method name regex" do
|
87
|
-
it 'should move to the method name that matches the regex' do
|
88
|
-
redirect_pry_io(InputTester.new("@first_method = __method__",
|
89
|
-
"up bi",
|
90
|
-
"@second_method = __method__",
|
91
|
-
"exit-all"), out=StringIO.new) do
|
92
|
-
@o.bing
|
93
|
-
end
|
94
|
-
|
95
|
-
@o.first_method.should == :bang
|
96
|
-
@o.second_method.should == :bing
|
97
|
-
end
|
98
|
-
|
99
|
-
it 'should move through all methods that match regex in order' do
|
100
|
-
redirect_pry_io(InputTester.new("@first_method = __method__",
|
101
|
-
"up b",
|
102
|
-
"@second_method = __method__",
|
103
|
-
"up b",
|
104
|
-
"@third_method = __method__",
|
105
|
-
"exit-all"), out=StringIO.new) do
|
106
|
-
@o.bing
|
107
|
-
end
|
108
|
-
|
109
|
-
@o.first_method.should == :bang
|
110
|
-
@o.second_method.should == :bong
|
111
|
-
@o.third_method.should == :bing
|
112
|
-
end
|
113
|
-
|
114
|
-
it 'should error if it cant find frame to match regex' do
|
115
|
-
redirect_pry_io(InputTester.new("up conrad_irwin",
|
116
|
-
"exit-all"), out=StringIO.new) do
|
117
|
-
@o.bing
|
118
|
-
end
|
119
|
-
|
120
|
-
out.string.should =~ /Error: No frame that matches/
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
|
125
|
-
describe 'by Class#method name regex' do
|
126
|
-
it 'should move to the method and class that matches the regex' do
|
127
|
-
redirect_pry_io(InputTester.new("@method_list << self.class.to_s + '#' + __method__.to_s",
|
128
|
-
'up Middle#bong',
|
129
|
-
"@method_list << self.class.to_s + '#' + __method__.to_s",
|
130
|
-
"exit-all"), out=StringIO.new) do
|
131
|
-
@top.bing
|
132
|
-
end
|
133
|
-
|
134
|
-
@top.method_list.should == ['Bottom#bang', 'Middle#bong']
|
135
|
-
end
|
136
|
-
|
137
|
-
### ????? ###
|
138
|
-
# it 'should be case sensitive' do
|
139
|
-
# end
|
140
|
-
### ????? ###
|
141
|
-
|
142
|
-
it 'should allow partial class names' do
|
143
|
-
redirect_pry_io(InputTester.new("@method_list << self.class.to_s + '#' + __method__.to_s",
|
144
|
-
'up Mid#bong',
|
145
|
-
"@method_list << self.class.to_s + '#' + __method__.to_s",
|
146
|
-
"exit-all"), out=StringIO.new) do
|
147
|
-
@top.bing
|
148
|
-
end
|
149
|
-
|
150
|
-
@top.method_list.should == ['Bottom#bang', 'Middle#bong']
|
151
|
-
|
152
|
-
end
|
153
|
-
|
154
|
-
it 'should allow partial method names' do
|
155
|
-
redirect_pry_io(InputTester.new("@method_list << self.class.to_s + '#' + __method__.to_s",
|
156
|
-
'up Middle#bo',
|
157
|
-
"@method_list << self.class.to_s + '#' + __method__.to_s",
|
158
|
-
"exit-all"), out=StringIO.new) do
|
159
|
-
@top.bing
|
160
|
-
end
|
161
|
-
|
162
|
-
@top.method_list.should == ['Bottom#bang', 'Middle#bong']
|
163
|
-
|
164
|
-
end
|
165
|
-
|
166
|
-
it 'should error if it cant find frame to match regex' do
|
167
|
-
redirect_pry_io(InputTester.new('up Conrad#irwin',
|
168
|
-
"exit-all"), out=StringIO.new) do
|
169
|
-
@top.bing
|
170
|
-
end
|
171
|
-
|
172
|
-
out.string.should =~ /Error: No frame that matches/
|
173
|
-
end
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
describe "down" do
|
178
|
-
it 'should move down the call stack one frame at a time' do
|
179
|
-
def @o.bang() Pry.start(binding, :initial_frame => 1) end
|
180
|
-
|
181
|
-
redirect_pry_io(InputTester.new("@first_method = __method__",
|
182
|
-
"down",
|
183
|
-
"@second_method = __method__",
|
184
|
-
"exit-all"), out=StringIO.new) do
|
185
|
-
@o.bing
|
186
|
-
end
|
187
|
-
|
188
|
-
@o.first_method.should == :bong
|
189
|
-
@o.second_method.should == :bang
|
190
|
-
end
|
191
|
-
|
192
|
-
it 'should move down the call stack two frames at a time' do
|
193
|
-
def @o.bang() Pry.start(binding, :initial_frame => 2) end
|
194
|
-
|
195
|
-
redirect_pry_io(InputTester.new("@first_method = __method__",
|
196
|
-
"down 2",
|
197
|
-
"@second_method = __method__",
|
198
|
-
"exit-all"), out=StringIO.new) do
|
199
|
-
@o.bing
|
200
|
-
end
|
201
|
-
|
202
|
-
@o.first_method.should == :bing
|
203
|
-
@o.second_method.should == :bang
|
204
|
-
end
|
205
|
-
|
206
|
-
describe "by method name regex" do
|
207
|
-
it 'should move to the method name that matches the regex' do
|
208
|
-
redirect_pry_io(InputTester.new("frame -1",
|
209
|
-
"down bo",
|
210
|
-
"@first_method = __method__",
|
211
|
-
"exit-all"), out=StringIO.new) do
|
212
|
-
@o.bing
|
213
|
-
end
|
214
|
-
|
215
|
-
@o.first_method.should == :bong
|
216
|
-
end
|
217
|
-
|
218
|
-
it 'should move through all methods that match regex in order' do
|
219
|
-
redirect_pry_io(InputTester.new("frame bing",
|
220
|
-
"@first_method = __method__",
|
221
|
-
"down b",
|
222
|
-
"@second_method = __method__",
|
223
|
-
"down b",
|
224
|
-
"@third_method = __method__",
|
225
|
-
"exit-all"), out=StringIO.new) do
|
226
|
-
@o.bing
|
227
|
-
end
|
228
|
-
|
229
|
-
@o.first_method.should == :bing
|
230
|
-
@o.second_method.should == :bong
|
231
|
-
@o.third_method.should == :bang
|
232
|
-
end
|
233
|
-
|
234
|
-
it 'should error if it cant find frame to match regex' do
|
235
|
-
redirect_pry_io(InputTester.new("frame -1",
|
236
|
-
"down conrad_irwin",
|
237
|
-
"exit-all"), out=StringIO.new) do
|
238
|
-
@o.bing
|
239
|
-
end
|
240
|
-
|
241
|
-
out.string.should =~ /Error: No frame that matches/
|
242
|
-
end
|
243
|
-
end
|
244
|
-
|
245
|
-
describe 'by Class#method name regex' do
|
246
|
-
it 'should move to the method and class that matches the regex' do
|
247
|
-
redirect_pry_io(InputTester.new('frame Top#bing',
|
248
|
-
"@method_list << self.class.to_s + '#' + __method__.to_s",
|
249
|
-
'down Middle#bong',
|
250
|
-
"@method_list << self.class.to_s + '#' + __method__.to_s",
|
251
|
-
"exit-all"), out=StringIO.new) do
|
252
|
-
@top.bing
|
253
|
-
end
|
254
|
-
|
255
|
-
@top.method_list.should == ['Top#bing', 'Middle#bong']
|
256
|
-
end
|
257
|
-
|
258
|
-
### ????? ###
|
259
|
-
# it 'should be case sensitive' do
|
260
|
-
# end
|
261
|
-
### ????? ###
|
262
|
-
|
263
|
-
it 'should error if it cant find frame to match regex' do
|
264
|
-
redirect_pry_io(InputTester.new('down Conrad#irwin',
|
265
|
-
"exit-all"), out=StringIO.new) do
|
266
|
-
@top.bing
|
267
|
-
end
|
268
|
-
|
269
|
-
out.string.should =~ /Error: No frame that matches/
|
270
|
-
end
|
271
|
-
end
|
272
|
-
|
273
|
-
end
|
274
|
-
|
275
|
-
describe "frame" do
|
276
|
-
describe "by method name regex" do
|
277
|
-
it 'should jump to correct stack frame when given method name' do
|
278
|
-
redirect_pry_io(InputTester.new("frame bi",
|
279
|
-
"@first_method = __method__",
|
280
|
-
"exit-all"), out=StringIO.new) do
|
281
|
-
@o.bing
|
282
|
-
end
|
283
|
-
|
284
|
-
@o.first_method.should == :bing
|
285
|
-
end
|
286
|
-
|
287
|
-
it 'should NOT jump to frames lower down stack when given method name' do
|
288
|
-
redirect_pry_io(InputTester.new("frame -1",
|
289
|
-
"frame bang",
|
290
|
-
"exit-all"), out=StringIO.new) do
|
291
|
-
@o.bing
|
292
|
-
end
|
293
|
-
|
294
|
-
out.string.should =~ /Error: No frame that matches/
|
295
|
-
end
|
296
|
-
|
297
|
-
end
|
298
|
-
|
299
|
-
it 'should move to the given frame in the call stack' do
|
300
|
-
redirect_pry_io(InputTester.new("frame 2",
|
301
|
-
"@first_method = __method__",
|
302
|
-
"exit-all"), out=StringIO.new) do
|
303
|
-
@o.bing
|
304
|
-
end
|
305
|
-
|
306
|
-
@o.first_method.should == :bing
|
307
|
-
end
|
308
|
-
|
309
|
-
it 'should return info on current frame when given no parameters' do
|
310
|
-
redirect_pry_io(InputTester.new("frame",
|
311
|
-
"exit-all"), out=StringIO.new) do
|
312
|
-
@o.bing
|
313
|
-
end
|
314
|
-
|
315
|
-
out.string.should =~ /\#0.*?bang/
|
316
|
-
out.string.should.not =~ /\#1/
|
317
|
-
end
|
318
|
-
|
319
|
-
describe "negative indices" do
|
320
|
-
it 'should work with negative frame numbers' do
|
321
|
-
o = Object.new
|
322
|
-
class << o; attr_accessor :frame; end
|
323
|
-
def o.alpha() binding end
|
324
|
-
def o.beta() binding end
|
325
|
-
def o.gamma() binding end
|
326
|
-
|
327
|
-
call_stack = [o.alpha, o.beta, o.gamma]
|
328
|
-
method_names = call_stack.map { |v| v.eval('__method__') }.reverse
|
329
|
-
(1..3).each_with_index do |v, idx|
|
330
|
-
redirect_pry_io(InputTester.new("frame -#{v}",
|
331
|
-
"@frame = __method__",
|
332
|
-
"exit-all"), out=StringIO.new) do
|
333
|
-
Pry.start(o, :call_stack => call_stack)
|
334
|
-
end
|
335
|
-
o.frame.should == method_names[idx]
|
336
|
-
end
|
337
|
-
end
|
338
|
-
|
339
|
-
it 'should convert negative indices to their positive counterparts' do
|
340
|
-
o = Object.new
|
341
|
-
class << o; attr_accessor :frame_number; end
|
342
|
-
def o.alpha() binding end
|
343
|
-
def o.beta() binding end
|
344
|
-
def o.gamma() binding end
|
345
|
-
|
346
|
-
call_stack = [o.alpha, o.beta, o.gamma]
|
347
|
-
(1..3).each_with_index do |v, idx|
|
348
|
-
redirect_pry_io(InputTester.new("frame -#{v}",
|
349
|
-
"@frame_number = PryStackExplorer.frame_manager(_pry_).binding_index",
|
350
|
-
"exit-all"), out=StringIO.new) do
|
351
|
-
Pry.start(o, :call_stack => call_stack)
|
352
|
-
end
|
353
|
-
o.frame_number.should == call_stack.size - v
|
354
|
-
end
|
355
|
-
end
|
356
|
-
end
|
357
|
-
end
|
358
|
-
end
|