pry 0.9.12.6 → 0.10.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +702 -0
  3. data/LICENSE +2 -2
  4. data/{README.markdown → README.md} +37 -31
  5. data/lib/pry.rb +38 -151
  6. data/lib/pry/cli.rb +35 -17
  7. data/lib/pry/code.rb +24 -63
  8. data/lib/pry/code/code_file.rb +103 -0
  9. data/lib/pry/code/code_range.rb +2 -1
  10. data/lib/pry/code/loc.rb +2 -2
  11. data/lib/pry/code_object.rb +40 -21
  12. data/lib/pry/color_printer.rb +55 -0
  13. data/lib/pry/command.rb +12 -9
  14. data/lib/pry/command_set.rb +81 -38
  15. data/lib/pry/commands.rb +1 -1
  16. data/lib/pry/commands/amend_line.rb +2 -2
  17. data/lib/pry/commands/bang.rb +1 -1
  18. data/lib/pry/commands/cat.rb +11 -2
  19. data/lib/pry/commands/cat/exception_formatter.rb +5 -6
  20. data/lib/pry/commands/cat/file_formatter.rb +15 -32
  21. data/lib/pry/commands/cd.rb +14 -3
  22. data/lib/pry/commands/change_inspector.rb +27 -0
  23. data/lib/pry/commands/change_prompt.rb +26 -0
  24. data/lib/pry/commands/code_collector.rb +4 -4
  25. data/lib/pry/commands/easter_eggs.rb +3 -3
  26. data/lib/pry/commands/edit.rb +10 -22
  27. data/lib/pry/commands/edit/exception_patcher.rb +2 -2
  28. data/lib/pry/commands/edit/file_and_line_locator.rb +0 -2
  29. data/lib/pry/commands/exit_program.rb +0 -1
  30. data/lib/pry/commands/find_method.rb +16 -22
  31. data/lib/pry/commands/gem_install.rb +5 -2
  32. data/lib/pry/commands/gem_open.rb +1 -1
  33. data/lib/pry/commands/gist.rb +10 -11
  34. data/lib/pry/commands/help.rb +14 -14
  35. data/lib/pry/commands/hist.rb +27 -8
  36. data/lib/pry/commands/install_command.rb +14 -12
  37. data/lib/pry/commands/list_inspectors.rb +35 -0
  38. data/lib/pry/commands/list_prompts.rb +35 -0
  39. data/lib/pry/commands/ls.rb +72 -296
  40. data/lib/pry/commands/ls/constants.rb +47 -0
  41. data/lib/pry/commands/ls/formatter.rb +49 -0
  42. data/lib/pry/commands/ls/globals.rb +48 -0
  43. data/lib/pry/commands/ls/grep.rb +21 -0
  44. data/lib/pry/commands/ls/instance_vars.rb +39 -0
  45. data/lib/pry/commands/ls/interrogatable.rb +18 -0
  46. data/lib/pry/commands/ls/jruby_hacks.rb +49 -0
  47. data/lib/pry/commands/ls/local_names.rb +35 -0
  48. data/lib/pry/commands/ls/local_vars.rb +39 -0
  49. data/lib/pry/commands/ls/ls_entity.rb +70 -0
  50. data/lib/pry/commands/ls/methods.rb +57 -0
  51. data/lib/pry/commands/ls/methods_helper.rb +46 -0
  52. data/lib/pry/commands/ls/self_methods.rb +32 -0
  53. data/lib/pry/commands/play.rb +44 -10
  54. data/lib/pry/commands/pry_backtrace.rb +1 -2
  55. data/lib/pry/commands/raise_up.rb +2 -2
  56. data/lib/pry/commands/reload_code.rb +16 -19
  57. data/lib/pry/commands/ri.rb +7 -3
  58. data/lib/pry/commands/shell_command.rb +18 -13
  59. data/lib/pry/commands/shell_mode.rb +2 -4
  60. data/lib/pry/commands/show_doc.rb +5 -0
  61. data/lib/pry/commands/show_info.rb +8 -13
  62. data/lib/pry/commands/show_source.rb +15 -3
  63. data/lib/pry/commands/simple_prompt.rb +1 -1
  64. data/lib/pry/commands/toggle_color.rb +8 -4
  65. data/lib/pry/commands/watch_expression.rb +105 -0
  66. data/lib/pry/commands/watch_expression/expression.rb +38 -0
  67. data/lib/pry/commands/whereami.rb +18 -10
  68. data/lib/pry/commands/wtf.rb +3 -3
  69. data/lib/pry/config.rb +20 -254
  70. data/lib/pry/config/behavior.rb +139 -0
  71. data/lib/pry/config/convenience.rb +26 -0
  72. data/lib/pry/config/default.rb +165 -0
  73. data/lib/pry/core_extensions.rb +31 -21
  74. data/lib/pry/editor.rb +107 -103
  75. data/lib/pry/exceptions.rb +77 -0
  76. data/lib/pry/helpers/base_helpers.rb +22 -109
  77. data/lib/pry/helpers/command_helpers.rb +10 -8
  78. data/lib/pry/helpers/documentation_helpers.rb +1 -2
  79. data/lib/pry/helpers/text.rb +4 -5
  80. data/lib/pry/history.rb +46 -45
  81. data/lib/pry/history_array.rb +6 -1
  82. data/lib/pry/hooks.rb +9 -29
  83. data/lib/pry/indent.rb +6 -6
  84. data/lib/pry/input_completer.rb +242 -0
  85. data/lib/pry/input_lock.rb +132 -0
  86. data/lib/pry/inspector.rb +27 -0
  87. data/lib/pry/last_exception.rb +61 -0
  88. data/lib/pry/method.rb +82 -87
  89. data/lib/pry/{commands/edit/method_patcher.rb → method/patcher.rb} +41 -38
  90. data/lib/pry/module_candidate.rb +4 -14
  91. data/lib/pry/object_path.rb +82 -0
  92. data/lib/pry/output.rb +50 -0
  93. data/lib/pry/pager.rb +191 -47
  94. data/lib/pry/plugins.rb +1 -1
  95. data/lib/pry/prompt.rb +26 -0
  96. data/lib/pry/pry_class.rb +149 -230
  97. data/lib/pry/pry_instance.rb +302 -413
  98. data/lib/pry/rbx_path.rb +1 -1
  99. data/lib/pry/repl.rb +202 -0
  100. data/lib/pry/repl_file_loader.rb +20 -26
  101. data/lib/pry/rubygem.rb +13 -5
  102. data/lib/pry/terminal.rb +2 -1
  103. data/lib/pry/test/helper.rb +26 -41
  104. data/lib/pry/version.rb +1 -1
  105. data/lib/pry/wrapped_module.rb +45 -59
  106. metadata +61 -224
  107. data/.document +0 -2
  108. data/.gitignore +0 -16
  109. data/.travis.yml +0 -25
  110. data/.yardopts +0 -1
  111. data/CHANGELOG +0 -534
  112. data/CONTRIBUTORS +0 -55
  113. data/Gemfile +0 -12
  114. data/Rakefile +0 -140
  115. data/TODO +0 -117
  116. data/lib/pry/completion.rb +0 -321
  117. data/lib/pry/custom_completions.rb +0 -6
  118. data/lib/pry/rbx_method.rb +0 -13
  119. data/man/pry.1 +0 -195
  120. data/man/pry.1.html +0 -204
  121. data/man/pry.1.ronn +0 -141
  122. data/pry.gemspec +0 -29
  123. data/spec/Procfile +0 -3
  124. data/spec/cli_spec.rb +0 -78
  125. data/spec/code_object_spec.rb +0 -277
  126. data/spec/code_spec.rb +0 -219
  127. data/spec/command_helpers_spec.rb +0 -29
  128. data/spec/command_integration_spec.rb +0 -644
  129. data/spec/command_set_spec.rb +0 -627
  130. data/spec/command_spec.rb +0 -821
  131. data/spec/commands/amend_line_spec.rb +0 -247
  132. data/spec/commands/bang_spec.rb +0 -19
  133. data/spec/commands/cat_spec.rb +0 -164
  134. data/spec/commands/cd_spec.rb +0 -250
  135. data/spec/commands/disable_pry_spec.rb +0 -25
  136. data/spec/commands/edit_spec.rb +0 -727
  137. data/spec/commands/exit_all_spec.rb +0 -34
  138. data/spec/commands/exit_program_spec.rb +0 -19
  139. data/spec/commands/exit_spec.rb +0 -34
  140. data/spec/commands/find_method_spec.rb +0 -70
  141. data/spec/commands/gem_list_spec.rb +0 -26
  142. data/spec/commands/gist_spec.rb +0 -79
  143. data/spec/commands/help_spec.rb +0 -56
  144. data/spec/commands/hist_spec.rb +0 -181
  145. data/spec/commands/jump_to_spec.rb +0 -15
  146. data/spec/commands/ls_spec.rb +0 -181
  147. data/spec/commands/play_spec.rb +0 -140
  148. data/spec/commands/raise_up_spec.rb +0 -56
  149. data/spec/commands/save_file_spec.rb +0 -177
  150. data/spec/commands/show_doc_spec.rb +0 -510
  151. data/spec/commands/show_input_spec.rb +0 -17
  152. data/spec/commands/show_source_spec.rb +0 -782
  153. data/spec/commands/whereami_spec.rb +0 -203
  154. data/spec/completion_spec.rb +0 -241
  155. data/spec/control_d_handler_spec.rb +0 -58
  156. data/spec/documentation_helper_spec.rb +0 -73
  157. data/spec/editor_spec.rb +0 -79
  158. data/spec/exception_whitelist_spec.rb +0 -21
  159. data/spec/fixtures/candidate_helper1.rb +0 -11
  160. data/spec/fixtures/candidate_helper2.rb +0 -8
  161. data/spec/fixtures/example.erb +0 -5
  162. data/spec/fixtures/example_nesting.rb +0 -33
  163. data/spec/fixtures/show_source_doc_examples.rb +0 -15
  164. data/spec/fixtures/testrc +0 -2
  165. data/spec/fixtures/testrcbad +0 -2
  166. data/spec/fixtures/whereami_helper.rb +0 -6
  167. data/spec/helper.rb +0 -34
  168. data/spec/helpers/bacon.rb +0 -86
  169. data/spec/helpers/mock_pry.rb +0 -43
  170. data/spec/helpers/table_spec.rb +0 -105
  171. data/spec/history_array_spec.rb +0 -67
  172. data/spec/hooks_spec.rb +0 -522
  173. data/spec/indent_spec.rb +0 -301
  174. data/spec/input_stack_spec.rb +0 -90
  175. data/spec/method_spec.rb +0 -482
  176. data/spec/prompt_spec.rb +0 -60
  177. data/spec/pry_defaults_spec.rb +0 -419
  178. data/spec/pry_history_spec.rb +0 -99
  179. data/spec/pry_output_spec.rb +0 -95
  180. data/spec/pry_spec.rb +0 -515
  181. data/spec/run_command_spec.rb +0 -25
  182. data/spec/sticky_locals_spec.rb +0 -157
  183. data/spec/syntax_checking_spec.rb +0 -81
  184. data/spec/wrapped_module_spec.rb +0 -261
  185. data/wiki/Customizing-pry.md +0 -397
  186. data/wiki/Home.md +0 -4
@@ -1,627 +0,0 @@
1
- require 'helper'
2
-
3
- describe Pry::CommandSet do
4
- before do
5
- @set = Pry::CommandSet.new do
6
- import Pry::Commands
7
- end
8
-
9
- @ctx = {
10
- :target => binding,
11
- :command_set => @set
12
- }
13
- end
14
-
15
- it 'should call the block used for the command when it is called' do
16
- run = false
17
- @set.command 'foo' do
18
- run = true
19
- end
20
-
21
- @set.run_command @ctx, 'foo'
22
- run.should == true
23
- end
24
-
25
- it 'should pass arguments of the command to the block' do
26
- @set.command 'foo' do |*args|
27
- args.should == [1, 2, 3]
28
- end
29
-
30
- @set.run_command @ctx, 'foo', 1, 2, 3
31
- end
32
-
33
- it 'should use the first argument as context' do
34
- ctx = @ctx
35
-
36
- @set.command 'foo' do
37
- self.context.should == ctx
38
- end
39
-
40
- @set.run_command @ctx, 'foo'
41
- end
42
-
43
- it 'should raise an error when calling an undefined command' do
44
- @set.command('foo') {}
45
- lambda {
46
- @set.run_command @ctx, 'bar'
47
- }.should.raise(Pry::NoCommandError)
48
- end
49
-
50
- it 'should be able to remove its own commands' do
51
- @set.command('foo') {}
52
- @set.delete 'foo'
53
-
54
- lambda {
55
- @set.run_command @ctx, 'foo'
56
- }.should.raise(Pry::NoCommandError)
57
- end
58
-
59
- it 'should be able to remove its own commands, by listing name' do
60
- @set.command(/^foo1/, 'desc', :listing => 'foo') {}
61
- @set.delete 'foo'
62
-
63
- lambda {
64
- @set.run_command @ctx, /^foo1/
65
- }.should.raise(Pry::NoCommandError)
66
- end
67
-
68
- it 'should be able to import some commands from other sets' do
69
- run = false
70
-
71
- other_set = Pry::CommandSet.new do
72
- command('foo') { run = true }
73
- command('bar') {}
74
- end
75
-
76
- @set.import_from(other_set, 'foo')
77
-
78
- @set.run_command @ctx, 'foo'
79
- run.should == true
80
-
81
- lambda {
82
- @set.run_command @ctx, 'bar'
83
- }.should.raise(Pry::NoCommandError)
84
- end
85
-
86
- it 'should return command set after import' do
87
- run = false
88
-
89
- other_set = Pry::CommandSet.new do
90
- command('foo') { run = true }
91
- command('bar') {}
92
- end
93
-
94
- @set.import(other_set).should == @set
95
- end
96
-
97
- it 'should return command set after import_from' do
98
- run = false
99
-
100
- other_set = Pry::CommandSet.new do
101
- command('foo') { run = true }
102
- command('bar') {}
103
- end
104
-
105
- @set.import_from(other_set, 'foo').should == @set
106
- end
107
-
108
- it 'should be able to import some commands from other sets using listing name' do
109
- run = false
110
-
111
- other_set = Pry::CommandSet.new do
112
- command(/^foo1/, 'desc', :listing => 'foo') { run = true }
113
- end
114
-
115
- @set.import_from(other_set, 'foo')
116
-
117
- @set.run_command @ctx, /^foo1/
118
- run.should == true
119
- end
120
-
121
- it 'should be able to import a whole set' do
122
- run = []
123
-
124
- other_set = Pry::CommandSet.new do
125
- command('foo') { run << true }
126
- command('bar') { run << true }
127
- end
128
-
129
- @set.import other_set
130
-
131
- @set.run_command @ctx, 'foo'
132
- @set.run_command @ctx, 'bar'
133
- run.should == [true, true]
134
- end
135
-
136
- it 'should be able to import sets at creation' do
137
- run = false
138
- @set.command('foo') { run = true }
139
-
140
- Pry::CommandSet.new(@set).run_command @ctx, 'foo'
141
- run.should == true
142
- end
143
-
144
- it 'should set the descriptions of commands' do
145
- @set.command('foo', 'some stuff') {}
146
- @set.commands['foo'].description.should == 'some stuff'
147
- end
148
-
149
- describe "aliases" do
150
- it 'should be able to alias command' do
151
- run = false
152
- @set.command('foo', 'stuff') { run = true }
153
-
154
- @set.alias_command 'bar', 'foo'
155
- @set.commands['bar'].match.should == 'bar'
156
- @set.commands['bar'].description.should == 'Alias for `foo`'
157
-
158
- @set.run_command @ctx, 'bar'
159
- run.should == true
160
- end
161
-
162
- it 'should inherit options from original command' do
163
- run = false
164
- @set.command('foo', 'stuff', :shellwords => true, :interpolate => false) { run = true }
165
-
166
- @set.alias_command 'bar', 'foo'
167
- @set.commands['bar'].options[:shellwords].should == @set.commands['foo'].options[:shellwords]
168
- @set.commands['bar'].options[:interpolate].should == @set.commands['foo'].options[:interpolate]
169
-
170
- # however some options should not be inherited
171
- @set.commands['bar'].options[:listing].should.not == @set.commands['foo'].options[:listing]
172
- @set.commands['bar'].options[:listing].should == "bar"
173
- end
174
-
175
- it 'should be able to specify alias\'s description when aliasing' do
176
- run = false
177
- @set.command('foo', 'stuff') { run = true }
178
-
179
- @set.alias_command 'bar', 'foo', :desc => "tobina"
180
- @set.commands['bar'].match.should == 'bar'
181
- @set.commands['bar'].description.should == "tobina"
182
-
183
- @set.run_command @ctx, 'bar'
184
- run.should == true
185
- end
186
-
187
- it "should be able to alias a command by its invocation line" do
188
- run = false
189
- @set.command(/^foo1/, 'stuff', :listing => 'foo') { run = true }
190
-
191
- @set.alias_command 'bar', 'foo1'
192
- @set.commands['bar'].match.should == 'bar'
193
- @set.commands['bar'].description.should == 'Alias for `foo1`'
194
-
195
- @set.run_command @ctx, 'bar'
196
- run.should == true
197
- end
198
-
199
- it "should be able to specify options when creating alias" do
200
- run = false
201
- @set.command(/^foo1/, 'stuff', :listing => 'foo') { run = true }
202
-
203
- @set.alias_command /^b.r/, 'foo1', :listing => "bar"
204
- @set.commands[/^b.r/].options[:listing].should == "bar"
205
- end
206
-
207
- it "should set description to default if description parameter is nil" do
208
- run = false
209
- @set.command(/^foo1/, 'stuff', :listing => 'foo') { run = true }
210
-
211
- @set.alias_command "bar", 'foo1'
212
- @set.commands["bar"].description.should == "Alias for `foo1`"
213
- end
214
- end
215
-
216
- it 'should be able to change the descriptions of commands' do
217
- @set.command('foo', 'bar') {}
218
- @set.desc 'foo', 'baz'
219
-
220
- @set.commands['foo'].description.should == 'baz'
221
- end
222
-
223
- it 'should get the descriptions of commands' do
224
- @set.command('foo', 'bar') {}
225
- @set.desc('foo').should == 'bar'
226
- end
227
-
228
- it 'should get the descriptions of commands, by listing' do
229
- @set.command(/^foo1/, 'bar', :listing => 'foo') {}
230
- @set.desc('foo').should == 'bar'
231
- end
232
-
233
- it 'should return Pry::Command::VOID_VALUE for commands by default' do
234
- @set.command('foo') { 3 }
235
- @set.run_command(@ctx, 'foo').should == Pry::Command::VOID_VALUE
236
- end
237
-
238
- it 'should be able to keep return values' do
239
- @set.command('foo', '', :keep_retval => true) { 3 }
240
- @set.run_command(@ctx, 'foo').should == 3
241
- end
242
-
243
- it 'should be able to keep return values, even if return value is nil' do
244
- @set.command('foo', '', :keep_retval => true) { nil }
245
- @set.run_command(@ctx, 'foo').should == nil
246
- end
247
-
248
- it 'should be able to have its own helpers' do
249
- @set.command('foo') do
250
- should.respond_to :my_helper
251
- end
252
-
253
- @set.helpers do
254
- def my_helper; end
255
- end
256
-
257
- @set.run_command(@ctx, 'foo')
258
- Pry::Command.subclass('foo', '', {}, Module.new).new({:target => binding}).should.not.respond_to :my_helper
259
- end
260
-
261
- it 'should not recreate a new helper module when helpers is called' do
262
- @set.command('foo') do
263
- should.respond_to :my_helper
264
- should.respond_to :my_other_helper
265
- end
266
-
267
- @set.helpers do
268
- def my_helper; end
269
- end
270
-
271
- @set.helpers do
272
- def my_other_helper; end
273
- end
274
-
275
- @set.run_command(@ctx, 'foo')
276
- end
277
-
278
- it 'should import helpers from imported sets' do
279
- imported_set = Pry::CommandSet.new do
280
- helpers do
281
- def imported_helper_method; end
282
- end
283
- end
284
-
285
- @set.import imported_set
286
- @set.command('foo') { should.respond_to :imported_helper_method }
287
- @set.run_command(@ctx, 'foo')
288
- end
289
-
290
- it 'should import helpers even if only some commands are imported' do
291
- imported_set = Pry::CommandSet.new do
292
- helpers do
293
- def imported_helper_method; end
294
- end
295
-
296
- command('bar') {}
297
- end
298
-
299
- @set.import_from imported_set, 'bar'
300
- @set.command('foo') { should.respond_to :imported_helper_method }
301
- @set.run_command(@ctx, 'foo')
302
- end
303
-
304
- it 'should provide a :listing for a command that defaults to its name' do
305
- @set.command 'foo', "" do;end
306
- @set.commands['foo'].options[:listing].should == 'foo'
307
- end
308
-
309
- it 'should provide a :listing for a command that differs from its name' do
310
- @set.command 'foo', "", :listing => 'bar' do;end
311
- @set.commands['foo'].options[:listing].should == 'bar'
312
- end
313
-
314
- it "should provide a 'help' command" do
315
- @ctx[:command_set] = @set
316
- @ctx[:output] = StringIO.new
317
-
318
- lambda {
319
- @set.run_command(@ctx, 'help')
320
- }.should.not.raise
321
- end
322
-
323
-
324
- describe "renaming a command" do
325
- it 'should be able to rename and run a command' do
326
- run = false
327
- @set.command('foo') { run = true }
328
- @set.rename_command('bar', 'foo')
329
- @set.run_command(@ctx, 'bar')
330
- run.should == true
331
- end
332
-
333
- it 'should accept listing name when renaming a command' do
334
- run = false
335
- @set.command('foo', "", :listing => 'love') { run = true }
336
- @set.rename_command('bar', 'love')
337
- @set.run_command(@ctx, 'bar')
338
- run.should == true
339
- end
340
-
341
- it 'should raise exception trying to rename non-existent command' do
342
- lambda { @set.rename_command('bar', 'foo') }.should.raise ArgumentError
343
- end
344
-
345
- it 'should make old command name inaccessible' do
346
- @set.command('foo') { }
347
- @set.rename_command('bar', 'foo')
348
- lambda { @set.run_command(@ctx, 'foo') }.should.raise Pry::NoCommandError
349
- end
350
-
351
- it 'should be able to pass in options when renaming command' do
352
- desc = "hello"
353
- listing = "bing"
354
- @set.command('foo') { }
355
- @set.rename_command('bar', 'foo', :description => desc, :listing => listing, :keep_retval => true)
356
- @set.commands['bar'].description.should == desc
357
- @set.commands['bar'].options[:listing].should == listing
358
- @set.commands['bar'].options[:keep_retval].should == true
359
- end
360
- end
361
-
362
- describe "command decorators - before_command and after_command" do
363
- describe "before_command" do
364
- it 'should be called before the original command' do
365
- foo = []
366
- @set.command('foo') { foo << 1 }
367
- @set.before_command('foo') { foo << 2 }
368
- @set.run_command(@ctx, 'foo')
369
-
370
- foo.should == [2, 1]
371
- end
372
-
373
- it 'should be called before the original command, using listing name' do
374
- foo = []
375
- @set.command(/^foo1/, '', :listing => 'foo') { foo << 1 }
376
- @set.before_command('foo') { foo << 2 }
377
- @set.run_command(@ctx, /^foo1/)
378
-
379
- foo.should == [2, 1]
380
- end
381
-
382
- it 'should share the context with the original command' do
383
- @ctx[:target] = "test target string".__binding__
384
- before_val = nil
385
- orig_val = nil
386
- @set.command('foo') { orig_val = target }
387
- @set.before_command('foo') { before_val = target }
388
- @set.run_command(@ctx, 'foo')
389
-
390
- before_val.should == @ctx[:target]
391
- orig_val.should == @ctx[:target]
392
- end
393
-
394
- it 'should work when applied multiple times' do
395
- foo = []
396
- @set.command('foo') { foo << 1 }
397
- @set.before_command('foo') { foo << 2 }
398
- @set.before_command('foo') { foo << 3 }
399
- @set.before_command('foo') { foo << 4 }
400
- @set.run_command(@ctx, 'foo')
401
-
402
- foo.should == [4, 3, 2, 1]
403
- end
404
-
405
- end
406
-
407
- describe "after_command" do
408
- it 'should be called after the original command' do
409
- foo = []
410
- @set.command('foo') { foo << 1 }
411
- @set.after_command('foo') { foo << 2 }
412
- @set.run_command(@ctx, 'foo')
413
-
414
- foo.should == [1, 2]
415
- end
416
-
417
- it 'should be called after the original command, using listing name' do
418
- foo = []
419
- @set.command(/^foo1/, '', :listing => 'foo') { foo << 1 }
420
- @set.after_command('foo') { foo << 2 }
421
- @set.run_command(@ctx, /^foo1/)
422
-
423
- foo.should == [1, 2]
424
- end
425
-
426
- it 'should share the context with the original command' do
427
- @ctx[:target] = "test target string".__binding__
428
- after_val = nil
429
- orig_val = nil
430
- @set.command('foo') { orig_val = target }
431
- @set.after_command('foo') { after_val = target }
432
- @set.run_command(@ctx, 'foo')
433
-
434
- after_val.should == @ctx[:target]
435
- orig_val.should == @ctx[:target]
436
- end
437
-
438
- it 'should determine the return value for the command' do
439
- @set.command('foo', 'bar', :keep_retval => true) { 1 }
440
- @set.after_command('foo') { 2 }
441
- @set.run_command(@ctx, 'foo').should == 2
442
- end
443
-
444
- it 'should work when applied multiple times' do
445
- foo = []
446
- @set.command('foo') { foo << 1 }
447
- @set.after_command('foo') { foo << 2 }
448
- @set.after_command('foo') { foo << 3 }
449
- @set.after_command('foo') { foo << 4 }
450
- @set.run_command(@ctx, 'foo')
451
-
452
- foo.should == [1, 2, 3, 4]
453
- end
454
- end
455
-
456
- describe "before_command and after_command" do
457
- it 'should work when combining both before_command and after_command' do
458
- foo = []
459
- @set.command('foo') { foo << 1 }
460
- @set.after_command('foo') { foo << 2 }
461
- @set.before_command('foo') { foo << 3 }
462
- @set.run_command(@ctx, 'foo')
463
-
464
- foo.should == [3, 1, 2]
465
- end
466
-
467
- end
468
-
469
- end
470
-
471
- describe 'find_command' do
472
- it 'should find commands with the right string' do
473
- cmd = @set.command('rincewind'){ }
474
- @set.find_command('rincewind').should == cmd
475
- end
476
-
477
- it 'should not find commands with spaces before' do
478
- cmd = @set.command('luggage'){ }
479
- @set.find_command(' luggage').should == nil
480
- end
481
-
482
- it 'should find commands with arguments after' do
483
- cmd = @set.command('vetinari'){ }
484
- @set.find_command('vetinari --knock 3').should == cmd
485
- end
486
-
487
- it 'should find commands with names containing spaces' do
488
- cmd = @set.command('nobby nobbs'){ }
489
- @set.find_command('nobby nobbs --steal petty-cash').should == cmd
490
- end
491
-
492
- it 'should find command defined by regex' do
493
- cmd = @set.command(/(capt|captain) vimes/i){ }
494
- @set.find_command('Capt Vimes').should == cmd
495
- end
496
-
497
- it 'should find commands defined by regex with arguments' do
498
- cmd = @set.command(/(cpl|corporal) Carrot/i){ }
499
- @set.find_command('cpl carrot --write-home').should == cmd
500
- end
501
-
502
- it 'should not find commands by listing' do
503
- cmd = @set.command(/werewol(f|ve)s?/, 'only once a month', :listing => "angua"){ }
504
- @set.find_command('angua').should == nil
505
- end
506
-
507
- it 'should not find commands without command_prefix' do
508
- Pry.config.command_prefix = '%'
509
- cmd = @set.command('detritus'){ }
510
- @set.find_command('detritus').should == nil
511
- Pry.config.command_prefix = ''
512
- end
513
-
514
- it "should find commands that don't use the prefix" do
515
- Pry.config.command_prefix = '%'
516
- cmd = @set.command('colon', 'Sergeant Fred', :use_prefix => false){ }
517
- @set.find_command('colon').should == cmd
518
- Pry.config.command_prefix = ''
519
- end
520
-
521
- it "should find the command that has the longest match" do
522
- cmd = @set.command(/\.(.*)/){ }
523
- cmd2 = @set.command(/\.\|\|(.*)/){ }
524
- @set.find_command('.||').should == cmd2
525
- end
526
-
527
- it "should find the command that has the longest name" do
528
- cmd = @set.command(/\.(.*)/){ }
529
- cmd2 = @set.command('.||'){ }
530
- @set.find_command('.||').should == cmd2
531
- end
532
- end
533
-
534
- describe '.valid_command?' do
535
- it 'should be true for commands that can be found' do
536
- cmd = @set.command('archchancellor')
537
- @set.valid_command?('archchancellor of_the?(:University)').should == true
538
- end
539
-
540
- it 'should be false for commands that can\'' do
541
- @set.valid_command?('def monkey(ape)').should == false
542
- end
543
-
544
- it 'should not cause argument interpolation' do
545
- cmd = @set.command('hello')
546
- lambda {
547
- @set.valid_command?('hello #{raise "futz"}')
548
- }.should.not.raise
549
- end
550
- end
551
-
552
- describe '.process_line' do
553
-
554
- it 'should return Result.new(false) if there is no matching command' do
555
- result = @set.process_line('1 + 42')
556
- result.command?.should == false
557
- result.void_command?.should == false
558
- result.retval.should == nil
559
- end
560
-
561
- it 'should return Result.new(true, VOID) if the command is not keep_retval' do
562
- @set.create_command('mrs-cake') do
563
- def process; 42; end
564
- end
565
-
566
- result = @set.process_line('mrs-cake')
567
- result.command?.should == true
568
- result.void_command?.should == true
569
- result.retval.should == Pry::Command::VOID_VALUE
570
- end
571
-
572
- it 'should return Result.new(true, retval) if the command is keep_retval' do
573
- @set.create_command('magrat', 'the maiden', :keep_retval => true) do
574
- def process; 42; end
575
- end
576
-
577
- result = @set.process_line('magrat')
578
- result.command?.should == true
579
- result.void_command?.should == false
580
- result.retval.should == 42
581
- end
582
-
583
- it 'should pass through context' do
584
- ctx = {
585
- :eval_string => "bloomers",
586
- :pry_instance => Object.new,
587
- :output => StringIO.new,
588
- :target => binding
589
- }
590
- @set.create_command('agnes') do
591
- define_method(:process) do
592
- eval_string.should == ctx[:eval_string]
593
- output.should == ctx[:output]
594
- target.should == ctx[:target]
595
- _pry_.should == ctx[:pry_instance]
596
- end
597
- end
598
-
599
- @set.process_line('agnes', ctx)
600
- end
601
-
602
- it 'should add command_set to context' do
603
- set = @set
604
- @set.create_command(/nann+y ogg+/) do
605
- define_method(:process) do
606
- command_set.should == set
607
- end
608
- end
609
-
610
- @set.process_line('nannnnnny oggggg')
611
- end
612
- end
613
-
614
- if defined?(Bond)
615
- describe '.complete' do
616
- it "should list all command names" do
617
- @set.create_command('susan'){ }
618
- @set.complete('sus').should.include 'susan '
619
- end
620
-
621
- it "should delegate to commands" do
622
- @set.create_command('susan'){ def complete(search); ['--foo']; end }
623
- @set.complete('susan ').should == ['--foo']
624
- end
625
- end
626
- end
627
- end