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,314 +0,0 @@
1
- require 'helper'
2
-
3
- if !mri18_and_no_real_source_location?
4
- describe "Pry::DefaultCommands::Documentation" do
5
- describe "show-doc" do
6
- before do
7
- @str_output = StringIO.new
8
- end
9
-
10
- it 'should output a method\'s documentation' do
11
- redirect_pry_io(InputTester.new("show-doc sample_method", "exit-all"), @str_output) do
12
- pry
13
- end
14
-
15
- @str_output.string.should =~ /sample doc/
16
- end
17
-
18
- it 'should output a method\'s documentation with line numbers' do
19
- redirect_pry_io(InputTester.new("show-doc sample_method -l", "exit-all"), @str_output) do
20
- pry
21
- end
22
-
23
- @str_output.string.should =~ /\d: sample doc/
24
- end
25
-
26
- it 'should output a method\'s documentation with line numbers (base one)' do
27
- redirect_pry_io(InputTester.new("show-doc sample_method -b", "exit-all"), @str_output) do
28
- pry
29
- end
30
-
31
- @str_output.string.should =~ /1: sample doc/
32
- end
33
-
34
- it 'should output a method\'s documentation if inside method without needing to use method name' do
35
- o = Object.new
36
-
37
- # sample comment
38
- def o.sample
39
- redirect_pry_io(InputTester.new("show-doc", "exit-all"), $out=StringIO.new) do
40
- binding.pry
41
- end
42
- end
43
- o.sample
44
- $out.string.should =~ /sample comment/
45
- $out = nil
46
- end
47
-
48
- it "should be able to find super methods" do
49
-
50
- c = Class.new{
51
- # classy initialize!
52
- def initialize(*args); end
53
- }
54
-
55
- d = Class.new(c){
56
- # grungy initialize??
57
- def initialize(*args, &block); end
58
- }
59
-
60
- o = d.new
61
-
62
- # instancey initialize!
63
- def o.initialize; end
64
-
65
- mock_pry(binding, "show-doc o.initialize").should =~ /instancey initialize/
66
- mock_pry(binding, "show-doc --super o.initialize").should =~ /grungy initialize/
67
- mock_pry(binding, "show-doc o.initialize -ss").should =~ /classy initialize/
68
- mock_pry(binding, "show-doc --super o.initialize -ss").should == mock_pry("show-doc Object#initialize")
69
- end
70
- end
71
-
72
- describe "rdoc highlighting" do
73
- it "should syntax highlight code in rdoc" do
74
- c = Class.new{
75
- # This can initialize your class:
76
- #
77
- # a = c.new :foo
78
- #
79
- # @param foo
80
- def initialize(foo); end
81
- }
82
-
83
- begin
84
- mock_pry(binding, "show-doc c#initialize").should =~ /c.new :foo/
85
- Pry.config.color = true
86
- # I don't want the test to rely on which colour codes are there, just to
87
- # assert that "something" is being colourized.
88
- mock_pry(binding, "show-doc c#initialize").should.not =~ /c.new :foo/
89
- ensure
90
- Pry.config.color = false
91
- end
92
- end
93
-
94
- it "should syntax highlight `code` in rdoc" do
95
- c = Class.new{
96
- # After initializing your class with `c.new(:foo)`, go have fun!
97
- #
98
- # @param foo
99
- def initialize(foo); end
100
- }
101
-
102
- begin
103
- mock_pry(binding, "show-doc c#initialize").should =~ /c.new\(:foo\)/
104
- Pry.config.color = true
105
- # I don't want the test to rely on which colour codes are there, just to
106
- # assert that "something" is being colourized.
107
- mock_pry(binding, "show-doc c#initialize").should.not =~ /c.new\(:foo\)/
108
- ensure
109
- Pry.config.color = false
110
- end
111
-
112
- end
113
-
114
- it "should not syntax highlight `` inside code" do
115
- c = Class.new{
116
- # Convert aligned output (from many shell commands) into nested arrays:
117
- #
118
- # a = decolumnize `ls -l $HOME`
119
- #
120
- # @param output
121
- def decolumnize(output); end
122
- }
123
-
124
- begin
125
- Pry.config.color = true
126
- mock_pry(binding, "show-doc c#decolumnize").should =~ /ls -l \$HOME/
127
- mock_pry(binding, "show-doc c#decolumnize").should.not =~ /`ls -l \$HOME`/
128
- ensure
129
- Pry.config.color = false
130
- end
131
- end
132
- end
133
-
134
- describe "on modules" do
135
- before do
136
- # god this is boring1
137
- class ShowSourceTestClass
138
- def alpha
139
- end
140
- end
141
-
142
- # god this is boring2
143
- module ShowSourceTestModule
144
- def alpha
145
- end
146
- end
147
-
148
- # god this is boring3
149
- ShowSourceTestClassWeirdSyntax = Class.new do
150
- def beta
151
- end
152
- end
153
-
154
- # god this is boring4
155
- ShowSourceTestModuleWeirdSyntax = Module.new do
156
- def beta
157
- end
158
- end
159
- end
160
-
161
- after do
162
- Object.remove_const :ShowSourceTestClass
163
- Object.remove_const :ShowSourceTestClassWeirdSyntax
164
- Object.remove_const :ShowSourceTestModule
165
- Object.remove_const :ShowSourceTestModuleWeirdSyntax
166
- end
167
-
168
- describe "basic functionality, should show docs for top-level module definitions" do
169
- it 'should show docs for a class' do
170
- mock_pry("show-doc ShowSourceTestClass").should =~ /god this is boring1/
171
- end
172
-
173
- it 'should show docs for a module' do
174
- mock_pry("show-doc ShowSourceTestModule").should =~ /god this is boring2/
175
- end
176
-
177
- it 'should show docs for a class when Const = Class.new syntax is used' do
178
- mock_pry("show-doc ShowSourceTestClassWeirdSyntax").should =~ /god this is boring3/
179
- end
180
-
181
- it 'should show docs for a module when Const = Module.new syntax is used' do
182
- mock_pry("show-doc ShowSourceTestModuleWeirdSyntax").should =~ /god this is boring4/
183
- end
184
- end
185
-
186
- if !Pry::Helpers::BaseHelpers.mri_18?
187
- describe "in REPL" do
188
- it 'should find class defined in repl' do
189
- mock_pry("# hello tobina", "class TobinaMyDog", "def woof", "end", "end", "show-doc TobinaMyDog").should =~ /hello tobina/
190
- Object.remove_const :TobinaMyDog
191
- end
192
- end
193
- end
194
-
195
- it 'should lookup module name with respect to current context' do
196
- constant_scope(:AlphaClass, :BetaClass) do
197
-
198
- # top-level beta
199
- class BetaClass
200
- def alpha
201
- end
202
- end
203
-
204
- class AlphaClass
205
-
206
- # nested beta
207
- class BetaClass
208
- def beta
209
- end
210
- end
211
- end
212
-
213
- redirect_pry_io(InputTester.new("show-doc BetaClass", "exit-all"), outp=StringIO.new) do
214
- AlphaClass.pry
215
- end
216
-
217
- outp.string.should =~ /nested beta/
218
- end
219
- end
220
-
221
- it 'should lookup nested modules' do
222
- constant_scope(:AlphaClass) do
223
- class AlphaClass
224
-
225
- # nested beta
226
- class BetaClass
227
- def beta
228
- end
229
- end
230
- end
231
-
232
- mock_pry("show-doc AlphaClass::BetaClass").should =~ /nested beta/
233
- end
234
- end
235
-
236
- describe "show-doc -a" do
237
- it 'should show the docs for all monkeypatches defined in different files' do
238
-
239
- # local monkeypatch
240
- class TestClassForShowSource
241
- def beta
242
- end
243
- end
244
-
245
- result = mock_pry("show-doc TestClassForShowSource -a")
246
- result.should =~ /used by/
247
- result.should =~ /local monkeypatch/
248
- end
249
- end
250
-
251
- describe "when no class/module arg is given" do
252
- before do
253
- module TestHost
254
-
255
- # hello there froggy
256
- module M
257
- def d; end
258
- def e; end
259
- end
260
- end
261
- end
262
-
263
- after do
264
- Object.remove_const(:TestHost)
265
- end
266
-
267
- it 'should return doc for current module' do
268
- redirect_pry_io(InputTester.new("show-doc"), out = StringIO.new) do
269
- Pry.start(TestHost::M)
270
- end
271
-
272
- out.string.should =~ /hello there froggy/
273
- end
274
-
275
- end
276
-
277
-
278
- describe "should skip over broken modules" do
279
- before do
280
- module TestHost
281
-
282
- # hello
283
- module M
284
- binding.eval("def a; end", "dummy.rb", 1)
285
- binding.eval("def b; end", "dummy.rb", 2)
286
- binding.eval("def c; end", "dummy.rb", 3)
287
- end
288
-
289
- # goodbye
290
- module M
291
- def d; end
292
- def e; end
293
- end
294
- end
295
- end
296
-
297
- after do
298
- Object.remove_const(:TestHost)
299
- end
300
-
301
- it 'should return doc for first valid module' do
302
- redirect_pry_io(InputTester.new("show-doc TestHost::M"), out = StringIO.new) do
303
- Pry.start
304
- end
305
-
306
- out.string.should =~ /goodbye/
307
- out.string.should.not =~ /hello/
308
- end
309
-
310
- end
311
- end
312
-
313
- end
314
- end
@@ -1,50 +0,0 @@
1
- require 'helper'
2
-
3
- # we turn off the test for MRI 1.8 because our source_location hack
4
- # for C methods actually runs the methods - and since it runs ALL
5
- # methods (in an attempt to find a match) it runs 'exit' and aborts
6
- # the test, causing a failure. We should fix this in the future by
7
- # blacklisting certain methods for 1.8 MRI (such as exit, fork, and so on)
8
- unless Pry::Helpers::BaseHelpers.mri_18?
9
- MyKlass = Class.new do
10
- def hello
11
- "timothy"
12
- end
13
- def goodbye
14
- "jenny"
15
- end
16
- end
17
-
18
- describe "find-command" do
19
- describe "find matching methods by name regex (-n option)" do
20
- it "should find a method by regex" do
21
- mock_pry("find-method hell MyKlass").should =~ /MyKlass.*?hello/m
22
- end
23
-
24
- it "should NOT match a method that does not match the regex" do
25
- mock_pry("find-method hell MyKlass").should.not =~ /MyKlass.*?goodbye/m
26
- end
27
- end
28
-
29
- describe "find matching methods by content regex (-c option)" do
30
- it "should find a method by regex" do
31
- mock_pry("find-method -c timothy MyKlass").should =~ /MyKlass.*?hello/m
32
- end
33
-
34
- it "should NOT match a method that does not match the regex" do
35
- mock_pry("find-method timothy MyKlass").should.not =~ /MyKlass.*?goodbye/m
36
- end
37
- end
38
-
39
- it "should work with badly behaved constants" do
40
- MyKlass::X = Object.new
41
- def (MyKlass::X).hash
42
- raise "mooo"
43
- end
44
-
45
- mock_pry("find-method -c timothy MyKlass").should =~ /MyKlass.*?hello/m
46
- end
47
- end
48
-
49
- Object.remove_const(:MyKlass)
50
- end
@@ -1,18 +0,0 @@
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 =~ /Error/
11
- end
12
-
13
- it 'should not raise when invoked with an argument' do
14
- mock_pry('gem-list pry').should.not =~ /Error/
15
- end
16
- end
17
- end
18
-
@@ -1,57 +0,0 @@
1
- require 'helper'
2
-
3
- describe "'help' command" do
4
- before do
5
- @oldset = Pry.config.commands
6
- @set = Pry.config.commands = Pry::CommandSet.new do
7
- import Pry::DefaultCommands::Help
8
- import Pry::DefaultCommands::Ls
9
- end
10
- end
11
-
12
- after do
13
- Pry.config.commands = @oldset
14
- end
15
-
16
- it 'should display help for a specific command' do
17
- mock_pry('help ls').should =~ /Usage: ls/
18
- end
19
-
20
- it 'should display help for a regex command with a "listing"' do
21
- @set.command /bar(.*)/, "Test listing", :listing => "foo" do; end
22
- mock_pry('help foo').should =~ /Test listing/
23
- end
24
-
25
- it 'should display help for a command with a spaces in its name' do
26
- @set.command "command with spaces", "description of a command with spaces" do; end
27
- mock_pry('help "command with spaces"').should =~ /description of a command with spaces/
28
- end
29
-
30
- it 'should display help for all commands with a description' do
31
- @set.command /bar(.*)/, "Test listing", :listing => "foo" do; end
32
- @set.command "b", "description for b", :listing => "foo" do; end
33
- @set.command "c" do;end
34
- @set.command "d", "" do;end
35
-
36
- output = mock_pry('help')
37
- output.should =~ /Test listing/
38
- output.should =~ /description for b/
39
- output.should =~ /No description/
40
- end
41
-
42
- it "should sort the output of the 'help' command" do
43
- @set.command 'faa', "Fooerizes" do; end
44
- @set.command 'gaa', "Gooerizes" do; end
45
- @set.command 'maa', "Mooerizes" do; end
46
- @set.command 'baa', "Booerizes" do; end
47
-
48
- doc = mock_pry('help')
49
-
50
- order = [doc.index("baa"),
51
- doc.index("faa"),
52
- doc.index("gaa"),
53
- doc.index("maa")]
54
-
55
- order.should == order.sort
56
- end
57
- end
@@ -1,428 +0,0 @@
1
- require 'helper'
2
-
3
- describe "Pry::DefaultCommands::Input" do
4
- before do
5
- @str_output = StringIO.new
6
- end
7
-
8
- describe "amend-line" do
9
- it 'should correctly amend the last line of input when no line number specified ' do
10
- redirect_pry_io(InputTester.new("def hello", "puts :bing", "amend-line puts :blah", "show-input", "exit-all"), @str_output) do
11
- pry
12
- end
13
-
14
- @str_output.string.should =~ /\A\d+: def hello\n\d+: puts :blah/
15
- end
16
-
17
- it 'should correctly amend the specified line of input when line number given ' do
18
- redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "amend-line 1 def goodbye", "show-input", "exit-all"), @str_output) do
19
- pry
20
- end
21
-
22
- @str_output.string.should =~ /\A\d+: def goodbye\n\d+: puts :bing\n\d+: puts :bang/
23
- end
24
-
25
- it 'should correctly amend the specified line of input when line number given, 0 should behave as 1 ' do
26
- redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "amend-line 0 def goodbye", "show-input", "exit-all"), @str_output) do
27
- pry
28
- end
29
-
30
- @str_output.string.should =~ /\A\d+: def goodbye\n\d+: puts :bing\n\d+: puts :bang/
31
- end
32
-
33
- it 'should correctly amend the specified line of input when line number given (negative number)' do
34
- redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "amend-line -1 puts :bink", "show-input", "exit-all"), @str_output) do
35
- pry
36
- end
37
-
38
- @str_output.string.should =~ /\A\d+: def hello\n\d+: puts :bing\n\d+: puts :bink/
39
-
40
- @str_output = StringIO.new
41
- redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "amend-line -2 puts :bink", "show-input", "exit-all"), @str_output) do
42
- pry
43
- end
44
-
45
- @str_output.string.should =~ /\A\d+: def hello\n\d+: puts :bink\n\d+: puts :bang/
46
- end
47
-
48
- it 'should correctly amend the specified range of lines of input when range of negative numbers given (negative number)' do
49
- 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
50
- pry
51
- end
52
-
53
- @str_output.string.should =~ /\A\d+: def hello\n\d+: puts :bink\n\d+: puts :boat/
54
- end
55
-
56
- it 'should correctly amend the specified line with string interpolated text' do
57
- redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", 'amend-line puts "#{goodbye}"', "show-input", "exit-all"), @str_output) do
58
- pry
59
- end
60
-
61
- @str_output.string.should =~ /\A\d+: def hello\n\d+: puts :bing\n\d+: puts \"\#\{goodbye\}\"/
62
- end
63
-
64
- it 'should display error if nothing to amend' do
65
- redirect_pry_io(InputTester.new("amend-line", "exit-all"), @str_output) do
66
- pry
67
- end
68
-
69
- @str_output.string.should =~ /No input to amend/
70
- end
71
-
72
-
73
- it 'should correctly amend the specified range of lines' do
74
- 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
75
- pry
76
- end
77
-
78
- @str_output.string.should =~ /\A\d+: def hello\n\d+: puts :bong\n\d+: puts :heart/
79
- end
80
-
81
- it 'should correctly delete a specific line using the ! for content' do
82
- 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
83
- pry
84
- end
85
-
86
- @str_output.string.should =~ /\d+: def hello\n\d+: puts :bing\n\d+: puts :boast\n\d+: puts :heart/
87
- end
88
-
89
- it 'should correctly delete a range of lines using the ! for content' do
90
- 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
91
- pry
92
- end
93
-
94
- @str_output.string.should =~ /\d+: def hello\n\d+: puts :heart\n\Z/
95
- end
96
-
97
- it 'should correctly delete the previous line using the ! for content' do
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
- 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
107
- pry
108
- end
109
- @str_output.string.should =~ /\d+: def hello\n\d+: puts :bong\n\d+: puts :heart/
110
- end
111
-
112
- it 'should correctly insert a new line of input before a specified line using the > syntax' do
113
- redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "amend-line 2 >puts :inserted", "show-input", "exit-all"), @str_output) do
114
- pry
115
- end
116
-
117
- @str_output.string.should =~ /\d+: def hello\n\d+: puts :inserted\n\d+: puts :bing\n\d+: puts :bang/
118
- end
119
-
120
- it 'should correctly insert a new line of input before a specified line using the > syntax (should ignore second value of range)' do
121
- redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "amend-line 2..21 >puts :inserted", "show-input", "exit-all"), @str_output) do
122
- pry
123
- end
124
-
125
- @str_output.string.should =~ /\d+: def hello\n\d+: puts :inserted\n\d+: puts :bing\n\d+: puts :bang/
126
- end
127
- end
128
-
129
- describe "show-input" do
130
- it 'should correctly show the current lines in the input buffer' do
131
- redirect_pry_io(InputTester.new("def hello", "puts :bing", "show-input", "exit-all"), @str_output) do
132
- pry
133
- end
134
-
135
- @str_output.string.should =~ /\A\d+: def hello\n\d+: puts :bing/
136
- end
137
- end
138
-
139
- describe "!" do
140
- it 'should correctly clear the input buffer ' do
141
- redirect_pry_io(InputTester.new("def hello", "puts :bing", "!", "show-input", "exit-all"), @str_output) do
142
- pry
143
- end
144
-
145
- stripped_output = @str_output.string.strip!
146
- stripped_output.each_line.count.should == 1
147
- stripped_output.should =~ /Input buffer cleared!/
148
- end
149
- end
150
-
151
- describe "play" do
152
- it 'should play a string variable (with no args)' do
153
- b = binding
154
- b.eval('x = "\"hello\""')
155
- redirect_pry_io(InputTester.new("play x", "exit-all"), @str_output) do
156
- Pry.start b, :hooks => Pry::Hooks.new
157
- end
158
-
159
- @str_output.string.should =~ /hello/
160
- end
161
-
162
- it 'should play a string variable (with no args) using --lines to select what to play' do
163
- b = binding
164
- b.eval('x = "\"hello\"\n\"goodbye\"\n\"love\""')
165
- redirect_pry_io(InputTester.new("play x --lines 1", "exit-all"), @str_output) do
166
- Pry.start b, :hooks => Pry::Hooks.new
167
- end
168
-
169
- @str_output.string.should =~ /hello/
170
- @str_output.string.should.not =~ /love/
171
- @str_output.string.should.not =~ /goodbye/
172
- end
173
-
174
- it 'should play documentation with the -d switch' do
175
- o = Object.new
176
-
177
- # @v = 10
178
- # @y = 20
179
- def o.test_method
180
- :test_method_content
181
- end
182
-
183
- redirect_pry_io(InputTester.new('play -d test_method', "exit-all")) do
184
- o.pry
185
- end
186
-
187
- o.instance_variable_get(:@v).should == 10
188
- o.instance_variable_get(:@y).should == 20
189
- end
190
-
191
- it 'should play documentation with the -d switch (restricted by --lines)' do
192
- o = Object.new
193
-
194
- # @x = 0
195
- # @v = 10
196
- # @y = 20
197
- # @z = 30
198
- def o.test_method
199
- :test_method_content
200
- end
201
-
202
- redirect_pry_io(InputTester.new('play -d test_method --lines 2..3', "exit-all")) do
203
- o.pry
204
- end
205
-
206
- o.instance_variable_get(:@x).should == nil
207
- o.instance_variable_get(:@z).should == nil
208
- o.instance_variable_get(:@v).should == 10
209
- o.instance_variable_get(:@y).should == 20
210
- end
211
-
212
-
213
- it 'should play a method with the -m switch (a single line)' do
214
- o = Object.new
215
- def o.test_method
216
- :test_method_content
217
- end
218
-
219
- redirect_pry_io(InputTester.new('play -m test_method --lines 2', "exit-all"), @str_output) do
220
- o.pry
221
- end
222
-
223
- @str_output.string.should =~ /:test_method_content/
224
- end
225
-
226
- it 'should APPEND to the input buffer when playing a line with play -m, not replace it' do
227
- o = Object.new
228
- def o.test_method
229
- :test_method_content
230
- end
231
-
232
- redirect_pry_io(InputTester.new('def another_test_method', 'play -m test_method --lines 2', 'show-input', 'exit-all'), @str_output) do
233
- o.pry
234
- end
235
-
236
- @str_output.string.should =~ /def another_test_method/
237
- @str_output.string.should =~ /:test_method_content/
238
- end
239
-
240
-
241
- it 'should play a method with the -m switch (multiple line)' do
242
- o = Object.new
243
-
244
- def o.test_method
245
- @var0 = 10
246
- @var1 = 20
247
- @var2 = 30
248
- @var3 = 40
249
- end
250
-
251
- redirect_pry_io(InputTester.new('play -m test_method --lines 3..4', "exit-all"), @str_output) do
252
- o.pry
253
- end
254
-
255
- o.instance_variable_get(:@var0).should == nil
256
- o.instance_variable_get(:@var1).should == 20
257
- o.instance_variable_get(:@var2).should == 30
258
- o.instance_variable_get(:@var3).should == nil
259
- @str_output.string.should =~ /30/
260
- @str_output.string.should.not =~ /20/
261
- end
262
- end
263
-
264
- describe "hist" do
265
- before do
266
- Pry.history.clear
267
- @hist = Pry.history
268
- end
269
-
270
- it 'should display the correct history' do
271
- @hist.push "hello"
272
- @hist.push "world"
273
- redirect_pry_io(InputTester.new("hist", "exit-all"), @str_output) do
274
- pry
275
- end
276
-
277
- @str_output.string.should =~ /hello\n.*world/
278
- end
279
-
280
- it 'should replay history correctly (single item)' do
281
- o = Object.new
282
- @hist.push "@x = 10"
283
- @hist.push "@y = 20"
284
- @hist.push "@z = 30"
285
- redirect_pry_io(InputTester.new("hist --replay -1", "exit-all")) do
286
- o.pry
287
- end
288
- o.instance_variable_get(:@x).should == nil
289
- o.instance_variable_get(:@y).should == nil
290
- o.instance_variable_get(:@z).should == 30
291
- end
292
-
293
- it 'should replay a range of history correctly (range of items)' do
294
- o = Object.new
295
- @hist.push "@x = 10"
296
- @hist.push "@y = 20"
297
- redirect_pry_io(InputTester.new("hist --replay 0..2", "exit-all")) do
298
- o.pry
299
- end
300
- o.instance_variable_get(:@x).should == 10
301
- o.instance_variable_get(:@y).should == 20
302
- end
303
-
304
- it 'should grep for correct lines in history' do
305
- @hist.push "abby"
306
- @hist.push "box"
307
- @hist.push "button"
308
- @hist.push "pepper"
309
- @hist.push "orange"
310
- @hist.push "grape"
311
- @hist.push "def blah 1"
312
- @hist.push "def boink 2"
313
- @hist.push "place holder"
314
-
315
- redirect_pry_io(InputTester.new("hist --grep o", "exit-all"), @str_output) do
316
- pry
317
- end
318
- @str_output.string.should =~ /\d:.*?box\n\d:.*?button\n\d:.*?orange/
319
-
320
- # test more than one word in a regex match (def blah)
321
- @str_output = StringIO.new
322
- redirect_pry_io(InputTester.new("hist --grep def blah", "exit-all"), @str_output) do
323
- pry
324
- end
325
- @str_output.string.should =~ /def blah 1/
326
-
327
- @str_output = StringIO.new
328
- # test more than one word with leading white space in a regex match (def boink)
329
- redirect_pry_io(InputTester.new("hist --grep def boink", "exit-all"), @str_output) do
330
- pry
331
- end
332
- @str_output.string.should =~ /def boink 2/
333
- end
334
-
335
- it 'should return last N lines in history with --tail switch' do
336
- ("a".."z").each do |v|
337
- @hist.push v
338
- end
339
-
340
- redirect_pry_io(InputTester.new("hist --tail 3", "exit-all"), @str_output) do
341
- pry
342
- end
343
-
344
- @str_output.string.each_line.count.should == 3
345
- @str_output.string.should =~ /x\n\d+:.*y\n\d+:.*z/
346
- end
347
-
348
- it 'should apply --tail after --grep' do
349
- @hist.push "print 1"
350
- @hist.push "print 2"
351
- @hist.push "puts 3"
352
- @hist.push "print 4"
353
- @hist.push "puts 5"
354
-
355
- str_output = StringIO.new
356
- redirect_pry_io(InputTester.new("hist --tail 2 --grep print", "exit-all"), @str_output) do
357
- pry
358
- end
359
-
360
- @str_output.string.each_line.count.should == 2
361
- @str_output.string.should =~ /\d:.*?print 2\n\d:.*?print 4/
362
- end
363
-
364
- it 'should apply --head after --grep' do
365
- @hist.push "puts 1"
366
- @hist.push "print 2"
367
- @hist.push "puts 3"
368
- @hist.push "print 4"
369
- @hist.push "print 5"
370
-
371
- redirect_pry_io(InputTester.new("hist --head 2 --grep print", "exit-all"), @str_output) do
372
- pry
373
- end
374
-
375
- @str_output.string.each_line.count.should == 2
376
- @str_output.string.should =~ /\d:.*?print 2\n\d:.*?print 4/
377
- end
378
-
379
- # strangeness in this test is due to bug in Readline::HISTORY not
380
- # always registering first line of input
381
- it 'should return first N lines in history with --head switch' do
382
- ("a".."z").each do |v|
383
- @hist.push v
384
- end
385
-
386
- redirect_pry_io(InputTester.new("hist --head 4", "exit-all"), @str_output) do
387
- pry
388
- end
389
-
390
- @str_output.string.each_line.count.should == 4
391
- @str_output.string.should =~ /a\n\d+:.*b\n\d+:.*c/
392
- end
393
-
394
- # strangeness in this test is due to bug in Readline::HISTORY not
395
- # always registering first line of input
396
- it 'should show lines between lines A and B with the --show switch' do
397
- ("a".."z").each do |v|
398
- @hist.push v
399
- end
400
-
401
- redirect_pry_io(InputTester.new("hist --show 1..4", "exit-all"), @str_output) do
402
- pry
403
- end
404
-
405
- @str_output.string.each_line.count.should == 4
406
- @str_output.string.should =~ /b\n\d+:.*c\n\d+:.*d/
407
- end
408
-
409
- it "should not contain duplicated lines" do
410
- redirect_pry_io(InputTester.new("3", "_ += 1", "_ += 1", "hist", "exit-all"), @str_output) do
411
- pry
412
- end
413
-
414
- @str_output.string.each_line.grep(/_ \+= 1/).count.should == 1
415
- end
416
-
417
- it "should not contain duplicated lines" do
418
- redirect_pry_io(InputTester.new(":place_holder", "2 + 2", "", "", "3 + 3", "hist", "exit-all"), @str_output) do
419
- pry
420
- end
421
-
422
- a = @str_output.string.each_line.to_a.index{|line| line.include?("2 + 2") }
423
- b = @str_output.string.each_line.to_a.index{|line| line.include?("3 + 3") }
424
-
425
- (a + 1).should == b
426
- end
427
- end
428
- end