pry 0.8.4pre1-i386-mswin32 → 0.9.0-i386-mswin32
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/.gitignore +1 -0
- data/CHANGELOG +25 -6
- data/README.markdown +11 -4
- data/Rakefile +15 -19
- data/TODO +28 -2
- data/bin/pry +28 -11
- data/examples/example_basic.rb +2 -4
- data/examples/example_command_override.rb +2 -5
- data/examples/example_commands.rb +1 -4
- data/examples/example_hooks.rb +2 -5
- data/examples/example_image_edit.rb +4 -8
- data/examples/example_input.rb +1 -4
- data/examples/example_input2.rb +1 -4
- data/examples/example_output.rb +1 -4
- data/examples/example_print.rb +2 -5
- data/examples/example_prompt.rb +2 -5
- data/examples/helper.rb +6 -0
- data/lib/pry.rb +59 -3
- data/lib/pry/command_context.rb +10 -9
- data/lib/pry/command_processor.rb +51 -73
- data/lib/pry/command_set.rb +79 -28
- data/lib/pry/commands.rb +9 -123
- data/lib/pry/completion.rb +30 -29
- data/lib/pry/config.rb +100 -0
- data/lib/pry/default_commands/basic.rb +37 -0
- data/lib/pry/default_commands/context.rb +16 -15
- data/lib/pry/default_commands/documentation.rb +73 -54
- data/lib/pry/default_commands/easter_eggs.rb +1 -20
- data/lib/pry/default_commands/gems.rb +31 -40
- data/lib/pry/default_commands/input.rb +223 -15
- data/lib/pry/default_commands/introspection.rb +108 -73
- data/lib/pry/default_commands/ls.rb +25 -11
- data/lib/pry/default_commands/shell.rb +29 -39
- data/lib/pry/extended_commands/experimental.rb +17 -0
- data/lib/pry/extended_commands/user_command_api.rb +22 -0
- data/lib/pry/helpers.rb +1 -0
- data/lib/pry/helpers/base_helpers.rb +15 -104
- data/lib/pry/helpers/command_helpers.rb +96 -59
- data/lib/pry/helpers/text.rb +83 -0
- data/lib/pry/history_array.rb +105 -0
- data/lib/pry/plugins.rb +79 -0
- data/lib/pry/pry_class.rb +102 -114
- data/lib/pry/pry_instance.rb +123 -55
- data/lib/pry/version.rb +1 -1
- data/pry.gemspec +45 -0
- data/test/helper.rb +57 -7
- data/test/test_command_processor.rb +205 -0
- data/test/{test_commandset.rb → test_command_set.rb} +18 -12
- data/test/test_default_commands.rb +59 -0
- data/test/test_default_commands/test_context.rb +64 -0
- data/test/test_default_commands/test_documentation.rb +31 -0
- data/test/test_default_commands/test_gems.rb +14 -0
- data/test/test_default_commands/test_input.rb +327 -0
- data/test/test_default_commands/test_introspection.rb +155 -0
- data/test/test_history_array.rb +65 -0
- data/test/test_pry.rb +548 -313
- metadata +48 -15
- data/lib/pry/hooks.rb +0 -17
- data/lib/pry/print.rb +0 -16
- data/lib/pry/prompts.rb +0 -31
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe "Pry::DefaultCommands::Gems" do
|
4
|
+
describe "gem-list" do
|
5
|
+
|
6
|
+
# fixing bug for 1.8 compat
|
7
|
+
it 'should not raise when invoked' do
|
8
|
+
str_output = StringIO.new
|
9
|
+
Pry.start self, :input => InputTester.new("gem-list", "exit-all"), :output => str_output
|
10
|
+
str_output.string.should.not =~ /NoMethodError/
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
@@ -0,0 +1,327 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe "Pry::DefaultCommands::Input" do
|
4
|
+
|
5
|
+
describe "amend-line-N" do
|
6
|
+
it 'should correctly amend the last line of input when no line number specified ' do
|
7
|
+
str_output = StringIO.new
|
8
|
+
redirect_pry_io(InputTester.new("def hello", "puts :bing", "amend-line puts :blah", "show-input", "exit-all"), str_output) do
|
9
|
+
pry
|
10
|
+
end
|
11
|
+
str_output.string.should =~ /\A\d+: def hello\n\d+: puts :blah/
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should correctly amend the specified line of input when line number given ' do
|
15
|
+
str_output = StringIO.new
|
16
|
+
redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "amend-line 1 def goodbye", "show-input", "exit-all"), str_output) do
|
17
|
+
pry
|
18
|
+
end
|
19
|
+
str_output.string.should =~ /\A\d+: def goodbye\n\d+: puts :bing\n\d+: puts :bang/
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should correctly amend the specified line of input when line number given, 0 should behave as 1 ' do
|
23
|
+
str_output = StringIO.new
|
24
|
+
redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "amend-line 0 def goodbye", "show-input", "exit-all"), str_output) do
|
25
|
+
pry
|
26
|
+
end
|
27
|
+
str_output.string.should =~ /\A\d+: def goodbye\n\d+: puts :bing\n\d+: puts :bang/
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should correctly amend the specified line of input when line number given (negative number)' do
|
31
|
+
str_output = StringIO.new
|
32
|
+
redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "amend-line -1 puts :bink", "show-input", "exit-all"), str_output) do
|
33
|
+
pry
|
34
|
+
end
|
35
|
+
str_output.string.should =~ /\A\d+: def hello\n\d+: puts :bing\n\d+: puts :bink/
|
36
|
+
|
37
|
+
str_output = StringIO.new
|
38
|
+
redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "amend-line -2 puts :bink", "show-input", "exit-all"), str_output) do
|
39
|
+
pry
|
40
|
+
end
|
41
|
+
str_output.string.should =~ /\A\d+: def hello\n\d+: puts :bink\n\d+: puts :bang/
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should correctly amend the specified range of lines of input when range of negative numbers given (negative number)' do
|
45
|
+
str_output = StringIO.new
|
46
|
+
redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "puts :boat", "amend-line -3..-2 puts :bink", "show-input", "exit-all"), str_output) do
|
47
|
+
pry
|
48
|
+
end
|
49
|
+
str_output.string.should =~ /\A\d+: def hello\n\d+: puts :bink\n\d+: puts :boat/
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should correctly amend the specified line with string interpolated text' do
|
53
|
+
str_output = StringIO.new
|
54
|
+
redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", 'amend-line puts "#{goodbye}"', "show-input", "exit-all"), str_output) do
|
55
|
+
pry
|
56
|
+
end
|
57
|
+
|
58
|
+
str_output.string.should =~ /\A\d+: def hello\n\d+: puts :bing\n\d+: puts \"\#{goodbye}\"/
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should display error if nothing to amend' do
|
62
|
+
str_output = StringIO.new
|
63
|
+
redirect_pry_io(InputTester.new("amend-line", "exit-all"), str_output) do
|
64
|
+
pry
|
65
|
+
end
|
66
|
+
str_output.string.should =~ /No input to amend/
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
it 'should correctly amend the specified range of lines' do
|
71
|
+
str_output = StringIO.new
|
72
|
+
redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "puts :heart", "amend-line 2..3 puts :bong", "show-input", "exit-all"), str_output) do
|
73
|
+
pry
|
74
|
+
end
|
75
|
+
str_output.string.should =~ /\A\d+: def hello\n\d+: puts :bong\n\d+: puts :heart/
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should correctly delete a specific line using the ! for content' do
|
79
|
+
str_output = StringIO.new
|
80
|
+
redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "puts :boast", "puts :heart", "amend-line 3 !", "show-input", "exit-all"), str_output) do
|
81
|
+
pry
|
82
|
+
end
|
83
|
+
|
84
|
+
str_output.string.should =~ /\d+: def hello\n\d+: puts :bing\n\d+: puts :boast\n\d+: puts :heart/
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should correctly delete a range of lines using the ! for content' do
|
88
|
+
str_output = StringIO.new
|
89
|
+
redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "puts :boast", "puts :heart", "amend-line 2..4 !", "show-input", "exit-all"), str_output) do
|
90
|
+
pry
|
91
|
+
end
|
92
|
+
|
93
|
+
str_output.string.should =~ /\d+: def hello\n\d+: puts :heart\n\Z/
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'should correctly delete the previous line using the ! for content' do
|
97
|
+
str_output = StringIO.new
|
98
|
+
redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "puts :boast", "puts :heart", "amend-line !", "show-input", "exit-all"), str_output) do
|
99
|
+
pry
|
100
|
+
end
|
101
|
+
|
102
|
+
str_output.string.should =~ /\d+: def hello\n\d+: puts :bing\n\d+: puts :bang\n\d+: puts :boast\n\Z/
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'should correctly amend the specified range of lines, using negative numbers in range' do
|
106
|
+
str_output = StringIO.new
|
107
|
+
redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "puts :boast", "puts :heart", "amend-line-2..-2 puts :bong", "show-input", "exit-all"), str_output) do
|
108
|
+
pry
|
109
|
+
end
|
110
|
+
str_output.string.should =~ /\d+: def hello\n\d+: puts :bong\n\d+: puts :heart/
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'should correctly insert a new line of input before a specified line using the > syntax' do
|
114
|
+
str_output = StringIO.new
|
115
|
+
redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "amend-line 2 >puts :inserted", "show-input", "exit-all"), str_output) do
|
116
|
+
pry
|
117
|
+
end
|
118
|
+
str_output.string.should =~ /\d+: def hello\n\d+: puts :inserted\n\d+: puts :bing\n\d+: puts :bang/
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'should correctly insert a new line of input before a specified line using the > syntax (should ignore second value of range)' do
|
122
|
+
str_output = StringIO.new
|
123
|
+
redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "amend-line 2..21 >puts :inserted", "show-input", "exit-all"), str_output) do
|
124
|
+
pry
|
125
|
+
end
|
126
|
+
str_output.string.should =~ /\d+: def hello\n\d+: puts :inserted\n\d+: puts :bing\n\d+: puts :bang/
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe "show-input" do
|
131
|
+
it 'should correctly show the current lines in the input buffer' do
|
132
|
+
str_output = StringIO.new
|
133
|
+
redirect_pry_io(InputTester.new("def hello", "puts :bing", "show-input", "exit-all"), str_output) do
|
134
|
+
pry
|
135
|
+
end
|
136
|
+
str_output.string.should =~ /\A\d+: def hello\n\d+: puts :bing/
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
describe "!" do
|
141
|
+
it 'should correctly clear the input buffer ' do
|
142
|
+
str_output = StringIO.new
|
143
|
+
redirect_pry_io(InputTester.new("def hello", "puts :bing", "!", "show-input", "exit-all"), str_output) do
|
144
|
+
pry
|
145
|
+
end
|
146
|
+
stripped_output = str_output.string.strip!
|
147
|
+
stripped_output.each_line.count.should == 1
|
148
|
+
stripped_output.should =~ /Input buffer cleared!/
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
describe "play" do
|
153
|
+
it 'should play a string of code (with no args)' do
|
154
|
+
redirect_pry_io(InputTester.new("play :test_string", "exit-all"), str_output = StringIO.new) do
|
155
|
+
pry
|
156
|
+
end
|
157
|
+
str_output.string.should =~ /:test_string/
|
158
|
+
end
|
159
|
+
|
160
|
+
it 'should play an interpolated string of code (with no args)' do
|
161
|
+
$obj = ":test_string_interpolated"
|
162
|
+
redirect_pry_io(InputTester.new('play #{$obj}', "exit-all"), str_output = StringIO.new) do
|
163
|
+
pry
|
164
|
+
end
|
165
|
+
str_output.string.should =~ /:test_string_interpolated/
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'should play a method with the -m switch (a single line)' do
|
169
|
+
$o = Object.new
|
170
|
+
def $o.test_method
|
171
|
+
:test_method_content
|
172
|
+
end
|
173
|
+
|
174
|
+
redirect_pry_io(InputTester.new('play -m $o.test_method --lines 2', "exit-all"), str_output = StringIO.new) do
|
175
|
+
pry
|
176
|
+
end
|
177
|
+
|
178
|
+
str_output.string.should =~ /:test_method_content/
|
179
|
+
$o = nil
|
180
|
+
end
|
181
|
+
|
182
|
+
it 'should play a method with the -m switch (multiple line)' do
|
183
|
+
$o = Object.new
|
184
|
+
def $o.test_method
|
185
|
+
1 + 102
|
186
|
+
5 * 6
|
187
|
+
end
|
188
|
+
|
189
|
+
redirect_pry_io(InputTester.new('play -m $o.test_method --lines 2..3', "exit-all"), str_output = StringIO.new) do
|
190
|
+
pry
|
191
|
+
end
|
192
|
+
|
193
|
+
str_output.string.should =~ /103\n.*30/
|
194
|
+
$o = nil
|
195
|
+
end
|
196
|
+
|
197
|
+
end
|
198
|
+
|
199
|
+
describe "hist" do
|
200
|
+
push_first_hist_line = lambda do |hist, line|
|
201
|
+
hist.push line
|
202
|
+
end
|
203
|
+
|
204
|
+
before do
|
205
|
+
Readline::HISTORY.shift until Readline::HISTORY.empty?
|
206
|
+
@hist = Readline::HISTORY
|
207
|
+
end
|
208
|
+
|
209
|
+
it 'should display the correct history' do
|
210
|
+
push_first_hist_line.call(@hist, "'bug in 1.8 means this line is ignored'")
|
211
|
+
@hist.push "hello"
|
212
|
+
@hist.push "world"
|
213
|
+
str_output = StringIO.new
|
214
|
+
redirect_pry_io(InputTester.new("hist", "exit-all"), str_output) do
|
215
|
+
pry
|
216
|
+
end
|
217
|
+
str_output.string.should =~ /hello\n.*world/
|
218
|
+
end
|
219
|
+
|
220
|
+
it 'should replay history correctly (single item)' do
|
221
|
+
push_first_hist_line.call(@hist, ":hello")
|
222
|
+
@hist.push ":blah"
|
223
|
+
@hist.push ":bucket"
|
224
|
+
@hist.push ":ostrich"
|
225
|
+
str_output = StringIO.new
|
226
|
+
redirect_pry_io(InputTester.new("hist --replay -1", "exit-all"), str_output) do
|
227
|
+
pry
|
228
|
+
end
|
229
|
+
str_output.string.should =~ /ostrich/
|
230
|
+
end
|
231
|
+
|
232
|
+
it 'should replay a range of history correctly (range of items)' do
|
233
|
+
push_first_hist_line.call(@hist, "'bug in 1.8 means this line is ignored'")
|
234
|
+
@hist.push ":hello"
|
235
|
+
@hist.push ":carl"
|
236
|
+
str_output = StringIO.new
|
237
|
+
redirect_pry_io(InputTester.new("hist --replay 0..2", "exit-all"), str_output) do
|
238
|
+
pry
|
239
|
+
end
|
240
|
+
str_output.string.should =~ /:hello\n.*:carl/
|
241
|
+
end
|
242
|
+
|
243
|
+
it 'should grep for correct lines in history' do
|
244
|
+
push_first_hist_line.call(@hist, "apple")
|
245
|
+
@hist.push "abby"
|
246
|
+
@hist.push "box"
|
247
|
+
@hist.push "button"
|
248
|
+
@hist.push "pepper"
|
249
|
+
@hist.push "orange"
|
250
|
+
@hist.push "grape"
|
251
|
+
@hist.push "def blah 1"
|
252
|
+
@hist.push "def boink 2"
|
253
|
+
@hist.push "place holder"
|
254
|
+
|
255
|
+
str_output = StringIO.new
|
256
|
+
redirect_pry_io(InputTester.new("hist --grep o", "exit-all"), str_output) do
|
257
|
+
pry
|
258
|
+
end
|
259
|
+
str_output.string.should =~ /\d:.*?box\n\d:.*?button\n\d:.*?orange/
|
260
|
+
|
261
|
+
# test more than one word in a regex match (def blah)
|
262
|
+
str_output = StringIO.new
|
263
|
+
redirect_pry_io(InputTester.new("hist --grep def blah", "exit-all"), str_output) do
|
264
|
+
pry
|
265
|
+
end
|
266
|
+
str_output.string.should =~ /def blah 1/
|
267
|
+
|
268
|
+
# test more than one word with leading white space in a regex match (def boink)
|
269
|
+
str_output = StringIO.new
|
270
|
+
redirect_pry_io(InputTester.new("hist --grep def boink", "exit-all"), str_output) do
|
271
|
+
pry
|
272
|
+
end
|
273
|
+
str_output.string.should =~ /def boink 2/
|
274
|
+
end
|
275
|
+
|
276
|
+
it 'should return last N lines in history with --tail switch' do
|
277
|
+
push_first_hist_line.call(@hist, "0")
|
278
|
+
("a".."z").each do |v|
|
279
|
+
@hist.push v
|
280
|
+
end
|
281
|
+
|
282
|
+
str_output = StringIO.new
|
283
|
+
redirect_pry_io(InputTester.new("hist --tail 3", "exit-all"), str_output) do
|
284
|
+
pry
|
285
|
+
end
|
286
|
+
|
287
|
+
str_output.string.each_line.count.should == 3
|
288
|
+
str_output.string.should =~ /x\n\d+:.*y\n\d+:.*z/
|
289
|
+
end
|
290
|
+
|
291
|
+
# strangeness in this test is due to bug in Readline::HISTORY not
|
292
|
+
# always registering first line of input
|
293
|
+
it 'should return first N lines in history with --head switch' do
|
294
|
+
push_first_hist_line.call(@hist, "0")
|
295
|
+
("a".."z").each do |v|
|
296
|
+
@hist.push v
|
297
|
+
end
|
298
|
+
|
299
|
+
str_output = StringIO.new
|
300
|
+
redirect_pry_io(InputTester.new("hist --head 4", "exit-all"), str_output) do
|
301
|
+
pry
|
302
|
+
end
|
303
|
+
|
304
|
+
str_output.string.each_line.count.should == 4
|
305
|
+
str_output.string.should =~ /a\n\d+:.*b\n\d+:.*c/
|
306
|
+
end
|
307
|
+
|
308
|
+
# strangeness in this test is due to bug in Readline::HISTORY not
|
309
|
+
# always registering first line of input
|
310
|
+
it 'should show lines between lines A and B with the --show switch' do
|
311
|
+
push_first_hist_line.call(@hist, "0")
|
312
|
+
("a".."z").each do |v|
|
313
|
+
@hist.push v
|
314
|
+
end
|
315
|
+
|
316
|
+
str_output = StringIO.new
|
317
|
+
redirect_pry_io(InputTester.new("hist --show 1..4", "exit-all"), str_output) do
|
318
|
+
pry
|
319
|
+
end
|
320
|
+
|
321
|
+
str_output.string.each_line.count.should == 4
|
322
|
+
str_output.string.should =~ /b\n\d+:.*c\n\d+:.*d/
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
326
|
+
|
327
|
+
end
|
@@ -0,0 +1,155 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe "Pry::DefaultCommands::Introspection" do
|
4
|
+
describe "show-method" do
|
5
|
+
it 'should output a method\'s source' do
|
6
|
+
str_output = StringIO.new
|
7
|
+
redirect_pry_io(InputTester.new("show-method sample_method", "exit-all"), str_output) do
|
8
|
+
pry
|
9
|
+
end
|
10
|
+
|
11
|
+
str_output.string.should =~ /def sample/
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should output a method\'s source with line numbers' do
|
15
|
+
str_output = StringIO.new
|
16
|
+
redirect_pry_io(InputTester.new("show-method -l sample_method", "exit-all"), str_output) do
|
17
|
+
pry
|
18
|
+
end
|
19
|
+
|
20
|
+
str_output.string.should =~ /\d+: def sample/
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should output a method\'s source with line numbers starting at 1' do
|
24
|
+
str_output = StringIO.new
|
25
|
+
redirect_pry_io(InputTester.new("show-method -b sample_method", "exit-all"), str_output) do
|
26
|
+
pry
|
27
|
+
end
|
28
|
+
|
29
|
+
str_output.string.should =~ /1: def sample/
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should output a method\'s source if inside method without needing to use method name' do
|
33
|
+
$str_output = StringIO.new
|
34
|
+
|
35
|
+
o = Object.new
|
36
|
+
def o.sample
|
37
|
+
redirect_pry_io(InputTester.new("show-method", "exit-all"), $str_output) do
|
38
|
+
binding.pry
|
39
|
+
end
|
40
|
+
end
|
41
|
+
o.sample
|
42
|
+
|
43
|
+
$str_output.string.should =~ /def o.sample/
|
44
|
+
$str_output = nil
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should output a method\'s source if inside method without needing to use method name, and using the -l switch' do
|
48
|
+
$str_output = StringIO.new
|
49
|
+
|
50
|
+
o = Object.new
|
51
|
+
def o.sample
|
52
|
+
redirect_pry_io(InputTester.new("show-method -l", "exit-all"), $str_output) do
|
53
|
+
binding.pry
|
54
|
+
end
|
55
|
+
end
|
56
|
+
o.sample
|
57
|
+
|
58
|
+
$str_output.string.should =~ /\d+: def o.sample/
|
59
|
+
$str_output = nil
|
60
|
+
end
|
61
|
+
|
62
|
+
# dynamically defined method source retrieval is only supported in
|
63
|
+
# 1.9 - where Method#source_location is native
|
64
|
+
if RUBY_VERSION =~ /1.9/
|
65
|
+
it 'should output a method\'s source for a method defined inside pry' do
|
66
|
+
str_output = StringIO.new
|
67
|
+
redirect_pry_io(InputTester.new("def dyna_method", ":testing", "end", "show-method dyna_method"), str_output) do
|
68
|
+
TOPLEVEL_BINDING.pry
|
69
|
+
end
|
70
|
+
|
71
|
+
str_output.string.should =~ /def dyna_method/
|
72
|
+
Object.remove_method :dyna_method
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'should output a method\'s source for a method defined inside pry, even if exceptions raised before hand' do
|
76
|
+
str_output = StringIO.new
|
77
|
+
redirect_pry_io(InputTester.new("bad code", "123", "bad code 2", "1 + 2", "def dyna_method", ":testing", "end", "show-method dyna_method"), str_output) do
|
78
|
+
TOPLEVEL_BINDING.pry
|
79
|
+
end
|
80
|
+
|
81
|
+
str_output.string.should =~ /def dyna_method/
|
82
|
+
Object.remove_method :dyna_method
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'should output an instance method\'s source for a method defined inside pry' do
|
86
|
+
str_output = StringIO.new
|
87
|
+
redirect_pry_io(InputTester.new("class A", "def yo", "end", "end", "show-method A#yo"), str_output) do
|
88
|
+
TOPLEVEL_BINDING.pry
|
89
|
+
end
|
90
|
+
|
91
|
+
str_output.string.should =~ /def yo/
|
92
|
+
Object.remove_const :A
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should output an instance method\'s source for a method defined inside pry using define_method' do
|
96
|
+
str_output = StringIO.new
|
97
|
+
redirect_pry_io(InputTester.new("class A", "define_method(:yup) {}", "end", "end", "show-method A#yup"), str_output) do
|
98
|
+
TOPLEVEL_BINDING.pry
|
99
|
+
end
|
100
|
+
|
101
|
+
str_output.string.should =~ /define_method\(:yup\)/
|
102
|
+
Object.remove_const :A
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
# show-command only works in implementations that support Proc#source_location
|
108
|
+
if Proc.method_defined?(:source_location)
|
109
|
+
describe "show-command" do
|
110
|
+
it 'should show source for an ordinary command' do
|
111
|
+
set = Pry::CommandSet.new do
|
112
|
+
import_from Pry::Commands, "show-command"
|
113
|
+
command "foo" do
|
114
|
+
:body_of_foo
|
115
|
+
end
|
116
|
+
end
|
117
|
+
str_output = StringIO.new
|
118
|
+
redirect_pry_io(InputTester.new("show-command foo"), str_output) do
|
119
|
+
Pry.new(:commands => set).rep
|
120
|
+
end
|
121
|
+
str_output.string.should =~ /:body_of_foo/
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'should show source for a command with spaces in its name' do
|
125
|
+
set = Pry::CommandSet.new do
|
126
|
+
import_from Pry::Commands, "show-command"
|
127
|
+
command "foo bar" do
|
128
|
+
:body_of_foo_bar
|
129
|
+
end
|
130
|
+
end
|
131
|
+
str_output = StringIO.new
|
132
|
+
redirect_pry_io(InputTester.new("show-command \"foo bar\""), str_output) do
|
133
|
+
Pry.new(:commands => set).rep
|
134
|
+
end
|
135
|
+
str_output.string.should =~ /:body_of_foo_bar/
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'should show source for a command by listing name' do
|
139
|
+
set = Pry::CommandSet.new do
|
140
|
+
import_from Pry::Commands, "show-command"
|
141
|
+
command /foo(.*)/, "", :listing => "bar" do
|
142
|
+
:body_of_foo_regex
|
143
|
+
end
|
144
|
+
end
|
145
|
+
str_output = StringIO.new
|
146
|
+
redirect_pry_io(InputTester.new("show-command bar"), str_output) do
|
147
|
+
Pry.new(:commands => set).rep
|
148
|
+
end
|
149
|
+
str_output.string.should =~ /:body_of_foo_regex/
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
|
155
|
+
end
|