pry 0.9.10pre1-i386-mingw32 → 0.9.11-i386-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (194) hide show
  1. data/.travis.yml +3 -1
  2. data/CHANGELOG +63 -2
  3. data/CONTRIBUTORS +43 -25
  4. data/Gemfile +7 -0
  5. data/Guardfile +62 -0
  6. data/README.markdown +4 -4
  7. data/Rakefile +34 -35
  8. data/lib/pry.rb +107 -54
  9. data/lib/pry/cli.rb +34 -11
  10. data/lib/pry/code.rb +165 -182
  11. data/lib/pry/code/code_range.rb +70 -0
  12. data/lib/pry/code/loc.rb +92 -0
  13. data/lib/pry/code_object.rb +153 -0
  14. data/lib/pry/command.rb +160 -22
  15. data/lib/pry/command_set.rb +37 -26
  16. data/lib/pry/commands.rb +4 -27
  17. data/lib/pry/commands/amend_line.rb +99 -0
  18. data/lib/pry/commands/bang.rb +20 -0
  19. data/lib/pry/commands/bang_pry.rb +17 -0
  20. data/lib/pry/commands/cat.rb +53 -0
  21. data/lib/pry/commands/cat/abstract_formatter.rb +27 -0
  22. data/lib/pry/commands/cat/exception_formatter.rb +78 -0
  23. data/lib/pry/commands/cat/file_formatter.rb +84 -0
  24. data/lib/pry/commands/cat/input_expression_formatter.rb +43 -0
  25. data/lib/pry/commands/cd.rb +30 -0
  26. data/lib/pry/commands/code_collector.rb +165 -0
  27. data/lib/pry/commands/deprecated_commands.rb +2 -0
  28. data/lib/pry/commands/disable_pry.rb +27 -0
  29. data/lib/pry/commands/easter_eggs.rb +112 -0
  30. data/lib/pry/commands/edit.rb +206 -0
  31. data/lib/pry/commands/edit/exception_patcher.rb +25 -0
  32. data/lib/pry/commands/edit/file_and_line_locator.rb +38 -0
  33. data/lib/pry/commands/edit/method_patcher.rb +122 -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 +24 -0
  37. data/lib/pry/commands/find_method.rb +199 -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 +29 -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 +95 -0
  44. data/lib/pry/commands/help.rb +164 -0
  45. data/lib/pry/commands/hist.rb +161 -0
  46. data/lib/pry/commands/import_set.rb +22 -0
  47. data/lib/pry/commands/install_command.rb +51 -0
  48. data/lib/pry/commands/jump_to.rb +29 -0
  49. data/lib/pry/commands/ls.rb +339 -0
  50. data/lib/pry/commands/nesting.rb +25 -0
  51. data/lib/pry/commands/play.rb +69 -0
  52. data/lib/pry/commands/pry_backtrace.rb +26 -0
  53. data/lib/pry/commands/pry_version.rb +17 -0
  54. data/lib/pry/commands/raise_up.rb +32 -0
  55. data/lib/pry/commands/reload_code.rb +39 -0
  56. data/lib/pry/commands/reset.rb +18 -0
  57. data/lib/pry/commands/ri.rb +56 -0
  58. data/lib/pry/commands/save_file.rb +61 -0
  59. data/lib/pry/commands/shell_command.rb +43 -0
  60. data/lib/pry/commands/shell_mode.rb +27 -0
  61. data/lib/pry/commands/show_doc.rb +78 -0
  62. data/lib/pry/commands/show_info.rb +139 -0
  63. data/lib/pry/commands/show_input.rb +17 -0
  64. data/lib/pry/commands/show_source.rb +37 -0
  65. data/lib/pry/commands/simple_prompt.rb +22 -0
  66. data/lib/pry/commands/stat.rb +40 -0
  67. data/lib/pry/commands/switch_to.rb +23 -0
  68. data/lib/pry/commands/toggle_color.rb +20 -0
  69. data/lib/pry/commands/whereami.rb +114 -0
  70. data/lib/pry/commands/wtf.rb +57 -0
  71. data/lib/pry/completion.rb +120 -46
  72. data/lib/pry/config.rb +11 -0
  73. data/lib/pry/core_extensions.rb +30 -19
  74. data/lib/pry/editor.rb +129 -0
  75. data/lib/pry/helpers.rb +1 -0
  76. data/lib/pry/helpers/base_helpers.rb +89 -119
  77. data/lib/pry/helpers/command_helpers.rb +7 -122
  78. data/lib/pry/helpers/table.rb +100 -0
  79. data/lib/pry/helpers/text.rb +4 -4
  80. data/lib/pry/history_array.rb +5 -0
  81. data/lib/pry/hooks.rb +1 -3
  82. data/lib/pry/indent.rb +104 -30
  83. data/lib/pry/method.rb +66 -22
  84. data/lib/pry/module_candidate.rb +26 -15
  85. data/lib/pry/pager.rb +70 -0
  86. data/lib/pry/plugins.rb +1 -2
  87. data/lib/pry/pry_class.rb +63 -22
  88. data/lib/pry/pry_instance.rb +58 -37
  89. data/lib/pry/rubygem.rb +74 -0
  90. data/lib/pry/terminal_info.rb +43 -0
  91. data/lib/pry/test/helper.rb +185 -0
  92. data/lib/pry/version.rb +1 -1
  93. data/lib/pry/wrapped_module.rb +58 -24
  94. data/pry.gemspec +21 -37
  95. data/{test/test_cli.rb → spec/cli_spec.rb} +0 -0
  96. data/spec/code_object_spec.rb +277 -0
  97. data/{test/test_code.rb → spec/code_spec.rb} +19 -1
  98. data/{test/test_command_helpers.rb → spec/command_helpers_spec.rb} +0 -0
  99. data/{test/test_command_integration.rb → spec/command_integration_spec.rb} +38 -46
  100. data/{test/test_command_set.rb → spec/command_set_spec.rb} +18 -1
  101. data/{test/test_command.rb → spec/command_spec.rb} +250 -149
  102. data/spec/commands/amend_line_spec.rb +247 -0
  103. data/spec/commands/bang_spec.rb +19 -0
  104. data/spec/commands/cat_spec.rb +164 -0
  105. data/spec/commands/cd_spec.rb +250 -0
  106. data/spec/commands/disable_pry_spec.rb +25 -0
  107. data/spec/commands/edit_spec.rb +727 -0
  108. data/spec/commands/exit_all_spec.rb +34 -0
  109. data/spec/commands/exit_program_spec.rb +19 -0
  110. data/spec/commands/exit_spec.rb +34 -0
  111. data/{test/test_default_commands/test_find_method.rb → spec/commands/find_method_spec.rb} +27 -7
  112. data/spec/commands/gem_list_spec.rb +26 -0
  113. data/spec/commands/gist_spec.rb +75 -0
  114. data/{test/test_default_commands/test_help.rb → spec/commands/help_spec.rb} +8 -9
  115. data/spec/commands/hist_spec.rb +181 -0
  116. data/spec/commands/jump_to_spec.rb +15 -0
  117. data/spec/commands/ls_spec.rb +177 -0
  118. data/spec/commands/play_spec.rb +140 -0
  119. data/spec/commands/raise_up_spec.rb +56 -0
  120. data/spec/commands/save_file_spec.rb +177 -0
  121. data/spec/commands/show_doc_spec.rb +378 -0
  122. data/spec/commands/show_input_spec.rb +17 -0
  123. data/spec/commands/show_source_spec.rb +597 -0
  124. data/spec/commands/whereami_spec.rb +154 -0
  125. data/spec/completion_spec.rb +233 -0
  126. data/spec/control_d_handler_spec.rb +58 -0
  127. data/spec/editor_spec.rb +79 -0
  128. data/{test/test_exception_whitelist.rb → spec/exception_whitelist_spec.rb} +0 -0
  129. data/{test → spec/fixtures}/candidate_helper1.rb +0 -0
  130. data/{test → spec/fixtures}/candidate_helper2.rb +0 -0
  131. data/{test/test_default_commands → spec/fixtures}/example.erb +0 -0
  132. data/spec/fixtures/example_nesting.rb +33 -0
  133. data/spec/fixtures/show_source_doc_examples.rb +15 -0
  134. data/{test → spec/fixtures}/testrc +0 -0
  135. data/{test → spec/fixtures}/testrcbad +0 -0
  136. data/spec/helper.rb +34 -0
  137. data/spec/helpers/bacon.rb +86 -0
  138. data/spec/helpers/mock_pry.rb +43 -0
  139. data/spec/helpers/table_spec.rb +83 -0
  140. data/{test/test_history_array.rb → spec/history_array_spec.rb} +21 -19
  141. data/{test/test_hooks.rb → spec/hooks_spec.rb} +0 -0
  142. data/{test/test_indent.rb → spec/indent_spec.rb} +24 -0
  143. data/{test/test_input_stack.rb → spec/input_stack_spec.rb} +4 -0
  144. data/{test/test_method.rb → spec/method_spec.rb} +65 -1
  145. data/{test/test_prompt.rb → spec/prompt_spec.rb} +0 -0
  146. data/{test/test_pry_defaults.rb → spec/pry_defaults_spec.rb} +14 -14
  147. data/{test/test_pry_history.rb → spec/pry_history_spec.rb} +15 -0
  148. data/spec/pry_output_spec.rb +95 -0
  149. data/{test/test_pry.rb → spec/pry_spec.rb} +74 -32
  150. data/{test/test_sticky_locals.rb → spec/sticky_locals_spec.rb} +27 -25
  151. data/{test/test_syntax_checking.rb → spec/syntax_checking_spec.rb} +17 -1
  152. data/{test/test_wrapped_module.rb → spec/wrapped_module_spec.rb} +92 -5
  153. metadata +239 -115
  154. data/examples/example_basic.rb +0 -15
  155. data/examples/example_command_override.rb +0 -32
  156. data/examples/example_commands.rb +0 -36
  157. data/examples/example_hooks.rb +0 -9
  158. data/examples/example_image_edit.rb +0 -67
  159. data/examples/example_input.rb +0 -7
  160. data/examples/example_input2.rb +0 -29
  161. data/examples/example_output.rb +0 -11
  162. data/examples/example_print.rb +0 -6
  163. data/examples/example_prompt.rb +0 -9
  164. data/examples/helper.rb +0 -6
  165. data/lib/pry/default_commands/cd.rb +0 -81
  166. data/lib/pry/default_commands/commands.rb +0 -62
  167. data/lib/pry/default_commands/context.rb +0 -98
  168. data/lib/pry/default_commands/easter_eggs.rb +0 -95
  169. data/lib/pry/default_commands/editing.rb +0 -420
  170. data/lib/pry/default_commands/find_method.rb +0 -169
  171. data/lib/pry/default_commands/gems.rb +0 -84
  172. data/lib/pry/default_commands/gist.rb +0 -187
  173. data/lib/pry/default_commands/help.rb +0 -127
  174. data/lib/pry/default_commands/hist.rb +0 -120
  175. data/lib/pry/default_commands/input_and_output.rb +0 -306
  176. data/lib/pry/default_commands/introspection.rb +0 -410
  177. data/lib/pry/default_commands/ls.rb +0 -272
  178. data/lib/pry/default_commands/misc.rb +0 -38
  179. data/lib/pry/default_commands/navigating_pry.rb +0 -110
  180. data/lib/pry/default_commands/whereami.rb +0 -92
  181. data/lib/pry/extended_commands/experimental.rb +0 -7
  182. data/test/helper.rb +0 -223
  183. data/test/test_completion.rb +0 -62
  184. data/test/test_control_d_handler.rb +0 -45
  185. data/test/test_default_commands/test_cd.rb +0 -321
  186. data/test/test_default_commands/test_context.rb +0 -288
  187. data/test/test_default_commands/test_documentation.rb +0 -315
  188. data/test/test_default_commands/test_gems.rb +0 -18
  189. data/test/test_default_commands/test_input.rb +0 -428
  190. data/test/test_default_commands/test_introspection.rb +0 -511
  191. data/test/test_default_commands/test_ls.rb +0 -151
  192. data/test/test_default_commands/test_shell.rb +0 -343
  193. data/test/test_default_commands/test_show_source.rb +0 -432
  194. data/test/test_pry_output.rb +0 -41
@@ -1,288 +0,0 @@
1
- require 'helper'
2
-
3
- describe "Pry::DefaultCommands::Context" do
4
-
5
- before do
6
- @self = "Pad.self = self"
7
- @inner = "Pad.inner = self"
8
- @outer = "Pad.outer = self"
9
- end
10
-
11
- after do
12
- Pad.clear
13
- end
14
-
15
- describe "exit-all" do
16
- it 'should break out of the repl loop of Pry instance and return nil' do
17
- redirect_pry_io(InputTester.new("exit-all")) do
18
- Pry.new.repl(0).should == nil
19
- end
20
- end
21
-
22
- it 'should break out of the repl loop of Pry instance wth a user specified value' do
23
- redirect_pry_io(InputTester.new("exit-all 'message'")) do
24
- Pry.new.repl(0).should == 'message'
25
- end
26
- end
27
-
28
- it 'should break of the repl loop even if multiple bindings still on stack' do
29
- ins = nil
30
- redirect_pry_io(InputTester.new("cd 1", "cd 2", "exit-all 'message'")) do
31
- ins = Pry.new.tap { |v| v.repl(0).should == 'message' }
32
- end
33
- end
34
-
35
- it 'binding_stack should be empty after breaking out of the repl loop' do
36
- ins = nil
37
- redirect_pry_io(InputTester.new("cd 1", "cd 2", "exit-all")) do
38
- ins = Pry.new.tap { |v| v.repl(0) }
39
- end
40
-
41
- ins.binding_stack.empty?.should == true
42
- end
43
- end
44
-
45
- describe "whereami" do
46
- it 'should work with methods that have been undefined' do
47
- class Cor
48
- def blimey!
49
- Cor.send :undef_method, :blimey!
50
- # using [.] so the regex doesn't match itself
51
- mock_pry(binding, 'whereami').should =~ /self[.]blimey!/
52
- end
53
- end
54
-
55
- Cor.new.blimey!
56
- Object.remove_const(:Cor)
57
- end
58
-
59
- it 'should work in objects with no method methods' do
60
- class Cor
61
- def blimey!
62
- mock_pry(binding, 'whereami').should =~ /Cor[#]blimey!/
63
- end
64
-
65
- def method; "moo"; end
66
- end
67
- Cor.new.blimey!
68
- Object.remove_const(:Cor)
69
- end
70
-
71
- it 'should properly set _file_, _line_ and _dir_' do
72
- class Cor
73
- def blimey!
74
- mock_pry(binding, 'whereami', '_file_') \
75
- .should =~ /#{File.expand_path(__FILE__)}/
76
- end
77
- end
78
-
79
- Cor.new.blimey!
80
- Object.remove_const(:Cor)
81
- end
82
-
83
- it 'should show description and correct code when __LINE__ and __FILE__ are outside @method.source_location' do
84
- class Cor
85
- def blimey!
86
- eval <<-END, binding, "test/test_default_commands/example.erb", 1
87
- mock_pry(binding, 'whereami')
88
- END
89
- end
90
- end
91
-
92
- Cor.instance_method(:blimey!).source.should =~ /mock_pry/
93
-
94
- Cor.new.blimey!.should =~ /Cor#blimey!.*Look at me/m
95
- Object.remove_const(:Cor)
96
- end
97
-
98
- it 'should show description and correct code when @method.source_location would raise an error' do
99
- class Cor
100
- eval <<-END, binding, "test/test_default_commands/example.erb", 1
101
- def blimey!
102
- mock_pry(binding, 'whereami')
103
- end
104
- END
105
- end
106
-
107
- lambda{
108
- Cor.instance_method(:blimey!).source
109
- }.should.raise(MethodSource::SourceNotFoundError)
110
-
111
- Cor.new.blimey!.should =~ /Cor#blimey!.*Look at me/m
112
- Object.remove_const(:Cor)
113
-
114
- end
115
-
116
- it 'should display a description and and error if reading the file goes wrong' do
117
- class Cor
118
- def blimey!
119
- eval <<-END, binding, "not.found.file.erb", 7
120
- mock_pry(binding, 'whereami')
121
- END
122
- end
123
- end
124
-
125
- Cor.new.blimey!.should =~ /From: not.found.file.erb @ line 7 Cor#blimey!:\n\nError: Cannot open "not.found.file.erb" for reading./m
126
- Object.remove_const(:Cor)
127
- end
128
-
129
- it 'should show code window (not just method source) if parameter passed to whereami' do
130
- class Cor
131
- def blimey!
132
- mock_pry(binding, 'whereami 3').should =~ /class Cor/
133
- end
134
- end
135
- Cor.new.blimey!
136
- Object.remove_const(:Cor)
137
- end
138
-
139
- it 'should use Pry.config.default_window_size for window size when outside a method context' do
140
- old_size, Pry.config.default_window_size = Pry.config.default_window_size, 1
141
- :litella
142
- :pig
143
- out = mock_pry(binding, 'whereami')
144
- :punk
145
- :sanders
146
-
147
- out.should.not =~ /:litella/
148
- out.should =~ /:pig/
149
- out.should =~ /:punk/
150
- out.should.not =~ /:sanders/
151
-
152
- Pry.config.default_window_size = old_size
153
- end
154
-
155
- it "should work at the top level" do
156
- mock_pry(Pry.toplevel_binding, 'whereami').should =~ /At the top level/
157
- end
158
-
159
- it "should work inside a class" do
160
- mock_pry(Pry.binding_for(Pry), 'whereami').should =~ /Inside Pry/
161
- end
162
-
163
- it "should work inside an object" do
164
- mock_pry(Pry.binding_for(Object.new), 'whereami').should =~ /Inside #<Object/
165
- end
166
- end
167
-
168
- describe "exit" do
169
- it 'should pop a binding with exit' do
170
- redirect_pry_io(InputTester.new("cd :inner", @inner, "exit",
171
- @outer, "exit-all")) do
172
- Pry.start(:outer)
173
- end
174
-
175
- Pad.inner.should == :inner
176
- Pad.outer.should == :outer
177
- end
178
-
179
- it 'should break out of the repl loop of Pry instance when binding_stack has only one binding with exit' do
180
- Pry.start(0, :input => StringIO.new("exit")).should == nil
181
- end
182
-
183
- it 'should break out of the repl loop of Pry instance when binding_stack has only one binding with exit, and return user-given value' do
184
- Pry.start(0, :input => StringIO.new("exit :john")).should == :john
185
- end
186
-
187
- it 'should break out the repl loop of Pry instance even after an exception in user-given value' do
188
- redirect_pry_io(InputTester.new("exit = 42", "exit")) do
189
- ins = Pry.new.tap { |v| v.repl(0).should == nil }
190
- end
191
- end
192
- end
193
-
194
- describe "jump-to" do
195
- before do
196
- @str_output = StringIO.new
197
- end
198
-
199
- it 'should jump to the proper binding index in the stack' do
200
- redirect_pry_io(InputTester.new("cd 1", "cd 2", "jump-to 1", @self, "exit-all")) do
201
- Pry.start(0)
202
- end
203
-
204
- Pad.self.should == 1
205
- end
206
-
207
- it 'should print error when trying to jump to a non-existent binding index' do
208
- redirect_pry_io(InputTester.new("cd 1", "cd 2", "jump-to 100", "exit-all"), @str_output) do
209
- Pry.start(0)
210
- end
211
-
212
- @str_output.string.should =~ /Invalid nest level/
213
- end
214
-
215
- it 'should print error when trying to jump to the same binding index' do
216
- redirect_pry_io(InputTester.new("cd 1", "cd 2", "jump-to 2", "exit-all"), @str_output) do
217
- Pry.new.repl(0)
218
- end
219
-
220
- @str_output.string.should =~ /Already/
221
- end
222
- end
223
-
224
- describe "exit-program" do
225
- it 'should raise SystemExit' do
226
- redirect_pry_io(InputTester.new("exit-program")) do
227
- lambda { Pry.new.repl(0).should == 0 }.should.raise SystemExit
228
- end
229
- end
230
-
231
- it 'should exit the program with the provided value' do
232
- redirect_pry_io(InputTester.new("exit-program 66")) do
233
- begin
234
- Pry.new.repl(0)
235
- rescue SystemExit => e
236
- e.status.should == 66
237
- end
238
- end
239
- end
240
- end
241
-
242
- describe "raise-up" do
243
- it "should raise the exception with raise-up" do
244
- redirect_pry_io(InputTester.new("raise NoMethodError", "raise-up NoMethodError")) do
245
- lambda { Pry.new.repl(0) }.should.raise NoMethodError
246
- end
247
- end
248
-
249
- it "should raise an unamed exception with raise-up" do
250
- redirect_pry_io(InputTester.new("raise 'stop'","raise-up 'noreally'")) do
251
- lambda { Pry.new.repl(0) }.should.raise RuntimeError, "noreally"
252
- end
253
- end
254
-
255
- it "should eat the exception at the last new pry instance on raise-up" do
256
- redirect_pry_io(InputTester.new(":inner.pry", "raise NoMethodError", @inner,
257
- "raise-up NoMethodError", @outer, "exit-all")) do
258
- Pry.start(:outer)
259
- end
260
-
261
- Pad.inner.should == :inner
262
- Pad.outer.should == :outer
263
- end
264
-
265
- it "should raise the most recently raised exception" do
266
- lambda { mock_pry("raise NameError, 'homographery'","raise-up") }.should.raise NameError, 'homographery'
267
- end
268
-
269
- it "should allow you to cd up and (eventually) out" do
270
- redirect_pry_io(InputTester.new("cd :inner", "raise NoMethodError", @inner,
271
- "deep = :deep", "cd deep","Pad.deep = self",
272
- "raise-up NoMethodError", "raise-up", @outer,
273
- "raise-up", "exit-all")) do
274
- lambda { Pry.start(:outer) }.should.raise NoMethodError
275
- end
276
-
277
- Pad.deep.should == :deep
278
- Pad.inner.should == :inner
279
- Pad.outer.should == :outer
280
- end
281
- end
282
-
283
- describe "raise-up!" do
284
- it "should jump immediately out of nested context's" do
285
- lambda { mock_pry("cd 1", "cd 2", "cd 3", "raise-up! 'fancy that...'") }.should.raise RuntimeError, 'fancy that...'
286
- end
287
- end
288
- end
@@ -1,315 +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
- @o = Object.new
9
- end
10
-
11
- it 'should output a method\'s documentation' do
12
- redirect_pry_io(InputTester.new("show-doc sample_method", "exit-all"), @str_output) do
13
- pry
14
- end
15
-
16
- @str_output.string.should =~ /sample doc/
17
- end
18
-
19
- it 'should output a method\'s documentation with line numbers' do
20
- redirect_pry_io(InputTester.new("show-doc sample_method -l", "exit-all"), @str_output) do
21
- pry
22
- end
23
-
24
- @str_output.string.should =~ /\d: sample doc/
25
- end
26
-
27
- it 'should output a method\'s documentation with line numbers (base one)' do
28
- redirect_pry_io(InputTester.new("show-doc sample_method -b", "exit-all"), @str_output) do
29
- pry
30
- end
31
-
32
- @str_output.string.should =~ /1: sample doc/
33
- end
34
-
35
- it 'should output a method\'s documentation if inside method without needing to use method name' do
36
- Pad.str_output = @str_output
37
-
38
- # sample comment
39
- def @o.sample
40
- redirect_pry_io(InputTester.new("show-doc", "exit-all"), Pad.str_output) do
41
- binding.pry
42
- end
43
- end
44
- @o.sample
45
-
46
- Pad.str_output.string.should =~ /sample comment/
47
- end
48
-
49
- it "should be able to find super methods" do
50
-
51
- c = Class.new{
52
- # classy initialize!
53
- def initialize(*args); end
54
- }
55
-
56
- d = Class.new(c){
57
- # grungy initialize??
58
- def initialize(*args, &block); end
59
- }
60
-
61
- o = d.new
62
-
63
- # instancey initialize!
64
- def o.initialize; end
65
-
66
- mock_pry(binding, "show-doc o.initialize").should =~ /instancey initialize/
67
- mock_pry(binding, "show-doc --super o.initialize").should =~ /grungy initialize/
68
- mock_pry(binding, "show-doc o.initialize -ss").should =~ /classy initialize/
69
- mock_pry(binding, "show-doc --super o.initialize -ss").should == mock_pry("show-doc Object#initialize")
70
- end
71
- end
72
-
73
- describe "rdoc highlighting" do
74
- it "should syntax highlight code in rdoc" do
75
- c = Class.new{
76
- # This can initialize your class:
77
- #
78
- # a = c.new :foo
79
- #
80
- # @param foo
81
- def initialize(foo); end
82
- }
83
-
84
- begin
85
- mock_pry(binding, "show-doc c#initialize").should =~ /c.new :foo/
86
- Pry.config.color = true
87
- # I don't want the test to rely on which colour codes are there, just to
88
- # assert that "something" is being colourized.
89
- mock_pry(binding, "show-doc c#initialize").should.not =~ /c.new :foo/
90
- ensure
91
- Pry.config.color = false
92
- end
93
- end
94
-
95
- it "should syntax highlight `code` in rdoc" do
96
- c = Class.new{
97
- # After initializing your class with `c.new(:foo)`, go have fun!
98
- #
99
- # @param foo
100
- def initialize(foo); end
101
- }
102
-
103
- begin
104
- mock_pry(binding, "show-doc c#initialize").should =~ /c.new\(:foo\)/
105
- Pry.config.color = true
106
- # I don't want the test to rely on which colour codes are there, just to
107
- # assert that "something" is being colourized.
108
- mock_pry(binding, "show-doc c#initialize").should.not =~ /c.new\(:foo\)/
109
- ensure
110
- Pry.config.color = false
111
- end
112
-
113
- end
114
-
115
- it "should not syntax highlight `` inside code" do
116
- c = Class.new{
117
- # Convert aligned output (from many shell commands) into nested arrays:
118
- #
119
- # a = decolumnize `ls -l $HOME`
120
- #
121
- # @param output
122
- def decolumnize(output); end
123
- }
124
-
125
- begin
126
- Pry.config.color = true
127
- mock_pry(binding, "show-doc c#decolumnize").should =~ /ls -l \$HOME/
128
- mock_pry(binding, "show-doc c#decolumnize").should.not =~ /`ls -l \$HOME`/
129
- ensure
130
- Pry.config.color = false
131
- end
132
- end
133
- end
134
-
135
- describe "on modules" do
136
- before do
137
- # god this is boring1
138
- class ShowSourceTestClass
139
- def alpha
140
- end
141
- end
142
-
143
- # god this is boring2
144
- module ShowSourceTestModule
145
- def alpha
146
- end
147
- end
148
-
149
- # god this is boring3
150
- ShowSourceTestClassWeirdSyntax = Class.new do
151
- def beta
152
- end
153
- end
154
-
155
- # god this is boring4
156
- ShowSourceTestModuleWeirdSyntax = Module.new do
157
- def beta
158
- end
159
- end
160
- end
161
-
162
- after do
163
- Object.remove_const :ShowSourceTestClass
164
- Object.remove_const :ShowSourceTestClassWeirdSyntax
165
- Object.remove_const :ShowSourceTestModule
166
- Object.remove_const :ShowSourceTestModuleWeirdSyntax
167
- end
168
-
169
- describe "basic functionality, should show docs for top-level module definitions" do
170
- it 'should show docs for a class' do
171
- mock_pry("show-doc ShowSourceTestClass").should =~ /god this is boring1/
172
- end
173
-
174
- it 'should show docs for a module' do
175
- mock_pry("show-doc ShowSourceTestModule").should =~ /god this is boring2/
176
- end
177
-
178
- it 'should show docs for a class when Const = Class.new syntax is used' do
179
- mock_pry("show-doc ShowSourceTestClassWeirdSyntax").should =~ /god this is boring3/
180
- end
181
-
182
- it 'should show docs for a module when Const = Module.new syntax is used' do
183
- mock_pry("show-doc ShowSourceTestModuleWeirdSyntax").should =~ /god this is boring4/
184
- end
185
- end
186
-
187
- if !Pry::Helpers::BaseHelpers.mri_18?
188
- describe "in REPL" do
189
- it 'should find class defined in repl' do
190
- mock_pry("# hello tobina", "class TobinaMyDog", "def woof", "end", "end", "show-doc TobinaMyDog").should =~ /hello tobina/
191
- Object.remove_const :TobinaMyDog
192
- end
193
- end
194
- end
195
-
196
- it 'should lookup module name with respect to current context' do
197
- constant_scope(:AlphaClass, :BetaClass) do
198
-
199
- # top-level beta
200
- class BetaClass
201
- def alpha
202
- end
203
- end
204
-
205
- class AlphaClass
206
-
207
- # nested beta
208
- class BetaClass
209
- def beta
210
- end
211
- end
212
- end
213
-
214
- redirect_pry_io(InputTester.new("show-doc BetaClass", "exit-all"), outp=StringIO.new) do
215
- AlphaClass.pry
216
- end
217
-
218
- outp.string.should =~ /nested beta/
219
- end
220
- end
221
-
222
- it 'should lookup nested modules' do
223
- constant_scope(:AlphaClass) do
224
- class AlphaClass
225
-
226
- # nested beta
227
- class BetaClass
228
- def beta
229
- end
230
- end
231
- end
232
-
233
- mock_pry("show-doc AlphaClass::BetaClass").should =~ /nested beta/
234
- end
235
- end
236
-
237
- describe "show-doc -a" do
238
- it 'should show the docs for all monkeypatches defined in different files' do
239
-
240
- # local monkeypatch
241
- class TestClassForShowSource
242
- def beta
243
- end
244
- end
245
-
246
- result = mock_pry("show-doc TestClassForShowSource -a")
247
- result.should =~ /used by/
248
- result.should =~ /local monkeypatch/
249
- end
250
- end
251
-
252
- describe "when no class/module arg is given" do
253
- before do
254
- module TestHost
255
-
256
- # hello there froggy
257
- module M
258
- def d; end
259
- def e; end
260
- end
261
- end
262
- end
263
-
264
- after do
265
- Object.remove_const(:TestHost)
266
- end
267
-
268
- it 'should return doc for current module' do
269
- redirect_pry_io(InputTester.new("show-doc"), out = StringIO.new) do
270
- Pry.start(TestHost::M)
271
- end
272
-
273
- out.string.should =~ /hello there froggy/
274
- end
275
-
276
- end
277
-
278
-
279
- describe "should skip over broken modules" do
280
- before do
281
- module TestHost
282
-
283
- # hello
284
- module M
285
- binding.eval("def a; end", "dummy.rb", 1)
286
- binding.eval("def b; end", "dummy.rb", 2)
287
- binding.eval("def c; end", "dummy.rb", 3)
288
- end
289
-
290
- # goodbye
291
- module M
292
- def d; end
293
- def e; end
294
- end
295
- end
296
- end
297
-
298
- after do
299
- Object.remove_const(:TestHost)
300
- end
301
-
302
- it 'should return doc for first valid module' do
303
- redirect_pry_io(InputTester.new("show-doc TestHost::M"), out = StringIO.new) do
304
- Pry.start
305
- end
306
-
307
- out.string.should =~ /goodbye/
308
- out.string.should.not =~ /hello/
309
- end
310
-
311
- end
312
- end
313
-
314
- end
315
- end