pry 0.10.2-i386-mingw32 → 1.0.0.pre1-i386-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (189) hide show
  1. data/.document +2 -0
  2. data/.gitignore +16 -0
  3. data/.travis.yml +21 -0
  4. data/.yardopts +3 -0
  5. data/CHANGELOG +503 -0
  6. data/CONTRIBUTORS +55 -0
  7. data/Gemfile +9 -0
  8. data/Guardfile +62 -0
  9. data/LICENSE +2 -2
  10. data/{README.md → README.markdown} +31 -37
  11. data/Rakefile +144 -0
  12. data/TODO +117 -0
  13. data/lib/pry.rb +146 -33
  14. data/lib/pry/cli.rb +13 -35
  15. data/lib/pry/code.rb +63 -24
  16. data/lib/pry/code/loc.rb +2 -2
  17. data/lib/pry/code_object.rb +21 -40
  18. data/lib/pry/command.rb +6 -9
  19. data/lib/pry/command_set.rb +37 -80
  20. data/lib/pry/commands.rb +1 -1
  21. data/lib/pry/commands/amend_line.rb +1 -1
  22. data/lib/pry/commands/bang.rb +1 -1
  23. data/lib/pry/commands/cat.rb +2 -11
  24. data/lib/pry/commands/cat/abstract_formatter.rb +1 -1
  25. data/lib/pry/commands/cat/exception_formatter.rb +7 -6
  26. data/lib/pry/commands/cat/file_formatter.rb +32 -15
  27. data/lib/pry/commands/cat/input_expression_formatter.rb +1 -1
  28. data/lib/pry/commands/cd.rb +3 -14
  29. data/lib/pry/commands/code_collector.rb +4 -4
  30. data/lib/pry/commands/easter_eggs.rb +3 -3
  31. data/lib/pry/commands/edit.rb +22 -10
  32. data/lib/pry/commands/edit/exception_patcher.rb +1 -1
  33. data/lib/pry/commands/edit/file_and_line_locator.rb +2 -0
  34. data/lib/pry/{method/patcher.rb → commands/edit/method_patcher.rb} +37 -40
  35. data/lib/pry/commands/find_method.rb +22 -16
  36. data/lib/pry/commands/gem_install.rb +2 -5
  37. data/lib/pry/commands/gem_open.rb +1 -1
  38. data/lib/pry/commands/gist.rb +11 -10
  39. data/lib/pry/commands/help.rb +14 -14
  40. data/lib/pry/commands/hist.rb +5 -24
  41. data/lib/pry/commands/ls.rb +287 -56
  42. data/lib/pry/commands/play.rb +10 -44
  43. data/lib/pry/commands/pry_backtrace.rb +2 -1
  44. data/lib/pry/commands/raise_up.rb +1 -1
  45. data/lib/pry/commands/reload_code.rb +15 -31
  46. data/lib/pry/commands/ri.rb +3 -7
  47. data/lib/pry/commands/shell_command.rb +12 -17
  48. data/lib/pry/commands/shell_mode.rb +2 -2
  49. data/lib/pry/commands/show_doc.rb +0 -5
  50. data/lib/pry/commands/show_info.rb +10 -11
  51. data/lib/pry/commands/show_source.rb +3 -15
  52. data/lib/pry/commands/simple_prompt.rb +1 -1
  53. data/lib/pry/commands/toggle_color.rb +4 -8
  54. data/lib/pry/commands/whereami.rb +10 -18
  55. data/lib/pry/completion.rb +293 -0
  56. data/lib/pry/config.rb +233 -20
  57. data/lib/pry/core_extensions.rb +19 -29
  58. data/lib/pry/custom_completions.rb +6 -0
  59. data/lib/pry/editor.rb +103 -109
  60. data/lib/pry/helpers/base_helpers.rb +109 -22
  61. data/lib/pry/helpers/command_helpers.rb +8 -10
  62. data/lib/pry/helpers/documentation_helpers.rb +2 -1
  63. data/lib/pry/helpers/text.rb +5 -4
  64. data/lib/pry/history.rb +10 -21
  65. data/lib/pry/history_array.rb +0 -5
  66. data/lib/pry/hooks.rb +29 -9
  67. data/lib/pry/indent.rb +10 -5
  68. data/lib/pry/method.rb +86 -81
  69. data/lib/pry/method/weird_method_locator.rb +2 -4
  70. data/lib/pry/module_candidate.rb +14 -5
  71. data/lib/pry/pager.rb +48 -193
  72. data/lib/pry/plugins.rb +2 -2
  73. data/lib/pry/pry_class.rb +193 -104
  74. data/lib/pry/pry_instance.rb +154 -152
  75. data/lib/pry/rbx_method.rb +13 -0
  76. data/lib/pry/rbx_path.rb +1 -1
  77. data/lib/pry/repl.rb +14 -17
  78. data/lib/pry/repl_file_loader.rb +3 -8
  79. data/lib/pry/rubygem.rb +3 -3
  80. data/lib/pry/terminal.rb +3 -4
  81. data/lib/pry/test/helper.rb +11 -6
  82. data/lib/pry/version.rb +1 -1
  83. data/lib/pry/wrapped_module.rb +56 -49
  84. data/man/pry.1 +195 -0
  85. data/man/pry.1.html +204 -0
  86. data/man/pry.1.ronn +141 -0
  87. data/pry.gemspec +31 -0
  88. data/spec/Procfile +3 -0
  89. data/spec/cli_spec.rb +78 -0
  90. data/spec/code_object_spec.rb +277 -0
  91. data/spec/code_spec.rb +219 -0
  92. data/spec/command_helpers_spec.rb +29 -0
  93. data/spec/command_integration_spec.rb +562 -0
  94. data/spec/command_set_spec.rb +627 -0
  95. data/spec/command_spec.rb +821 -0
  96. data/spec/commands/amend_line_spec.rb +247 -0
  97. data/spec/commands/bang_spec.rb +18 -0
  98. data/spec/commands/cat_spec.rb +164 -0
  99. data/spec/commands/cd_spec.rb +250 -0
  100. data/spec/commands/disable_pry_spec.rb +25 -0
  101. data/spec/commands/edit_spec.rb +725 -0
  102. data/spec/commands/exit_all_spec.rb +27 -0
  103. data/spec/commands/exit_program_spec.rb +19 -0
  104. data/spec/commands/exit_spec.rb +28 -0
  105. data/spec/commands/find_method_spec.rb +70 -0
  106. data/spec/commands/gem_list_spec.rb +26 -0
  107. data/spec/commands/gist_spec.rb +79 -0
  108. data/spec/commands/help_spec.rb +56 -0
  109. data/spec/commands/hist_spec.rb +172 -0
  110. data/spec/commands/jump_to_spec.rb +15 -0
  111. data/spec/commands/ls_spec.rb +189 -0
  112. data/spec/commands/play_spec.rb +136 -0
  113. data/spec/commands/raise_up_spec.rb +56 -0
  114. data/spec/commands/save_file_spec.rb +177 -0
  115. data/spec/commands/show_doc_spec.rb +488 -0
  116. data/spec/commands/show_input_spec.rb +17 -0
  117. data/spec/commands/show_source_spec.rb +760 -0
  118. data/spec/commands/whereami_spec.rb +203 -0
  119. data/spec/completion_spec.rb +221 -0
  120. data/spec/control_d_handler_spec.rb +62 -0
  121. data/spec/documentation_helper_spec.rb +73 -0
  122. data/spec/editor_spec.rb +79 -0
  123. data/spec/exception_whitelist_spec.rb +21 -0
  124. data/spec/fixtures/candidate_helper1.rb +11 -0
  125. data/spec/fixtures/candidate_helper2.rb +8 -0
  126. data/spec/fixtures/example.erb +5 -0
  127. data/spec/fixtures/example_nesting.rb +33 -0
  128. data/spec/fixtures/show_source_doc_examples.rb +15 -0
  129. data/spec/fixtures/testlinkrc +2 -0
  130. data/spec/fixtures/testrc +2 -0
  131. data/spec/fixtures/testrcbad +2 -0
  132. data/spec/fixtures/whereami_helper.rb +6 -0
  133. data/spec/helper.rb +35 -0
  134. data/spec/helpers/bacon.rb +86 -0
  135. data/spec/helpers/mock_pry.rb +44 -0
  136. data/spec/helpers/repl_tester.rb +112 -0
  137. data/spec/helpers/table_spec.rb +105 -0
  138. data/spec/history_array_spec.rb +67 -0
  139. data/spec/hooks_spec.rb +522 -0
  140. data/spec/indent_spec.rb +301 -0
  141. data/spec/method_spec.rb +482 -0
  142. data/spec/prompt_spec.rb +61 -0
  143. data/spec/pry_defaults_spec.rb +420 -0
  144. data/spec/pry_history_spec.rb +69 -0
  145. data/spec/pry_output_spec.rb +95 -0
  146. data/spec/pry_repl_spec.rb +86 -0
  147. data/spec/pry_spec.rb +394 -0
  148. data/spec/pryrc_spec.rb +97 -0
  149. data/spec/run_command_spec.rb +25 -0
  150. data/spec/sticky_locals_spec.rb +147 -0
  151. data/spec/syntax_checking_spec.rb +81 -0
  152. data/spec/wrapped_module_spec.rb +261 -0
  153. data/wiki/Customizing-pry.md +397 -0
  154. data/wiki/Home.md +4 -0
  155. metadata +272 -61
  156. checksums.yaml +0 -7
  157. data/CHANGELOG.md +0 -714
  158. data/lib/pry/code/code_file.rb +0 -103
  159. data/lib/pry/color_printer.rb +0 -55
  160. data/lib/pry/commands/change_inspector.rb +0 -27
  161. data/lib/pry/commands/change_prompt.rb +0 -26
  162. data/lib/pry/commands/list_inspectors.rb +0 -35
  163. data/lib/pry/commands/list_prompts.rb +0 -35
  164. data/lib/pry/commands/ls/constants.rb +0 -47
  165. data/lib/pry/commands/ls/formatter.rb +0 -49
  166. data/lib/pry/commands/ls/globals.rb +0 -48
  167. data/lib/pry/commands/ls/grep.rb +0 -21
  168. data/lib/pry/commands/ls/instance_vars.rb +0 -39
  169. data/lib/pry/commands/ls/interrogatable.rb +0 -18
  170. data/lib/pry/commands/ls/jruby_hacks.rb +0 -49
  171. data/lib/pry/commands/ls/local_names.rb +0 -35
  172. data/lib/pry/commands/ls/local_vars.rb +0 -39
  173. data/lib/pry/commands/ls/ls_entity.rb +0 -70
  174. data/lib/pry/commands/ls/methods.rb +0 -57
  175. data/lib/pry/commands/ls/methods_helper.rb +0 -46
  176. data/lib/pry/commands/ls/self_methods.rb +0 -32
  177. data/lib/pry/commands/watch_expression.rb +0 -105
  178. data/lib/pry/commands/watch_expression/expression.rb +0 -38
  179. data/lib/pry/config/behavior.rb +0 -139
  180. data/lib/pry/config/convenience.rb +0 -25
  181. data/lib/pry/config/default.rb +0 -161
  182. data/lib/pry/exceptions.rb +0 -78
  183. data/lib/pry/input_completer.rb +0 -242
  184. data/lib/pry/input_lock.rb +0 -132
  185. data/lib/pry/inspector.rb +0 -27
  186. data/lib/pry/last_exception.rb +0 -61
  187. data/lib/pry/object_path.rb +0 -82
  188. data/lib/pry/output.rb +0 -50
  189. data/lib/pry/prompt.rb +0 -26
@@ -0,0 +1,17 @@
1
+ require 'helper'
2
+
3
+ describe "show-input" do
4
+ before do
5
+ @t = pry_tester
6
+ end
7
+
8
+ it 'should correctly show the current lines in the input buffer' do
9
+ @t.push *unindent(<<-STR).split("\n")
10
+ def hello
11
+ puts :bing
12
+ STR
13
+
14
+ @t.process_command 'show-input'
15
+ @t.last_output.should =~ /\A\d+: def hello\n\d+: puts :bing/
16
+ end
17
+ end
@@ -0,0 +1,760 @@
1
+ require 'helper'
2
+ require "fixtures/show_source_doc_examples"
3
+
4
+ if !PryTestHelpers.mri18_and_no_real_source_location?
5
+ describe "show-source" do
6
+ before do
7
+ @o = Object.new
8
+ def @o.sample_method
9
+ :sample
10
+ end
11
+
12
+ Object.const_set(:Test, Module.new)
13
+ end
14
+
15
+ after do
16
+ Pad.clear
17
+ end
18
+
19
+ it "should output a method's source" do
20
+ pry_eval(binding, 'show-source @o.sample_method').should =~ /def @o.sample/
21
+ end
22
+
23
+ it "should output help" do
24
+ pry_eval('show-source -h').should =~ /Usage:\s+show-source/
25
+ end
26
+
27
+ it "should output a method's source with line numbers" do
28
+ pry_eval(binding, 'show-source -l @o.sample_method').should =~ /\d+: def @o.sample/
29
+ end
30
+
31
+ it "should output a method's source with line numbers starting at 1" do
32
+ pry_eval(binding, 'show-source -b @o.sample_method').should =~ /1: def @o.sample/
33
+ end
34
+
35
+ it "should output a method's source if inside method and no name given" do
36
+ def @o.sample
37
+ pry_eval(binding, 'show-source').should =~ /def @o.sample/
38
+ end
39
+ @o.sample
40
+ end
41
+
42
+ it "should output a method's source inside method using the -l switch" do
43
+ def @o.sample
44
+ pry_eval(binding, 'show-source -l').should =~ /def @o.sample/
45
+ end
46
+ @o.sample
47
+ end
48
+
49
+ it "should find methods even if there are spaces in the arguments" do
50
+ def @o.foo(*bars)
51
+ "Mr flibble"
52
+ self
53
+ end
54
+
55
+ out = pry_eval(binding, "show-source @o.foo('bar', 'baz bam').foo")
56
+ out.should =~ /Mr flibble/
57
+ end
58
+
59
+ it "should find methods even if the object overrides method method" do
60
+ c = Class.new{
61
+ def method;
62
+ 98
63
+ end
64
+ }
65
+
66
+ pry_eval(binding, "show-source c.new.method").should =~ /98/
67
+ end
68
+
69
+ it "should not show the source when a non-extant method is requested" do
70
+ c = Class.new{ def method; 98; end }
71
+ mock_pry(binding, "show-source c#wrongmethod").should =~ /Couldn't locate/
72
+ end
73
+
74
+ it "should find instance_methods if the class overrides instance_method" do
75
+ c = Class.new{
76
+ def method;
77
+ 98
78
+ end
79
+
80
+ def self.instance_method; 789; end
81
+ }
82
+
83
+ pry_eval(binding, "show-source c#method").should =~ /98/
84
+ end
85
+
86
+ it "should find instance methods with self#moo" do
87
+ c = Class.new{ def moo; "ve over!"; end }
88
+
89
+ pry_eval(binding, "cd c", "show-source self#moo").should =~ /ve over/
90
+ end
91
+
92
+ it "should not find instance methods with self.moo" do
93
+ c = Class.new{ def moo; "ve over!"; end }
94
+
95
+ proc {
96
+ pry_eval(binding, 'cd c', 'show-source self.moo')
97
+ }.should.raise(Pry::CommandError).message.should =~ /Couldn't locate/
98
+ end
99
+
100
+ it "should find normal methods with self.moo" do
101
+ c = Class.new{ def self.moo; "ve over!"; end }
102
+
103
+ pry_eval(binding, 'cd c', 'show-source self.moo').should =~ /ve over/
104
+ end
105
+
106
+ it "should not find normal methods with self#moo" do
107
+ c = Class.new{ def self.moo; "ve over!"; end }
108
+
109
+ proc {
110
+ pry_eval(binding, 'cd c', 'show-source self#moo')
111
+ }.should.raise(Pry::CommandError).message.should =~ /Couldn't locate/
112
+ end
113
+
114
+ it "should find normal methods (i.e non-instance methods) by default" do
115
+ c = Class.new{ def self.moo; "ve over!"; end }
116
+
117
+ pry_eval(binding, "cd c", "show-source moo").should =~ /ve over/
118
+ end
119
+
120
+ it "should find instance methods if no normal methods available" do
121
+ c = Class.new{ def moo; "ve over!"; end }
122
+
123
+ pry_eval(binding, "cd c", "show-source moo").should =~ /ve over/
124
+ end
125
+
126
+ it "should find super methods" do
127
+ class Foo
128
+ def foo(*bars)
129
+ :super_wibble
130
+ end
131
+ end
132
+ o = Foo.new
133
+ Object.remove_const(:Foo)
134
+ def o.foo(*bars)
135
+ :wibble
136
+ end
137
+
138
+ pry_eval(binding, "show-source --super o.foo").
139
+ should =~ /:super_wibble/
140
+ end
141
+
142
+ it "should raise a CommandError when super method doesn't exist" do
143
+ def @o.foo(*bars); end
144
+
145
+ proc {
146
+ pry_eval(binding, "show-source --super @o.foo")
147
+ }.should.raise(Pry::CommandError).message.should =~ /No superclass found/
148
+ end
149
+
150
+ # dynamically defined method source retrieval is only supported in
151
+ # 1.9 - where Method#source_location is native
152
+ if RUBY_VERSION =~ /1.9/
153
+ it "should output the source of a method defined inside Pry" do
154
+ out = pry_eval("def dyn_method\n:test\nend", 'show-source dyn_method')
155
+ out.should =~ /def dyn_method/
156
+ Object.remove_method :dyn_method
157
+ end
158
+
159
+ it 'should output source for an instance method defined inside pry' do
160
+ pry_tester.tap do |t|
161
+ t.eval "class Test::A\n def yo\n end\nend"
162
+ t.eval('show-source Test::A#yo').should =~ /def yo/
163
+ end
164
+ end
165
+
166
+ it 'should output source for a repl method defined using define_method' do
167
+ pry_tester.tap do |t|
168
+ t.eval "class Test::A\n define_method(:yup) {}\nend"
169
+ t.eval('show-source Test::A#yup').should =~ /define_method\(:yup\)/
170
+ end
171
+ end
172
+
173
+ it "should output the source of a command defined inside Pry" do
174
+ command_definition = %{
175
+ Pry.commands.command "hubba-hubba" do
176
+ puts "that's what she said!"
177
+ end
178
+ }
179
+ out = pry_eval(command_definition, 'show-source hubba-hubba')
180
+ out.should =~ /what she said/
181
+ Pry.commands.delete "hubba-hubba"
182
+ end
183
+ end
184
+
185
+ describe "on sourcable objects" do
186
+ if RUBY_VERSION =~ /1.9/
187
+ it "should output source defined inside pry" do
188
+ pry_tester.tap do |t|
189
+ t.eval "hello = proc { puts 'hello world!' }"
190
+ t.eval("show-source hello").should =~ /proc \{ puts/
191
+ end
192
+ end
193
+ end
194
+
195
+ it "should output source for procs/lambdas stored in variables" do
196
+ hello = proc { puts 'hello world!' }
197
+ pry_eval(binding, 'show-source hello').should =~ /proc \{ puts/
198
+ end
199
+
200
+ it "should output source for procs/lambdas stored in constants" do
201
+ HELLO = proc { puts 'hello world!' }
202
+ pry_eval(binding, "show-source HELLO").should =~ /proc \{ puts/
203
+ Object.remove_const(:HELLO)
204
+ end
205
+
206
+ it "should output source for method objects" do
207
+ def @o.hi; puts 'hi world'; end
208
+ meth = @o.method(:hi)
209
+ pry_eval(binding, "show-source meth").should =~ /puts 'hi world'/
210
+ end
211
+
212
+ describe "on variables that shadow methods" do
213
+ before do
214
+ @t = pry_tester.eval unindent(<<-EOS)
215
+ class ::TestHost
216
+ def hello
217
+ hello = proc { ' smile ' }
218
+ pry_tester(binding)
219
+ end
220
+ end
221
+ ::TestHost.new.hello
222
+ EOS
223
+ end
224
+
225
+ after do
226
+ Object.remove_const(:TestHost)
227
+ end
228
+
229
+ it "source of variable should take precedence over method that is being shadowed" do
230
+ source = @t.eval('show-source hello')
231
+ source.should.not =~ /def hello/
232
+ source.should =~ /proc \{ ' smile ' \}/
233
+ end
234
+
235
+ it "source of method being shadowed should take precedence over variable
236
+ if given self.meth_name syntax" do
237
+ @t.eval('show-source self.hello').should =~ /def hello/
238
+ end
239
+ end
240
+ end
241
+
242
+ describe "on variable or constant" do
243
+ before do
244
+ class TestHost
245
+ def hello
246
+ "hi there"
247
+ end
248
+ end
249
+ end
250
+
251
+ after do
252
+ Object.remove_const(:TestHost)
253
+ end
254
+
255
+ it "should output source of its class if variable doesn't respond to source_location" do
256
+ test_host = TestHost.new
257
+ pry_eval(binding, 'show-source test_host').
258
+ should =~ /class TestHost\n.*def hello/
259
+ end
260
+
261
+ it "should output source of its class if constant doesn't respond to source_location" do
262
+ TEST_HOST = TestHost.new
263
+ pry_eval(binding, 'show-source TEST_HOST').
264
+ should =~ /class TestHost\n.*def hello/
265
+ Object.remove_const(:TEST_HOST)
266
+ end
267
+ end
268
+
269
+ describe "on modules" do
270
+ before do
271
+ class ShowSourceTestSuperClass
272
+ def alpha
273
+ end
274
+ end
275
+
276
+ class ShowSourceTestClass<ShowSourceTestSuperClass
277
+ def alpha
278
+ end
279
+ end
280
+
281
+ module ShowSourceTestSuperModule
282
+ def alpha
283
+ end
284
+ end
285
+
286
+ module ShowSourceTestModule
287
+ include ShowSourceTestSuperModule
288
+ def alpha
289
+ end
290
+ end
291
+
292
+ ShowSourceTestClassWeirdSyntax = Class.new do
293
+ def beta
294
+ end
295
+ end
296
+
297
+ ShowSourceTestModuleWeirdSyntax = Module.new do
298
+ def beta
299
+ end
300
+ end
301
+ end
302
+
303
+ after do
304
+ Object.remove_const :ShowSourceTestSuperClass
305
+ Object.remove_const :ShowSourceTestClass
306
+ Object.remove_const :ShowSourceTestClassWeirdSyntax
307
+ Object.remove_const :ShowSourceTestSuperModule
308
+ Object.remove_const :ShowSourceTestModule
309
+ Object.remove_const :ShowSourceTestModuleWeirdSyntax
310
+ end
311
+
312
+ describe "basic functionality, should find top-level module definitions" do
313
+ it 'should show source for a class' do
314
+ pry_eval('show-source ShowSourceTestClass').
315
+ should =~ /class ShowSourceTestClass.*?def alpha/m
316
+ end
317
+
318
+ it 'should show source for a super class' do
319
+ pry_eval('show-source -s ShowSourceTestClass').
320
+ should =~ /class ShowSourceTestSuperClass.*?def alpha/m
321
+ end
322
+
323
+ it 'should show source for a module' do
324
+ pry_eval('show-source ShowSourceTestModule').
325
+ should =~ /module ShowSourceTestModule/
326
+ end
327
+
328
+ it 'should show source for an ancestor module' do
329
+ pry_eval('show-source -s ShowSourceTestModule').
330
+ should =~ /module ShowSourceTestSuperModule/
331
+ end
332
+
333
+ it 'should show source for a class when Const = Class.new syntax is used' do
334
+ pry_eval('show-source ShowSourceTestClassWeirdSyntax').
335
+ should =~ /ShowSourceTestClassWeirdSyntax = Class.new/
336
+ end
337
+
338
+ it 'should show source for a super class when Const = Class.new syntax is used' do
339
+ pry_eval('show-source -s ShowSourceTestClassWeirdSyntax').
340
+ should =~ /class Object/
341
+ end
342
+
343
+ it 'should show source for a module when Const = Module.new syntax is used' do
344
+ pry_eval('show-source ShowSourceTestModuleWeirdSyntax').
345
+ should =~ /ShowSourceTestModuleWeirdSyntax = Module.new/
346
+ end
347
+ end
348
+
349
+ if !Pry::Helpers::BaseHelpers.mri_18?
350
+ before do
351
+ pry_eval unindent(<<-EOS)
352
+ class Dog
353
+ def woof
354
+ end
355
+ end
356
+
357
+ class TobinaMyDog < Dog
358
+ def woof
359
+ end
360
+ end
361
+ EOS
362
+ end
363
+
364
+ after do
365
+ Object.remove_const :Dog
366
+ Object.remove_const :TobinaMyDog
367
+ end
368
+
369
+ describe "in REPL" do
370
+ it 'should find class defined in repl' do
371
+ pry_eval('show-source TobinaMyDog').should =~ /class TobinaMyDog/
372
+ end
373
+ it 'should find superclass defined in repl' do
374
+ pry_eval('show-source -s TobinaMyDog').should =~ /class Dog/
375
+ end
376
+ end
377
+ end
378
+
379
+ it 'should lookup module name with respect to current context' do
380
+
381
+ constant_scope(:AlphaClass, :BetaClass) do
382
+ class BetaClass
383
+ def alpha
384
+ end
385
+ end
386
+
387
+ class AlphaClass
388
+ class BetaClass
389
+ def beta
390
+ end
391
+ end
392
+ end
393
+
394
+ pry_eval(AlphaClass, 'show-source BetaClass').should =~ /def beta/
395
+ end
396
+ end
397
+
398
+ it 'should lookup nested modules' do
399
+ constant_scope(:AlphaClass) do
400
+ class AlphaClass
401
+ class BetaClass
402
+ def beta
403
+ end
404
+ end
405
+ end
406
+
407
+ pry_eval('show-source AlphaClass::BetaClass').should =~ /class Beta/
408
+ end
409
+ end
410
+
411
+ # note that pry assumes a class is only monkey-patched at most
412
+ # ONCE per file, so will not find multiple monkeypatches in the
413
+ # SAME file.
414
+ describe "show-source -a" do
415
+ it 'should show the source for all monkeypatches defined in different files' do
416
+ class TestClassForShowSource
417
+ def beta
418
+ end
419
+ end
420
+
421
+ result = pry_eval('show-source TestClassForShowSource -a')
422
+ result.should =~ /def alpha/
423
+ result.should =~ /def beta/
424
+ end
425
+
426
+ it 'should show the source for a class_eval-based monkeypatch' do
427
+ TestClassForShowSourceClassEval.class_eval do
428
+ def class_eval_method
429
+ end
430
+ end
431
+
432
+ result = pry_eval('show-source TestClassForShowSourceClassEval -a')
433
+ result.should =~ /def class_eval_method/
434
+ end
435
+
436
+ it 'should ignore -a when object is not a module' do
437
+ TestClassForShowSourceClassEval.class_eval do
438
+ def class_eval_method
439
+ :bing
440
+ end
441
+ end
442
+
443
+ result = pry_eval('show-source TestClassForShowSourceClassEval#class_eval_method -a')
444
+ result.should =~ /bing/
445
+ end
446
+
447
+ it 'should show the source for an instance_eval-based monkeypatch' do
448
+ TestClassForShowSourceInstanceEval.instance_eval do
449
+ def instance_eval_method
450
+ end
451
+ end
452
+
453
+ result = pry_eval('show-source TestClassForShowSourceInstanceEval -a')
454
+ result.should =~ /def instance_eval_method/
455
+ end
456
+ end
457
+
458
+ describe "when show-source is invoked without a method or class argument" do
459
+ before do
460
+ module TestHost
461
+ class M
462
+ def alpha; end
463
+ def beta; end
464
+ end
465
+
466
+ module C
467
+ end
468
+
469
+ module D
470
+ def self.invoked_in_method
471
+ pry_eval(binding, 'show-source')
472
+ end
473
+ end
474
+ end
475
+ end
476
+
477
+ after do
478
+ Object.remove_const(:TestHost)
479
+ end
480
+
481
+ describe "inside a module" do
482
+ it 'should display module source by default' do
483
+ out = pry_eval(TestHost::M, 'show-source')
484
+ out.should =~ /class M/
485
+ out.should =~ /def alpha/
486
+ out.should =~ /def beta/
487
+ end
488
+
489
+ it 'should be unable to find module source if no methods defined' do
490
+ proc {
491
+ pry_eval(TestHost::C, 'show-source')
492
+ }.should.raise(Pry::CommandError).
493
+ message.should =~ /Couldn't locate/
494
+ end
495
+
496
+ it 'should display method code (rather than class) if Pry started inside method binding' do
497
+ out = TestHost::D.invoked_in_method
498
+ out.should =~ /invoked_in_method/
499
+ out.should.not =~ /module D/
500
+ end
501
+
502
+ it 'should display class source when inside instance' do
503
+ out = pry_eval(TestHost::M.new, 'show-source')
504
+ out.should =~ /class M/
505
+ out.should =~ /def alpha/
506
+ out.should =~ /def beta/
507
+ end
508
+
509
+ it 'should allow options to be passed' do
510
+ out = pry_eval(TestHost::M, 'show-source -b')
511
+ out.should =~ /\d:\s*class M/
512
+ out.should =~ /\d:\s*def alpha/
513
+ out.should =~ /\d:\s*def beta/
514
+ end
515
+
516
+ describe "should skip over broken modules" do
517
+ before do
518
+ module BabyDuck
519
+
520
+ module Muesli
521
+ binding.eval("def a; end", "dummy.rb", 1)
522
+ binding.eval("def b; end", "dummy.rb", 2)
523
+ binding.eval("def c; end", "dummy.rb", 3)
524
+ end
525
+
526
+ module Muesli
527
+ def d; end
528
+ def e; end
529
+ end
530
+ end
531
+ end
532
+
533
+ after do
534
+ Object.remove_const(:BabyDuck)
535
+ end
536
+
537
+ it 'should return source for first valid module' do
538
+ out = pry_eval('show-source BabyDuck::Muesli')
539
+ out.should =~ /def d; end/
540
+ out.should.not =~ /def a; end/
541
+ end
542
+ end
543
+ end
544
+ end
545
+ end
546
+
547
+ describe "on commands" do
548
+ before do
549
+ @oldset = Pry.config.commands
550
+ @set = Pry.config.commands = Pry::CommandSet.new do
551
+ import Pry::Commands
552
+ end
553
+ end
554
+
555
+ after do
556
+ Pry.config.commands = @oldset
557
+ end
558
+
559
+ describe "block commands" do
560
+ it 'should show source for an ordinary command' do
561
+ @set.command "foo", :body_of_foo do; end
562
+
563
+ pry_eval('show-source foo').should =~ /:body_of_foo/
564
+ end
565
+
566
+ it "should output source of commands using special characters" do
567
+ @set.command "!%$", "I gots the yellow fever" do; end
568
+
569
+ pry_eval('show-source !%$').should =~ /yellow fever/
570
+ end
571
+
572
+ it 'should show source for a command with spaces in its name' do
573
+ @set.command "foo bar", :body_of_foo_bar do; end
574
+
575
+ pry_eval('show-source foo bar').should =~ /:body_of_foo_bar/
576
+ end
577
+
578
+ it 'should show source for a command by listing name' do
579
+ @set.command /foo(.*)/, :body_of_foo_bar_regex, :listing => "bar" do; end
580
+
581
+ pry_eval('show-source bar').should =~ /:body_of_foo_bar_regex/
582
+ end
583
+ end
584
+
585
+ describe "create_command commands" do
586
+ it 'should show source for a command' do
587
+ @set.create_command "foo", "babble" do
588
+ def process() :body_of_foo end
589
+ end
590
+ pry_eval('show-source foo').should =~ /:body_of_foo/
591
+ end
592
+
593
+ it 'should show source for a command defined inside pry' do
594
+ pry_eval %{
595
+ _pry_.commands.create_command "foo", "babble" do
596
+ def process() :body_of_foo end
597
+ end
598
+ }
599
+ pry_eval('show-source foo').should =~ /:body_of_foo/
600
+ end
601
+ end
602
+
603
+ describe "real class-based commands" do
604
+ before do
605
+ class ::TemporaryCommand < Pry::ClassCommand
606
+ match 'temp-command'
607
+ def process() :body_of_temp end
608
+ end
609
+
610
+ Pry.commands.add_command(::TemporaryCommand)
611
+ end
612
+
613
+ after do
614
+ Object.remove_const(:TemporaryCommand)
615
+ end
616
+
617
+ it 'should show source for a command' do
618
+ pry_eval('show-source temp-command').should =~ /:body_of_temp/
619
+ end
620
+
621
+ it 'should show source for a command defined inside pry' do
622
+ pry_eval %{
623
+ class ::TemporaryCommandInPry < Pry::ClassCommand
624
+ match 'temp-command-in-pry'
625
+ def process() :body_of_temp end
626
+ end
627
+ }
628
+ Pry.commands.add_command(::TemporaryCommandInPry)
629
+ pry_eval('show-source temp-command-in-pry').should =~ /:body_of_temp/
630
+ Object.remove_const(:TemporaryCommandInPry)
631
+ end
632
+ end
633
+ end
634
+
635
+ describe "should set _file_ and _dir_" do
636
+ it 'should set _file_ and _dir_ to file containing method source' do
637
+ t = pry_tester
638
+ t.process_command "show-source TestClassForShowSource#alpha"
639
+ t.pry.last_file.should =~ /show_source_doc_examples/
640
+ t.pry.last_dir.should =~ /fixtures/
641
+ end
642
+ end
643
+
644
+ unless Pry::Helpers::BaseHelpers.rbx?
645
+ describe "can't find class/module code" do
646
+ describe "for classes" do
647
+ before do
648
+ module Jesus
649
+ module Pig
650
+ def lillybing; :lillybing; end
651
+ end
652
+
653
+ class Brian; end
654
+ class Jingle
655
+ def a; :doink; end
656
+ end
657
+
658
+ class Jangle < Jingle; include Pig; end
659
+ class Bangle < Jangle; end
660
+ end
661
+ end
662
+
663
+ after do
664
+ Object.remove_const(:Jesus)
665
+ end
666
+
667
+ it 'shows superclass code' do
668
+ t = pry_tester
669
+ t.process_command "show-source Jesus::Jangle"
670
+ t.last_output.should =~ /doink/
671
+ end
672
+
673
+ it 'ignores included modules' do
674
+ t = pry_tester
675
+ t.process_command "show-source Jesus::Jangle"
676
+ t.last_output.should.not =~ /lillybing/
677
+ end
678
+
679
+ it 'errors when class has no superclass to show' do
680
+ t = pry_tester
681
+ lambda { t.process_command "show-source Jesus::Brian" }.should.raise(Pry::CommandError).message.
682
+ should =~ /Couldn't locate/
683
+ end
684
+
685
+ it 'shows warning when reverting to superclass code' do
686
+ t = pry_tester
687
+ t.process_command "show-source Jesus::Jangle"
688
+ t.last_output.should =~ /Warning.*?Cannot find.*?Jesus::Jangle.*Showing.*Jesus::Jingle instead/
689
+ end
690
+
691
+ it 'shows nth level superclass code (when no intermediary superclasses have code either)' do
692
+ t = pry_tester
693
+ t.process_command "show-source Jesus::Bangle"
694
+ t.last_output.should =~ /doink/
695
+ end
696
+
697
+ it 'shows correct warning when reverting to nth level superclass' do
698
+ t = pry_tester
699
+ t.process_command "show-source Jesus::Bangle"
700
+ t.last_output.should =~ /Warning.*?Cannot find.*?Jesus::Bangle.*Showing.*Jesus::Jingle instead/
701
+ end
702
+ end
703
+
704
+ describe "for modules" do
705
+ before do
706
+ module Jesus
707
+ module Alpha
708
+ def alpha; :alpha; end
709
+ end
710
+
711
+ module Zeta; end
712
+
713
+ module Beta
714
+ include Alpha
715
+ end
716
+
717
+ module Gamma
718
+ include Beta
719
+ end
720
+ end
721
+ end
722
+
723
+ after do
724
+ Object.remove_const(:Jesus)
725
+ end
726
+
727
+ it 'shows included module code' do
728
+ t = pry_tester
729
+ t.process_command "show-source Jesus::Beta"
730
+ t.last_output.should =~ /alpha/
731
+ end
732
+
733
+ it 'shows warning when reverting to included module code' do
734
+ t = pry_tester
735
+ t.process_command "show-source Jesus::Beta"
736
+ t.last_output.should =~ /Warning.*?Cannot find.*?Jesus::Beta.*Showing.*Jesus::Alpha instead/
737
+ end
738
+
739
+ it 'errors when module has no included module to show' do
740
+ t = pry_tester
741
+ lambda { t.process_command "show-source Jesus::Zeta" }.should.raise(Pry::CommandError).message.
742
+ should =~ /Couldn't locate/
743
+ end
744
+
745
+ it 'shows nth level included module code (when no intermediary modules have code either)' do
746
+ t = pry_tester
747
+ t.process_command "show-source Jesus::Gamma"
748
+ t.last_output.should =~ /alpha/
749
+ end
750
+
751
+ it 'shows correct warning when reverting to nth level included module' do
752
+ t = pry_tester
753
+ t.process_command "show-source Jesus::Gamma"
754
+ t.last_output.should =~ /Warning.*?Cannot find.*?Jesus::Gamma.*Showing.*Jesus::Alpha instead/
755
+ end
756
+ end
757
+ end
758
+ end
759
+ end
760
+ end