pry 0.10.pre.1-i386-mingw32 → 0.10.0.pre3-i386-mingw32

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