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

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 (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,432 +0,0 @@
1
- require 'helper'
2
-
3
- if !mri18_and_no_real_source_location?
4
- describe "show-source" do
5
- before do
6
- @str_output = StringIO.new
7
- @o = Object.new
8
- end
9
-
10
- after do
11
- Pad.clear
12
- end
13
-
14
- it 'should output a method\'s source' do
15
- redirect_pry_io(InputTester.new("show-source sample_method", "exit-all"), @str_output) do
16
- pry
17
- end
18
-
19
- @str_output.string.should =~ /def sample/
20
- end
21
-
22
- it 'should output help' do
23
- mock_pry('show-source -h').should =~ /Usage: show-source/
24
- end
25
-
26
- it 'should output a method\'s source with line numbers' do
27
- redirect_pry_io(InputTester.new("show-source -l sample_method", "exit-all"), @str_output) do
28
- pry
29
- end
30
-
31
- @str_output.string.should =~ /\d+: def sample/
32
- end
33
-
34
- it 'should output a method\'s source with line numbers starting at 1' do
35
- redirect_pry_io(InputTester.new("show-source -b sample_method", "exit-all"), @str_output) do
36
- pry
37
- end
38
-
39
- @str_output.string.should =~ /1: def sample/
40
- end
41
-
42
- it 'should output a method\'s source if inside method without needing to use method name' do
43
- Pad.str_output = @str_output
44
-
45
- def @o.sample
46
- redirect_pry_io(InputTester.new("show-source", "exit-all"), Pad.str_output) do
47
- binding.pry
48
- end
49
- end
50
- @o.sample
51
-
52
- Pad.str_output.string.should =~ /def @o.sample/
53
- end
54
-
55
- it 'should output a method\'s source if inside method without needing to use method name, and using the -l switch' do
56
- Pad.str_output = @str_output
57
-
58
- def @o.sample
59
- redirect_pry_io(InputTester.new("show-source -l", "exit-all"), Pad.str_output) do
60
- binding.pry
61
- end
62
- end
63
- @o.sample
64
-
65
- Pad.str_output.string.should =~ /def @o.sample/
66
- end
67
-
68
- it "should find methods even if there are spaces in the arguments" do
69
- def @o.foo(*bars)
70
- "Mr flibble"
71
- self
72
- end
73
-
74
- redirect_pry_io(InputTester.new("show-source @o.foo('bar', 'baz bam').foo",
75
- "exit-all"), @str_output) do
76
- binding.pry
77
- end
78
-
79
- @str_output.string.should =~ /Mr flibble/
80
- end
81
-
82
- it "should find methods even if the object has an overridden method method" do
83
- c = Class.new{
84
- def method;
85
- 98
86
- end
87
- }
88
-
89
- mock_pry(binding, "show-source c.new.method").should =~ /98/
90
- end
91
-
92
- it "should find instance_methods even if the class has an override instance_method method" do
93
- c = Class.new{
94
- def method;
95
- 98
96
- end
97
-
98
- def self.instance_method; 789; end
99
- }
100
-
101
- mock_pry(binding, "show-source c#method").should =~ /98/
102
- end
103
-
104
- it "should find instance methods with -M" do
105
- c = Class.new{ def moo; "ve over!"; end }
106
- mock_pry(binding, "cd c","show-source -M moo").should =~ /ve over/
107
- end
108
-
109
- it "should not find instance methods with -m" do
110
- c = Class.new{ def moo; "ve over!"; end }
111
- mock_pry(binding, "cd c", "show-source -m moo").should =~ /could not be found/
112
- end
113
-
114
- it "should find normal methods with -m" do
115
- c = Class.new{ def self.moo; "ve over!"; end }
116
- mock_pry(binding, "cd c", "show-source -m moo").should =~ /ve over/
117
- end
118
-
119
- it "should not find normal methods with -M" do
120
- c = Class.new{ def self.moo; "ve over!"; end }
121
- mock_pry(binding, "cd c", "show-source -M moo").should =~ /could not be found/
122
- end
123
-
124
- it "should find normal methods with no -M or -m" do
125
- c = Class.new{ def self.moo; "ve over!"; end }
126
- mock_pry(binding, "cd c", "show-source moo").should =~ /ve over/
127
- end
128
-
129
- it "should find instance methods with no -M or -m" do
130
- c = Class.new{ def moo; "ve over!"; end }
131
- mock_pry(binding, "cd c", "show-source moo").should =~ /ve over/
132
- end
133
-
134
- it "should find super methods" do
135
- class Foo
136
- def foo(*bars)
137
- :super_wibble
138
- end
139
- end
140
- o = Foo.new
141
- Object.remove_const(:Foo)
142
- def o.foo(*bars)
143
- :wibble
144
- end
145
-
146
- mock_pry(binding, "show-source --super o.foo").should =~ /:super_wibble/
147
- end
148
-
149
- it "should not raise an exception when a non-extant super method is requested" do
150
- def @o.foo(*bars); end
151
-
152
- mock_pry(binding, "show-source --super @o.foo").should =~ /'self.foo' has no super method/
153
- end
154
-
155
- # dynamically defined method source retrieval is only supported in
156
- # 1.9 - where Method#source_location is native
157
- if RUBY_VERSION =~ /1.9/
158
- it 'should output a method\'s source for a method defined inside pry' do
159
- redirect_pry_io(InputTester.new("def dyna_method", ":testing", "end", "show-source dyna_method"), @str_output) do
160
- TOPLEVEL_BINDING.pry
161
- end
162
-
163
- @str_output.string.should =~ /def dyna_method/
164
- Object.remove_method :dyna_method
165
- end
166
-
167
- it 'should output a method\'s source for a method defined inside pry, even if exceptions raised before hand' do
168
- redirect_pry_io(InputTester.new("bad code", "123", "bad code 2", "1 + 2", "def dyna_method", ":testing", "end", "show-source dyna_method"), @str_output) do
169
- TOPLEVEL_BINDING.pry
170
- end
171
-
172
- @str_output.string.should =~ /def dyna_method/
173
- Object.remove_method :dyna_method
174
- end
175
-
176
- it 'should output an instance method\'s source for a method defined inside pry' do
177
- Object.remove_const :A if defined?(A)
178
- redirect_pry_io(InputTester.new("class A", "def yo", "end", "end", "show-source A#yo"), @str_output) do
179
- TOPLEVEL_BINDING.pry
180
- end
181
-
182
- @str_output.string.should =~ /def yo/
183
- Object.remove_const :A
184
- end
185
-
186
- it 'should output an instance method\'s source for a method defined inside pry using define_method' do
187
- Object.remove_const :A if defined?(A)
188
- redirect_pry_io(InputTester.new("class A", "define_method(:yup) {}", "end", "show-source A#yup"), @str_output) do
189
- TOPLEVEL_BINDING.pry
190
- end
191
-
192
- @str_output.string.should =~ /define_method\(:yup\)/
193
- Object.remove_const :A
194
- end
195
- end
196
-
197
- describe "on modules" do
198
- before do
199
- class ShowSourceTestClass
200
- def alpha
201
- end
202
- end
203
-
204
- module ShowSourceTestModule
205
- def alpha
206
- end
207
- end
208
-
209
- ShowSourceTestClassWeirdSyntax = Class.new do
210
- def beta
211
- end
212
- end
213
-
214
- ShowSourceTestModuleWeirdSyntax = Module.new do
215
- def beta
216
- end
217
- end
218
- end
219
-
220
- after do
221
- Object.remove_const :ShowSourceTestClass
222
- Object.remove_const :ShowSourceTestClassWeirdSyntax
223
- Object.remove_const :ShowSourceTestModule
224
- Object.remove_const :ShowSourceTestModuleWeirdSyntax
225
- end
226
-
227
- describe "basic functionality, should find top-level module definitions" do
228
- it 'should show source for a class' do
229
- mock_pry("show-source ShowSourceTestClass").should =~ /class ShowSourceTest.*?def alpha/m
230
- end
231
-
232
- it 'should show source for a module' do
233
- mock_pry("show-source ShowSourceTestModule").should =~ /module ShowSourceTestModule/
234
- end
235
-
236
- it 'should show source for a class when Const = Class.new syntax is used' do
237
- mock_pry("show-source ShowSourceTestClassWeirdSyntax").should =~ /ShowSourceTestClassWeirdSyntax = Class.new/
238
- end
239
-
240
- it 'should show source for a module when Const = Module.new syntax is used' do
241
- mock_pry("show-source ShowSourceTestModuleWeirdSyntax").should =~ /ShowSourceTestModuleWeirdSyntax = Module.new/
242
- end
243
- end
244
-
245
- if !Pry::Helpers::BaseHelpers.mri_18?
246
- describe "in REPL" do
247
- it 'should find class defined in repl' do
248
- mock_pry("class TobinaMyDog", "def woof", "end", "end", "show-source TobinaMyDog").should =~ /class TobinaMyDog/
249
- Object.remove_const :TobinaMyDog
250
- end
251
- end
252
- end
253
-
254
- it 'should lookup module name with respect to current context' do
255
- constant_scope(:AlphaClass, :BetaClass) do
256
- class BetaClass
257
- def alpha
258
- end
259
- end
260
-
261
- class AlphaClass
262
- class BetaClass
263
- def beta
264
- end
265
- end
266
- end
267
-
268
- redirect_pry_io(InputTester.new("show-source BetaClass", "exit-all"), out=StringIO.new) do
269
- AlphaClass.pry
270
- end
271
-
272
- out.string.should =~ /def beta/
273
- end
274
- end
275
-
276
- it 'should lookup nested modules' do
277
- constant_scope(:AlphaClass) do
278
- class AlphaClass
279
- class BetaClass
280
- def beta
281
- end
282
- end
283
- end
284
-
285
- mock_pry("show-source AlphaClass::BetaClass").should =~ /class BetaClass/
286
- end
287
- end
288
-
289
- # note that pry assumes a class is only monkey-patched at most
290
- # ONCE per file, so will not find multiple monkeypatches in the
291
- # SAME file.
292
- describe "show-source -a" do
293
- it 'should show the source for all monkeypatches defined in different files' do
294
- class TestClassForShowSource
295
- def beta
296
- end
297
- end
298
-
299
- result = mock_pry("show-source TestClassForShowSource -a")
300
- result.should =~ /def alpha/
301
- result.should =~ /def beta/
302
- end
303
-
304
- it 'should show the source for a class_eval-based monkeypatch' do
305
- TestClassForShowSourceClassEval.class_eval do
306
- def class_eval_method
307
- end
308
- end
309
-
310
- result = mock_pry("show-source TestClassForShowSourceClassEval -a")
311
- result.should =~ /def class_eval_method/
312
- end
313
-
314
- it 'should show the source for an instance_eval-based monkeypatch' do
315
- TestClassForShowSourceInstanceEval.instance_eval do
316
- def instance_eval_method
317
- end
318
- end
319
-
320
- result = mock_pry("show-source TestClassForShowSourceInstanceEval -a")
321
- result.should =~ /def instance_eval_method/
322
- end
323
- end
324
-
325
- describe "when show-source is invoked without a method or class argument" do
326
- before do
327
- module TestHost
328
- class M
329
- def alpha; end
330
- def beta; end
331
- end
332
-
333
- module C
334
- end
335
-
336
- module D
337
- def self.invoked_in_method
338
- redirect_pry_io(InputTester.new("show-source", "exit-all"), out = StringIO.new) do
339
- Pry.start(binding)
340
- end
341
- out.string
342
- end
343
- end
344
- end
345
- end
346
-
347
- after do
348
- Object.remove_const(:TestHost)
349
- end
350
-
351
- describe "inside a module" do
352
- it 'should display module source by default' do
353
- redirect_pry_io(InputTester.new("show-source", "exit-all"), out = StringIO.new) do
354
- Pry.start(TestHost::M)
355
- end
356
-
357
- out.string.should =~ /class M/
358
- out.string.should =~ /def alpha/
359
- out.string.should =~ /def beta/
360
- end
361
-
362
- it 'should be unable to find module source if no methods defined' do
363
- redirect_pry_io(InputTester.new("show-source", "exit-all"), out = StringIO.new) do
364
- Pry.start(TestHost::C)
365
- end
366
-
367
- out.string.should.should =~ /Cannot find a definition for/
368
- end
369
-
370
- it 'should display method code (rather than class) if Pry started inside method binding' do
371
- string = TestHost::D.invoked_in_method
372
- string.should =~ /invoked_in_method/
373
- string.should.not =~ /module D/
374
- end
375
-
376
- it 'should display class source when inside instance' do
377
- redirect_pry_io(InputTester.new("show-source", "exit-all"), out = StringIO.new) do
378
- Pry.start(TestHost::M.new)
379
- end
380
-
381
- out.string.should =~ /class M/
382
- out.string.should =~ /def alpha/
383
- out.string.should =~ /def beta/
384
- end
385
-
386
- it 'should allow options to be passed' do
387
- redirect_pry_io(InputTester.new("show-source -b", "exit-all"), out = StringIO.new) do
388
- Pry.start(TestHost::M)
389
- end
390
-
391
- out.string.should =~ /\d:\s*class M/
392
- out.string.should =~ /\d:\s*def alpha/
393
- out.string.should =~ /\d:\s*def beta/
394
- end
395
-
396
- describe "should skip over broken modules" do
397
- before do
398
- module BabyDuck
399
-
400
- module Muesli
401
- binding.eval("def a; end", "dummy.rb", 1)
402
- binding.eval("def b; end", "dummy.rb", 2)
403
- binding.eval("def c; end", "dummy.rb", 3)
404
- end
405
-
406
- module Muesli
407
- def d; end
408
- def e; end
409
- end
410
- end
411
- end
412
-
413
- after do
414
- Object.remove_const(:BabyDuck)
415
- end
416
-
417
- it 'should return source for first valid module' do
418
- redirect_pry_io(InputTester.new("show-source BabyDuck::Muesli"), out = StringIO.new) do
419
- Pry.start
420
- end
421
-
422
- out.string.should =~ /def d; end/
423
- out.string.should.not =~ /def a; end/
424
- end
425
-
426
- end
427
- end
428
- end
429
- end
430
- end
431
- end
432
-
@@ -1,41 +0,0 @@
1
- require 'helper'
2
-
3
- describe Pry do
4
- describe "output failsafe" do
5
- after do
6
- Pry.config.print = Pry::DEFAULT_PRINT
7
- end
8
-
9
- it "should catch serialization exceptions" do
10
- Pry.config.print = lambda { |*a| raise "catch-22" }
11
-
12
- lambda {
13
- mock_pry("1")
14
- }.should.not.raise
15
- end
16
-
17
- it "should display serialization exceptions" do
18
- Pry.config.print = lambda { |*a| raise "catch-22" }
19
-
20
- mock_pry("1").should =~ /\(pry\) output error: #<RuntimeError: catch-22>/
21
- end
22
-
23
- it "should catch errors serializing exceptions" do
24
- Pry.config.print = lambda do |*a|
25
- raise Exception.new("catch-22").tap{ |e| class << e; def inspect; raise e; end; end }
26
- end
27
-
28
- mock_pry("1").should =~ /\(pry\) output error: failed to show result/
29
- end
30
- end
31
-
32
- describe "DEFAULT_PRINT" do
33
- it "should output the right thing" do
34
- mock_pry("{:a => 1}").should =~ /\{:a=>1\}/
35
- end
36
-
37
- it "should not be phased by un-inspectable things" do
38
- mock_pry("class NastyClass; undef pretty_inspect; end", "NastyClass.new").should =~ /#<NastyClass:0x.*?>/
39
- end
40
- end
41
- end