pry 0.10.pre.1-java → 0.10.0.pre2-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 +126 -182
  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,9 +0,0 @@
1
- require 'helper'
2
-
3
- describe Pry::Helpers::CommandHelpers do
4
- before do
5
- @helper = Pry::Helpers::CommandHelpers
6
- end
7
-
8
- # FIXME: currently no tests
9
- end
@@ -1,668 +0,0 @@
1
- require 'helper'
2
-
3
- describe "commands" do
4
- before do
5
- @str_output = StringIO.new
6
- end
7
-
8
- describe "alias_command" do
9
- it 'should make an aliasd command behave like its original' do
10
- set = Pry::CommandSet.new do
11
- command "test-command" do
12
- output.puts "testing 1, 2, 3"
13
- end
14
- alias_command "test-alias", "test-command"
15
- end
16
- redirect_pry_io(InputTester.new("test-alias"), out1 = StringIO.new) do
17
- Pry.start self, :commands => set
18
- end
19
-
20
- redirect_pry_io(InputTester.new("test-command"), out2 = StringIO.new) do
21
- Pry.start self, :commands => set
22
- end
23
-
24
- out1.string.should == out2.string
25
- end
26
-
27
- it 'should pass on arguments to original' do
28
- set = Pry::CommandSet.new do
29
- command "test-command" do |*args|
30
- output.puts "testing #{args.join(' ')}"
31
- end
32
- alias_command "test-alias", "test-command"
33
- end
34
-
35
- redirect_pry_io(InputTester.new("test-command hello baby duck"), out1 = StringIO.new) do
36
- Pry.start self, :commands => set
37
- end
38
-
39
- out1.string.should =~ /hello baby duck/
40
-
41
- redirect_pry_io(InputTester.new("test-alias hello baby duck"), out2 = StringIO.new) do
42
- Pry.start self, :commands => set
43
- end
44
-
45
- out2.string.should == out1.string
46
- end
47
-
48
- it 'should pass option arguments to original' do
49
- set = Pry::CommandSet.new do
50
- import Pry::Commands
51
- alias_command "test-alias", "ls"
52
- end
53
-
54
- obj = Class.new { @x = 10 }
55
- redirect_pry_io(InputTester.new("ls -i"), out1 = StringIO.new) do
56
- Pry.start obj, :commands => set
57
- end
58
-
59
- out1.string.should =~ /@x/
60
-
61
- redirect_pry_io(InputTester.new("test-alias -i"), out2 = StringIO.new) do
62
- Pry.start obj, :commands => set
63
- end
64
-
65
- out2.string.should == out1.string
66
- end
67
-
68
- it 'should pass option arguments to original with additional parameters' do
69
- set = Pry::CommandSet.new do
70
- import Pry::Commands
71
- alias_command "test-alias", "ls -M"
72
- end
73
-
74
- obj = Class.new { @x = Class.new { define_method(:plymouth) {} } }
75
- redirect_pry_io(InputTester.new("ls -M @x"), out1 = StringIO.new) do
76
- Pry.start obj, :commands => set
77
- end
78
-
79
- out1.string.should =~ /plymouth/
80
-
81
- redirect_pry_io(InputTester.new("test-alias @x"), out2 = StringIO.new) do
82
- Pry.start obj, :commands => set
83
- end
84
-
85
- out2.string.should == out1.string
86
- end
87
-
88
- it 'should be able to alias a regex command' do
89
- set = Pry::CommandSet.new do
90
- command /du.k/ do
91
- output.puts "ducky"
92
- end
93
- alias_command "test-alias", "duck"
94
- end
95
-
96
- redirect_pry_io(InputTester.new("test-alias"), out1 = StringIO.new) do
97
- Pry.start self, :commands => set
98
- end
99
-
100
- out1.string.should =~ /ducky/
101
- end
102
-
103
- it 'should be able to make the alias a regex' do
104
- set = Pry::CommandSet.new do
105
- command /du.k/ do
106
- output.puts "ducky"
107
- end
108
- alias_command /test-ali.s/, "duck"
109
- end
110
-
111
- redirect_pry_io(InputTester.new("test-alias"), out1 = StringIO.new) do
112
- Pry.start self, :commands => set
113
- end
114
-
115
- out1.string.should =~ /ducky/
116
- end
117
- end
118
-
119
- describe "Pry::Command#run" do
120
- it 'should allow running of commands with following whitespace' do
121
- $_scratch = Object.new
122
- o = Object.new
123
-
124
- set = Pry::CommandSet.new do
125
- import Pry::Commands
126
- command "test-run" do
127
- run "cd / "
128
- end
129
- end
130
- redirect_pry_io(InputTester.new("cd 1/2/3/4/5/6/$_scratch",
131
- "@nesting1 = _pry_.binding_stack.size",
132
- "test-run",
133
- "@obj = self",
134
- "@nesting2 = _pry_.binding_stack.size",
135
- "exit-all")) do
136
- Pry.start(o, :commands => set)
137
- end
138
-
139
- $_scratch.instance_variable_get(:@nesting1).should == 8
140
- o.instance_variable_get(:@obj).should == o
141
- o.instance_variable_get(:@nesting2).should == 1
142
- $_scratch = nil
143
- end
144
-
145
- it 'should allow running of cd command when contained in a single string' do
146
- $_scratch = Object.new
147
- o = Object.new
148
-
149
- set = Pry::CommandSet.new do
150
- import Pry::Commands
151
- command "test-run" do
152
- run "cd /"
153
- end
154
- end
155
- redirect_pry_io(InputTester.new("cd 1/2/3/4/5/6/$_scratch",
156
- "@nesting1 = _pry_.binding_stack.size",
157
- "test-run",
158
- "@obj = self",
159
- "@nesting2 = _pry_.binding_stack.size",
160
- "exit-all")) do
161
- Pry.start(o, :commands => set)
162
- end
163
-
164
- $_scratch.instance_variable_get(:@nesting1).should == 8
165
- o.instance_variable_get(:@obj).should == o
166
- o.instance_variable_get(:@nesting2).should == 1
167
- $_scratch = nil
168
- end
169
-
170
- it 'should allow running of cd command when split into array' do
171
- $_scratch = Object.new
172
- o = Object.new
173
-
174
- set = Pry::CommandSet.new do
175
- import Pry::Commands
176
- command "test-run" do
177
- run "cd", "/"
178
- end
179
- end
180
- redirect_pry_io(InputTester.new("cd 1/2/3/4/5/6/$_scratch",
181
- "@nesting1 = _pry_.binding_stack.size",
182
- "test-run",
183
- "@obj = self",
184
- "@nesting2 = _pry_.binding_stack.size",
185
- "exit-all")) do
186
- Pry.start(o, :commands => set)
187
- end
188
-
189
- $_scratch.instance_variable_get(:@nesting1).should == 8
190
- o.instance_variable_get(:@obj).should == o
191
- o.instance_variable_get(:@nesting2).should == 1
192
- $_scratch = nil
193
- end
194
-
195
- it 'should run a command from within a command' do
196
- klass = Pry::CommandSet.new do
197
- command "v" do
198
- output.puts "v command"
199
- end
200
-
201
- command "run_v" do
202
- run "v"
203
- end
204
- end
205
-
206
- Pry.new(:input => InputTester.new("run_v"), :output => @str_output, :commands => klass).rep
207
-
208
- @str_output.string.should =~ /v command/
209
- end
210
-
211
- it 'should run a regex command from within a command' do
212
- klass = Pry::CommandSet.new do
213
- command /v(.*)?/ do |arg|
214
- output.puts "v #{arg}"
215
- end
216
-
217
- command "run_v" do
218
- run "vbaby"
219
- end
220
- end
221
-
222
- redirect_pry_io(InputTester.new("run_v"), @str_output) do
223
- Pry.new(:commands => klass).rep
224
- end
225
-
226
- @str_output.string.should =~ /v baby/
227
- end
228
-
229
- it 'should run a command from within a command with arguments' do
230
- klass = Pry::CommandSet.new do
231
- command /v(\w+)/ do |arg1, arg2|
232
- output.puts "v #{arg1} #{arg2}"
233
- end
234
-
235
- command "run_v_explicit_parameter" do
236
- run "vbaby", "param"
237
- end
238
-
239
- command "run_v_embedded_parameter" do
240
- run "vbaby param"
241
- end
242
- end
243
-
244
- ["run_v_explicit_parameter", "run_v_embedded_parameter"].each do |cmd|
245
- redirect_pry_io(InputTester.new(cmd), @str_output) do
246
- Pry.new(:commands => klass).rep
247
- end
248
- @str_output.string.should =~ /v baby param/
249
- end
250
- end
251
- end
252
-
253
- describe "Pry#run_command" do
254
- it 'should run a command in a specified context' do
255
- b = Pry.binding_for(7)
256
- p = Pry.new(:output => @str_output)
257
- p.run_command("ls -m", "", b)
258
- p.output.string.should =~ /divmod/
259
- end
260
-
261
- it 'should run a command that modifies the passed in eval_string' do
262
- b = Pry.binding_for(7)
263
- p = Pry.new(:output => @str_output)
264
- eval_string = "def hello\npeter pan\n"
265
- p.run_command("amend-line !", eval_string, b)
266
- eval_string.should =~ /def hello/
267
- eval_string.should.not =~ /peter pan/
268
- end
269
-
270
- it 'should run a command in the context of a session' do
271
- mock_pry("@session_ivar = 10", "_pry_.run_command('ls')").should =~ /@session_ivar/
272
- end
273
- end
274
-
275
- it 'should interpolate ruby code into commands' do
276
- klass = Pry::CommandSet.new do
277
- command "hello", "", :keep_retval => true do |arg|
278
- arg
279
- end
280
- end
281
-
282
- $test_interpolation = "bing"
283
- Pry.new(:input => StringIO.new('hello #{$test_interpolation}'), :output => @str_output, :commands => klass).rep
284
- @str_output.string.should =~ /bing/
285
- $test_interpolation = nil
286
- end
287
-
288
- # bug fix for https://github.com/pry/pry/issues/170
289
- it 'should not choke on complex string interpolation when checking if ruby code is a command' do
290
- redirect_pry_io(InputTester.new('/#{Regexp.escape(File.expand_path("."))}/'), @str_output) do
291
- pry
292
- end
293
-
294
- @str_output.string.should.not =~ /SyntaxError/
295
- end
296
-
297
- it 'should NOT interpolate ruby code into commands if :interpolate => false' do
298
- klass = Pry::CommandSet.new do
299
- command "hello", "", :keep_retval => true, :interpolate => false do |arg|
300
- arg
301
- end
302
- end
303
-
304
- $test_interpolation = "bing"
305
- Pry.new(:input => StringIO.new('hello #{$test_interpolation}'), :output => @str_output, :commands => klass).rep
306
- @str_output.string.should =~ /test_interpolation/
307
- $test_interpolation = nil
308
- end
309
-
310
- it 'should NOT try to interpolate pure ruby code (no commands) ' do
311
- Pry.new(:input => StringIO.new('format \'#{aggy}\''), :output => @str_output).rep
312
- @str_output.string.should.not =~ /NameError/
313
-
314
- @str_output = StringIO.new
315
- Pry.new(:input => StringIO.new('format #{aggy}'), :output => @str_output).rep
316
- @str_output.string.should.not =~ /NameError/
317
-
318
- $test_interpolation = "blah"
319
- @str_output = StringIO.new
320
- Pry.new(:input => StringIO.new('format \'#{$test_interpolation}\''), :output => @str_output).rep
321
-
322
- @str_output.string.should.not =~ /blah/
323
- $test_interpolation = nil
324
- end
325
-
326
- it 'should create a command with a space in its name' do
327
- set = Pry::CommandSet.new do
328
- command "hello baby", "" do
329
- output.puts "hello baby command"
330
- end
331
- end
332
-
333
- redirect_pry_io(InputTester.new("hello baby", "exit-all"), @str_output) do
334
- Pry.new(:commands => set).rep
335
- end
336
-
337
- @str_output.string.should =~ /hello baby command/
338
- end
339
-
340
- it 'should create a command with a space in its name and pass an argument' do
341
- set = Pry::CommandSet.new do
342
- command "hello baby", "" do |arg|
343
- output.puts "hello baby command #{arg}"
344
- end
345
- end
346
-
347
- redirect_pry_io(InputTester.new("hello baby john"), @str_output) do
348
- Pry.new(:commands => set).rep
349
- end
350
-
351
- @str_output.string.should =~ /hello baby command john/
352
- end
353
-
354
- it 'should create a regex command and be able to invoke it' do
355
- set = Pry::CommandSet.new do
356
- command /hello(.)/, "" do
357
- c = captures.first
358
- output.puts "hello#{c}"
359
- end
360
- end
361
-
362
- redirect_pry_io(InputTester.new("hello1"), @str_output) do
363
- Pry.new(:commands => set).rep
364
- end
365
-
366
- @str_output.string.should =~ /hello1/
367
- end
368
-
369
- it 'should create a regex command and pass captures into the args list before regular arguments' do
370
- set = Pry::CommandSet.new do
371
- command /hello(.)/, "" do |c1, a1|
372
- output.puts "hello #{c1} #{a1}"
373
- end
374
- end
375
-
376
- redirect_pry_io(InputTester.new("hello1 baby"), @str_output) do
377
- Pry.new(:commands => set).rep
378
- end
379
-
380
- @str_output.string.should =~ /hello 1 baby/
381
- end
382
-
383
- it 'should create a regex command and interpolate the captures' do
384
- set = Pry::CommandSet.new do
385
- command /hello (.*)/, "" do |c1|
386
- output.puts "hello #{c1}"
387
- end
388
- end
389
-
390
- $obj = "bing"
391
- redirect_pry_io(InputTester.new('hello #{$obj}'), @str_output) do
392
- Pry.new(:commands => set).rep
393
- end
394
-
395
- @str_output.string.should =~ /hello bing/
396
-
397
- $obj = nil
398
- end
399
-
400
- it 'should create a regex command and arg_string should be interpolated' do
401
- set = Pry::CommandSet.new do
402
- command /hello(\w+)/, "" do |c1, a1, a2, a3|
403
- output.puts "hello #{c1} #{a1} #{a2} #{a3}"
404
- end
405
- end
406
-
407
- $a1 = "bing"
408
- $a2 = "bong"
409
- $a3 = "bang"
410
- redirect_pry_io(InputTester.new('hellojohn #{$a1} #{$a2} #{$a3}'), @str_output) do
411
- Pry.new(:commands => set).rep
412
- end
413
-
414
- @str_output.string.should =~ /hello john bing bong bang/
415
-
416
- $a1 = $a2 = $a3 = nil
417
- end
418
-
419
- it 'if a regex capture is missing it should be nil' do
420
- set = Pry::CommandSet.new do
421
- command /hello(.)?/, "" do |c1, a1|
422
- output.puts "hello #{c1.inspect} #{a1}"
423
- end
424
- end
425
-
426
- redirect_pry_io(InputTester.new("hello baby"), @str_output) do
427
- Pry.new(:commands => set).rep
428
- end
429
-
430
- @str_output.string.should =~ /hello nil baby/
431
- end
432
-
433
- it 'should create a command in a nested context and that command should be accessible from the parent' do
434
- x = "@x=nil\ncd 7\n_pry_.commands.instance_eval {\ncommand('bing') { |arg| run arg }\n}\ncd ..\nbing ls\nexit-all"
435
- redirect_pry_io(StringIO.new("@x=nil\ncd 7\n_pry_.commands.instance_eval {\ncommand('bing') { |arg| run arg }\n}\ncd ..\nbing ls\nexit-all"), @str_output) do
436
- Pry.new.repl(0)
437
- end
438
-
439
- @str_output.string.should =~ /@x/
440
- end
441
-
442
- it 'should define a command that keeps its return value' do
443
- klass = Pry::CommandSet.new do
444
- command "hello", "", :keep_retval => true do
445
- :kept_hello
446
- end
447
- end
448
-
449
- Pry.new(:input => StringIO.new("hello\n"), :output => @str_output, :commands => klass).rep
450
- @str_output.string.should =~ /:kept_hello/
451
- @str_output.string.should =~ /=>/
452
- end
453
-
454
- it 'should define a command that does NOT keep its return value' do
455
- klass = Pry::CommandSet.new do
456
- command "hello", "", :keep_retval => false do
457
- :kept_hello
458
- end
459
- end
460
-
461
- Pry.new(:input => StringIO.new("hello\n"), :output => @str_output, :commands => klass).rep
462
- (@str_output.string =~ /:kept_hello/).should == nil
463
- @str_output.string !~ /=>/
464
- end
465
-
466
- it 'should define a command that keeps its return value even when nil' do
467
- klass = Pry::CommandSet.new do
468
- command "hello", "", :keep_retval => true do
469
- nil
470
- end
471
- end
472
-
473
- Pry.new(:input => StringIO.new("hello\n"), :output => @str_output, :commands => klass).rep
474
-
475
- @str_output.string.should =~ /nil/
476
- @str_output.string.should =~ /=>/
477
- end
478
-
479
- it 'should define a command that keeps its return value but does not return when value is void' do
480
- klass = Pry::CommandSet.new do
481
- command "hello", "", :keep_retval => true do
482
- void
483
- end
484
- end
485
-
486
- Pry.new(:input => StringIO.new("hello\n"), :output => @str_output, :commands => klass).rep
487
- @str_output.string.empty?.should == true
488
- end
489
-
490
- it 'a command (with :keep_retval => false) that replaces eval_string with a valid expression should not have the expression value suppressed' do
491
- klass = Pry::CommandSet.new do
492
- command "hello", "" do
493
- eval_string.replace("6")
494
- end
495
- end
496
-
497
- Pry.new(:input => StringIO.new("def yo\nhello\n"), :output => @str_output, :commands => klass).rep
498
- @str_output.string.should =~ /6/
499
- end
500
-
501
-
502
- it 'a command (with :keep_retval => true) that replaces eval_string with a valid expression should overwrite the eval_string with the return value' do
503
- klass = Pry::CommandSet.new do
504
- command "hello", "", :keep_retval => true do
505
- eval_string.replace("6")
506
- 7
507
- end
508
- end
509
-
510
- Pry.new(:input => StringIO.new("def yo\nhello\n"), :output => @str_output, :commands => klass).rep
511
-
512
- @str_output.string.should =~ /7/
513
- @str_output.string.should.not =~ /6/
514
- end
515
-
516
- it 'a command that return a value in a multi-line expression should clear the expression and return the value' do
517
- klass = Pry::CommandSet.new do
518
- command "hello", "", :keep_retval => true do
519
- 5
520
- end
521
- end
522
-
523
- Pry.new(:input => StringIO.new("def yo\nhello\n"), :output => @str_output, :commands => klass).rep
524
-
525
- @str_output.string.should =~ /5/
526
- end
527
-
528
- it 'should set the commands default, and the default should be overridable' do
529
- klass = Pry::CommandSet.new do
530
- command "hello" do
531
- output.puts "hello world"
532
- end
533
- end
534
-
535
- Pry.commands = klass
536
-
537
- Pry.new(:input => InputTester.new("hello"), :output => @str_output).rep
538
- @str_output.string.should =~ /hello world/
539
-
540
- other_klass = Pry::CommandSet.new do
541
- command "goodbye", "" do
542
- output.puts "goodbye world"
543
- end
544
- end
545
-
546
- @str_output = StringIO.new
547
-
548
- Pry.new(:input => InputTester.new("goodbye"), :output => @str_output, :commands => other_klass).rep
549
- @str_output.string.should =~ /goodbye world/
550
- end
551
-
552
- it 'should inherit commands from Pry::Commands' do
553
- klass = Pry::CommandSet.new Pry::Commands do
554
- command "v" do
555
- end
556
- end
557
-
558
- klass.commands.include?("nesting").should == true
559
- klass.commands.include?("jump-to").should == true
560
- klass.commands.include?("cd").should == true
561
- klass.commands.include?("v").should == true
562
- end
563
-
564
- it 'should change description of a command using desc' do
565
- klass = Pry::CommandSet.new do; import Pry::DefaultCommands::Help; end
566
- orig = klass.commands["help"].description
567
- klass.instance_eval do
568
- desc "help", "blah"
569
- end
570
- klass.commands["help"].description.should.not == orig
571
- klass.commands["help"].description.should == "blah"
572
- end
573
-
574
- it 'should enable an inherited method to access opts and output and target, due to instance_exec' do
575
- klass = Pry::CommandSet.new do
576
- command "v" do
577
- output.puts "#{target.eval('self')}"
578
- end
579
- end
580
-
581
- child_klass = Pry::CommandSet.new klass do
582
- end
583
-
584
- Pry.new(:print => proc {}, :input => InputTester.new("v"),
585
- :output => @str_output, :commands => child_klass).rep("john")
586
-
587
- @str_output.string.rstrip.should == "john"
588
- end
589
-
590
- it 'should import commands from another command object' do
591
- klass = Pry::CommandSet.new do
592
- import_from Pry::Commands, "ls", "jump-to"
593
- end
594
-
595
- klass.commands.include?("ls").should == true
596
- klass.commands.include?("jump-to").should == true
597
- end
598
-
599
- it 'should delete some inherited commands when using delete method' do
600
- klass = Pry::CommandSet.new Pry::Commands do
601
- command "v" do
602
- end
603
-
604
- delete "show-doc", "show-method"
605
- delete "ls"
606
- end
607
-
608
- klass.commands.include?("nesting").should == true
609
- klass.commands.include?("jump-to").should == true
610
- klass.commands.include?("cd").should == true
611
- klass.commands.include?("v").should == true
612
- klass.commands.include?("show-doc").should == false
613
- klass.commands.include?("show-method").should == false
614
- klass.commands.include?("ls").should == false
615
- end
616
-
617
- it 'should override some inherited commands' do
618
- klass = Pry::CommandSet.new Pry::Commands do
619
- command "jump-to" do
620
- output.puts "jump-to the music"
621
- end
622
-
623
- command "help" do
624
- output.puts "help to the music"
625
- end
626
- end
627
-
628
- # suppress evaluation output
629
- Pry.print = proc {}
630
-
631
- Pry.new(:input => InputTester.new("jump-to"), :output => @str_output, :commands => klass).rep
632
- @str_output.string.rstrip.should == "jump-to the music"
633
-
634
- @str_output = StringIO.new
635
- Pry.new(:input => InputTester.new("help"), :output => @str_output, :commands => klass).rep
636
- @str_output.string.should == "help to the music\n"
637
-
638
-
639
- Pry.reset_defaults
640
- Pry.color = false
641
- end
642
-
643
- it 'should run a command with no parameter' do
644
- pry_tester = Pry.new
645
- pry_tester.commands = CommandTester
646
- pry_tester.input = InputTester.new("command1", "exit-all")
647
- pry_tester.commands = CommandTester
648
-
649
- pry_tester.output = @str_output
650
-
651
- pry_tester.rep
652
-
653
- @str_output.string.should =~ /command1/
654
- end
655
-
656
- it 'should run a command with one parameter' do
657
- pry_tester = Pry.new
658
- pry_tester.commands = CommandTester
659
- pry_tester.input = InputTester.new("command2 horsey", "exit-all")
660
- pry_tester.commands = CommandTester
661
-
662
- pry_tester.output = @str_output
663
-
664
- pry_tester.rep
665
-
666
- @str_output.string.should =~ /horsey/
667
- end
668
- end