pry 0.9.9.6pre2-java → 0.9.10-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. data/CHANGELOG +41 -0
  2. data/CONTRIBUTORS +27 -26
  3. data/README.markdown +4 -4
  4. data/Rakefile +2 -2
  5. data/lib/pry.rb +25 -19
  6. data/lib/pry/cli.rb +31 -10
  7. data/lib/pry/code.rb +41 -83
  8. data/lib/pry/command.rb +87 -76
  9. data/lib/pry/command_set.rb +13 -20
  10. data/lib/pry/completion.rb +139 -121
  11. data/lib/pry/config.rb +4 -0
  12. data/lib/pry/core_extensions.rb +88 -31
  13. data/lib/pry/default_commands/cd.rb +31 -8
  14. data/lib/pry/default_commands/context.rb +4 -58
  15. data/lib/pry/default_commands/easter_eggs.rb +1 -1
  16. data/lib/pry/default_commands/editing.rb +21 -14
  17. data/lib/pry/default_commands/find_method.rb +5 -7
  18. data/lib/pry/default_commands/gist.rb +187 -0
  19. data/lib/pry/default_commands/hist.rb +6 -6
  20. data/lib/pry/default_commands/input_and_output.rb +73 -129
  21. data/lib/pry/default_commands/introspection.rb +107 -52
  22. data/lib/pry/default_commands/ls.rb +1 -1
  23. data/lib/pry/default_commands/misc.rb +0 -5
  24. data/lib/pry/default_commands/whereami.rb +92 -0
  25. data/lib/pry/helpers/base_helpers.rb +6 -1
  26. data/lib/pry/helpers/command_helpers.rb +30 -9
  27. data/lib/pry/helpers/documentation_helpers.rb +7 -7
  28. data/lib/pry/helpers/options_helpers.rb +1 -1
  29. data/lib/pry/helpers/text.rb +7 -9
  30. data/lib/pry/history.rb +15 -2
  31. data/lib/pry/hooks.rb +1 -1
  32. data/lib/pry/indent.rb +17 -10
  33. data/lib/pry/method.rb +35 -19
  34. data/lib/pry/module_candidate.rb +130 -0
  35. data/lib/pry/pry_class.rb +54 -22
  36. data/lib/pry/pry_instance.rb +71 -14
  37. data/lib/pry/repl_file_loader.rb +80 -0
  38. data/lib/pry/version.rb +1 -1
  39. data/lib/pry/wrapped_module.rb +121 -142
  40. data/pry.gemspec +13 -13
  41. data/test/candidate_helper1.rb +11 -0
  42. data/test/candidate_helper2.rb +8 -0
  43. data/test/helper.rb +16 -0
  44. data/test/test_code.rb +1 -1
  45. data/test/test_command.rb +364 -270
  46. data/test/test_command_integration.rb +235 -267
  47. data/test/test_completion.rb +36 -0
  48. data/test/test_control_d_handler.rb +45 -0
  49. data/test/test_default_commands/example.erb +5 -0
  50. data/test/test_default_commands/test_cd.rb +316 -11
  51. data/test/test_default_commands/test_context.rb +143 -192
  52. data/test/test_default_commands/test_documentation.rb +81 -14
  53. data/test/test_default_commands/test_find_method.rb +10 -2
  54. data/test/test_default_commands/test_input.rb +102 -111
  55. data/test/test_default_commands/test_introspection.rb +17 -12
  56. data/test/test_default_commands/test_ls.rb +8 -6
  57. data/test/test_default_commands/test_shell.rb +18 -15
  58. data/test/test_default_commands/test_show_source.rb +170 -44
  59. data/test/test_exception_whitelist.rb +6 -2
  60. data/test/test_hooks.rb +32 -0
  61. data/test/test_input_stack.rb +19 -16
  62. data/test/test_method.rb +0 -4
  63. data/test/test_prompt.rb +60 -0
  64. data/test/test_pry.rb +23 -31
  65. data/test/test_pry_defaults.rb +75 -57
  66. data/test/test_syntax_checking.rb +12 -11
  67. data/test/test_wrapped_module.rb +103 -0
  68. metadata +72 -26
@@ -1,7 +1,6 @@
1
1
  require 'helper'
2
2
 
3
3
  describe "Pry::DefaultCommands::Introspection" do
4
-
5
4
  describe "edit" do
6
5
  before do
7
6
  @old_editor = Pry.config.editor
@@ -11,6 +10,7 @@ describe "Pry::DefaultCommands::Introspection" do
11
10
  nil
12
11
  end
13
12
  end
13
+
14
14
  after do
15
15
  Pry.config.editor = @old_editor
16
16
  end
@@ -458,6 +458,10 @@ describe "Pry::DefaultCommands::Introspection" do
458
458
  # show-command only works in implementations that support Proc#source_location
459
459
  if Proc.method_defined?(:source_location)
460
460
  describe "show-command" do
461
+ before do
462
+ @str_output = StringIO.new
463
+ end
464
+
461
465
  it 'should show source for an ordinary command' do
462
466
  set = Pry::CommandSet.new do
463
467
  import_from Pry::Commands, "show-command"
@@ -465,11 +469,12 @@ describe "Pry::DefaultCommands::Introspection" do
465
469
  :body_of_foo
466
470
  end
467
471
  end
468
- str_output = StringIO.new
469
- redirect_pry_io(InputTester.new("show-command foo"), str_output) do
472
+
473
+ redirect_pry_io(InputTester.new("show-command foo"), @str_output) do
470
474
  Pry.new(:commands => set).rep
471
475
  end
472
- str_output.string.should =~ /:body_of_foo/
476
+
477
+ @str_output.string.should =~ /:body_of_foo/
473
478
  end
474
479
 
475
480
  it 'should show source for a command with spaces in its name' do
@@ -479,11 +484,12 @@ describe "Pry::DefaultCommands::Introspection" do
479
484
  :body_of_foo_bar
480
485
  end
481
486
  end
482
- str_output = StringIO.new
483
- redirect_pry_io(InputTester.new("show-command \"foo bar\""), str_output) do
487
+
488
+ redirect_pry_io(InputTester.new("show-command \"foo bar\""), @str_output) do
484
489
  Pry.new(:commands => set).rep
485
490
  end
486
- str_output.string.should =~ /:body_of_foo_bar/
491
+
492
+ @str_output.string.should =~ /:body_of_foo_bar/
487
493
  end
488
494
 
489
495
  it 'should show source for a command by listing name' do
@@ -493,14 +499,13 @@ describe "Pry::DefaultCommands::Introspection" do
493
499
  :body_of_foo_regex
494
500
  end
495
501
  end
496
- str_output = StringIO.new
497
- redirect_pry_io(InputTester.new("show-command bar"), str_output) do
502
+
503
+ redirect_pry_io(InputTester.new("show-command bar"), @str_output) do
498
504
  Pry.new(:commands => set).rep
499
505
  end
500
- str_output.string.should =~ /:body_of_foo_regex/
506
+
507
+ @str_output.string.should =~ /:body_of_foo_regex/
501
508
  end
502
509
  end
503
510
  end
504
-
505
-
506
511
  end
@@ -1,4 +1,5 @@
1
1
  require 'helper'
2
+
2
3
  describe "ls" do
3
4
  describe "below ceiling" do
4
5
  it "should stop before Object by default" do
@@ -30,21 +31,21 @@ describe "ls" do
30
31
 
31
32
  describe "methods" do
32
33
  it "should show public methods by default" do
33
- mock_pry("ls Class.new{ def goo; end }.new").should =~ /goo/
34
+ mock_pry("ls Class.new{ def goo; end }.new").should =~ /methods: goo/
34
35
  end
35
36
 
36
37
  it "should not show protected/private by default" do
37
- mock_pry("ls -M Class.new{ def goo; end; private :goo }").should.not =~ /goo/
38
- mock_pry("ls Class.new{ def goo; end; protected :goo }.new").should.not =~ /goo/
38
+ mock_pry("ls -M Class.new{ def goo; end; private :goo }").should.not =~ /methods: goo/
39
+ mock_pry("ls Class.new{ def goo; end; protected :goo }.new").should.not =~ /methods: goo/
39
40
  end
40
41
 
41
42
  it "should show public methods with -p" do
42
- mock_pry("ls -p Class.new{ def goo; end }.new").should =~ /goo/
43
+ mock_pry("ls -p Class.new{ def goo; end }.new").should =~ /methods: goo/
43
44
  end
44
45
 
45
46
  it "should show protected/private methods with -p" do
46
- mock_pry("ls -pM Class.new{ def goo; end; protected :goo }").should =~ /goo/
47
- mock_pry("ls -p Class.new{ def goo; end; private :goo }.new").should =~ /goo/
47
+ mock_pry("ls -pM Class.new{ def goo; end; protected :goo }").should =~ /methods: goo/
48
+ mock_pry("ls -p Class.new{ def goo; end; private :goo }.new").should =~ /methods: goo/
48
49
  end
49
50
 
50
51
  it "should work for objects with an overridden method method" do
@@ -92,6 +93,7 @@ describe "ls" do
92
93
  mock_pry("ls -c").should =~ /ArgumentError/
93
94
  mock_pry("ls -c --grep Run").should.not =~ /ArgumentError/
94
95
  end
96
+
95
97
  it "should still output matching things" do
96
98
  mock_pry("ls -c --grep Run").should =~ /RuntimeError/
97
99
  end
@@ -154,7 +154,7 @@ describe "Pry::DefaultCommands::Shell" do
154
154
 
155
155
  describe "-c" do
156
156
  it 'should save a command to a file' do
157
- redirect_pry_io(InputTester.new("save-file #{@path} -c show-method",
157
+ redirect_pry_io(InputTester.new("save-file #{@path} -k show-method",
158
158
  "exit-all")) do
159
159
  Pry.start(@o)
160
160
  end
@@ -192,6 +192,9 @@ describe "Pry::DefaultCommands::Shell" do
192
192
  end
193
193
 
194
194
  describe "cat" do
195
+ before do
196
+ @str_output = StringIO.new
197
+ end
195
198
 
196
199
  describe "on receiving a file that does not exist" do
197
200
  it 'should display an error message' do
@@ -250,7 +253,7 @@ describe "Pry::DefaultCommands::Shell" do
250
253
 
251
254
  describe "with --ex N" do
252
255
  it 'should cat first level of backtrace when --ex used with no argument ' do
253
- pry_instance = Pry.new(:input => StringIO.new("cat --ex"), :output => str_output = StringIO.new)
256
+ pry_instance = Pry.new(:input => StringIO.new("cat --ex"), :output => @str_output)
254
257
 
255
258
  temp_file do |f|
256
259
  f << "bt number 1"
@@ -259,11 +262,11 @@ describe "Pry::DefaultCommands::Shell" do
259
262
  pry_instance.rep(self)
260
263
  end
261
264
 
262
- str_output.string.should =~ /bt number 1/
265
+ @str_output.string.should =~ /bt number 1/
263
266
  end
264
267
 
265
268
  it 'should cat first level of backtrace when --ex 0 used ' do
266
- pry_instance = Pry.new(:input => StringIO.new("cat --ex 0"), :output => str_output = StringIO.new)
269
+ pry_instance = Pry.new(:input => StringIO.new("cat --ex 0"), :output => @str_output)
267
270
 
268
271
  temp_file do |f|
269
272
  f << "bt number 1"
@@ -272,11 +275,11 @@ describe "Pry::DefaultCommands::Shell" do
272
275
  pry_instance.rep(self)
273
276
  end
274
277
 
275
- str_output.string.should =~ /bt number 1/
278
+ @str_output.string.should =~ /bt number 1/
276
279
  end
277
280
 
278
281
  it 'should cat second level of backtrace when --ex 1 used ' do
279
- pry_instance = Pry.new(:input => StringIO.new("cat --ex 1"), :output => str_output = StringIO.new)
282
+ pry_instance = Pry.new(:input => StringIO.new("cat --ex 1"), :output => @str_output)
280
283
 
281
284
  temp_file do |f|
282
285
  f << "bt number 2"
@@ -285,11 +288,11 @@ describe "Pry::DefaultCommands::Shell" do
285
288
  pry_instance.rep(self)
286
289
  end
287
290
 
288
- str_output.string.should =~ /bt number 2/
291
+ @str_output.string.should =~ /bt number 2/
289
292
  end
290
293
 
291
294
  it 'should cat third level of backtrace when --ex 2 used' do
292
- pry_instance = Pry.new(:input => StringIO.new("cat --ex 2"), :output => str_output = StringIO.new)
295
+ pry_instance = Pry.new(:input => StringIO.new("cat --ex 2"), :output => @str_output)
293
296
 
294
297
  temp_file do |f|
295
298
  f << "bt number 3"
@@ -298,14 +301,14 @@ describe "Pry::DefaultCommands::Shell" do
298
301
  pry_instance.rep(self)
299
302
  end
300
303
 
301
- str_output.string.should =~ /bt number 3/
304
+ @str_output.string.should =~ /bt number 3/
302
305
  end
303
306
 
304
307
  it 'should show error when backtrace level out of bounds' do
305
- pry_instance = Pry.new(:input => StringIO.new("cat --ex 3"), :output => str_output = StringIO.new)
308
+ pry_instance = Pry.new(:input => StringIO.new("cat --ex 3"), :output => @str_output)
306
309
  pry_instance.last_exception = mock_exception("x", "x", "x")
307
310
  pry_instance.rep(self)
308
- str_output.string.should =~ /out of bounds/
311
+ @str_output.string.should =~ /out of bounds/
309
312
  end
310
313
 
311
314
  it 'each successive cat --ex should show the next level of backtrace, and going past the final level should return to the first' do
@@ -317,18 +320,18 @@ describe "Pry::DefaultCommands::Shell" do
317
320
  end
318
321
 
319
322
  pry_instance = Pry.new(:input => StringIO.new("cat --ex\n" * 4),
320
- :output => (str_output = StringIO.new))
323
+ :output => @str_output)
321
324
 
322
325
  pry_instance.last_exception = mock_exception(*temp_files.map { |f| "#{f.path}:1" })
323
326
 
324
327
  3.times do |i|
325
328
  pry_instance.rep(self)
326
- str_output.string.should =~ /bt number #{i}/
329
+ @str_output.string.should =~ /bt number #{i}/
327
330
  end
328
331
 
329
- str_output.reopen
332
+ @str_output.reopen
330
333
  pry_instance.rep(self)
331
- str_output.string.should =~ /bt number 0/
334
+ @str_output.string.should =~ /bt number 0/
332
335
 
333
336
  temp_files.each do |file|
334
337
  file.close(true)
@@ -2,13 +2,21 @@ require 'helper'
2
2
 
3
3
  if !mri18_and_no_real_source_location?
4
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
+
5
14
  it 'should output a method\'s source' do
6
- str_output = StringIO.new
7
- redirect_pry_io(InputTester.new("show-source sample_method", "exit-all"), str_output) do
15
+ redirect_pry_io(InputTester.new("show-source sample_method", "exit-all"), @str_output) do
8
16
  pry
9
17
  end
10
18
 
11
- str_output.string.should =~ /def sample/
19
+ @str_output.string.should =~ /def sample/
12
20
  end
13
21
 
14
22
  it 'should output help' do
@@ -16,65 +24,59 @@ if !mri18_and_no_real_source_location?
16
24
  end
17
25
 
18
26
  it 'should output a method\'s source with line numbers' do
19
- str_output = StringIO.new
20
- redirect_pry_io(InputTester.new("show-source -l sample_method", "exit-all"), str_output) do
27
+ redirect_pry_io(InputTester.new("show-source -l sample_method", "exit-all"), @str_output) do
21
28
  pry
22
29
  end
23
30
 
24
- str_output.string.should =~ /\d+: def sample/
31
+ @str_output.string.should =~ /\d+: def sample/
25
32
  end
26
33
 
27
34
  it 'should output a method\'s source with line numbers starting at 1' do
28
- str_output = StringIO.new
29
- redirect_pry_io(InputTester.new("show-source -b sample_method", "exit-all"), str_output) do
35
+ redirect_pry_io(InputTester.new("show-source -b sample_method", "exit-all"), @str_output) do
30
36
  pry
31
37
  end
32
38
 
33
- str_output.string.should =~ /1: def sample/
39
+ @str_output.string.should =~ /1: def sample/
34
40
  end
35
41
 
36
42
  it 'should output a method\'s source if inside method without needing to use method name' do
37
- $str_output = StringIO.new
43
+ Pad.str_output = @str_output
38
44
 
39
- o = Object.new
40
- def o.sample
41
- redirect_pry_io(InputTester.new("show-source", "exit-all"), $str_output) do
45
+ def @o.sample
46
+ redirect_pry_io(InputTester.new("show-source", "exit-all"), Pad.str_output) do
42
47
  binding.pry
43
48
  end
44
49
  end
45
- o.sample
50
+ @o.sample
46
51
 
47
- $str_output.string.should =~ /def o.sample/
48
- $str_output = nil
52
+ Pad.str_output.string.should =~ /def @o.sample/
49
53
  end
50
54
 
51
55
  it 'should output a method\'s source if inside method without needing to use method name, and using the -l switch' do
52
- $str_output = StringIO.new
56
+ Pad.str_output = @str_output
53
57
 
54
- o = Object.new
55
- def o.sample
56
- redirect_pry_io(InputTester.new("show-source -l", "exit-all"), $str_output) do
58
+ def @o.sample
59
+ redirect_pry_io(InputTester.new("show-source -l", "exit-all"), Pad.str_output) do
57
60
  binding.pry
58
61
  end
59
62
  end
60
- o.sample
63
+ @o.sample
61
64
 
62
- $str_output.string.should =~ /\d+: def o.sample/
63
- $str_output = nil
65
+ Pad.str_output.string.should =~ /def @o.sample/
64
66
  end
65
67
 
66
68
  it "should find methods even if there are spaces in the arguments" do
67
- o = Object.new
68
- def o.foo(*bars);
69
+ def @o.foo(*bars)
69
70
  "Mr flibble"
70
- self;
71
+ self
71
72
  end
72
73
 
73
- str_output = StringIO.new
74
- redirect_pry_io(InputTester.new("show-source o.foo('bar', 'baz bam').foo", "exit-all"), str_output) do
74
+ redirect_pry_io(InputTester.new("show-source @o.foo('bar', 'baz bam').foo",
75
+ "exit-all"), @str_output) do
75
76
  binding.pry
76
77
  end
77
- str_output.string.should =~ /Mr flibble/
78
+
79
+ @str_output.string.should =~ /Mr flibble/
78
80
  end
79
81
 
80
82
  it "should find methods even if the object has an overridden method method" do
@@ -145,54 +147,49 @@ if !mri18_and_no_real_source_location?
145
147
  end
146
148
 
147
149
  it "should not raise an exception when a non-extant super method is requested" do
148
- o = Object.new
149
- def o.foo(*bars); end
150
+ def @o.foo(*bars); end
150
151
 
151
- mock_pry(binding, "show-source --super o.foo").should =~ /'self.foo' has no super method/
152
+ mock_pry(binding, "show-source --super @o.foo").should =~ /'self.foo' has no super method/
152
153
  end
153
154
 
154
155
  # dynamically defined method source retrieval is only supported in
155
156
  # 1.9 - where Method#source_location is native
156
157
  if RUBY_VERSION =~ /1.9/
157
158
  it 'should output a method\'s source for a method defined inside pry' do
158
- str_output = StringIO.new
159
- redirect_pry_io(InputTester.new("def dyna_method", ":testing", "end", "show-source dyna_method"), str_output) do
159
+ redirect_pry_io(InputTester.new("def dyna_method", ":testing", "end", "show-source dyna_method"), @str_output) do
160
160
  TOPLEVEL_BINDING.pry
161
161
  end
162
162
 
163
- str_output.string.should =~ /def dyna_method/
163
+ @str_output.string.should =~ /def dyna_method/
164
164
  Object.remove_method :dyna_method
165
165
  end
166
166
 
167
167
  it 'should output a method\'s source for a method defined inside pry, even if exceptions raised before hand' do
168
- str_output = StringIO.new
169
- 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
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
170
169
  TOPLEVEL_BINDING.pry
171
170
  end
172
171
 
173
- str_output.string.should =~ /def dyna_method/
172
+ @str_output.string.should =~ /def dyna_method/
174
173
  Object.remove_method :dyna_method
175
174
  end
176
175
 
177
176
  it 'should output an instance method\'s source for a method defined inside pry' do
178
- str_output = StringIO.new
179
177
  Object.remove_const :A if defined?(A)
180
- redirect_pry_io(InputTester.new("class A", "def yo", "end", "end", "show-source A#yo"), str_output) do
178
+ redirect_pry_io(InputTester.new("class A", "def yo", "end", "end", "show-source A#yo"), @str_output) do
181
179
  TOPLEVEL_BINDING.pry
182
180
  end
183
181
 
184
- str_output.string.should =~ /def yo/
182
+ @str_output.string.should =~ /def yo/
185
183
  Object.remove_const :A
186
184
  end
187
185
 
188
186
  it 'should output an instance method\'s source for a method defined inside pry using define_method' do
189
- str_output = StringIO.new
190
187
  Object.remove_const :A if defined?(A)
191
- redirect_pry_io(InputTester.new("class A", "define_method(:yup) {}", "end", "show-source A#yup"), str_output) do
188
+ redirect_pry_io(InputTester.new("class A", "define_method(:yup) {}", "end", "show-source A#yup"), @str_output) do
192
189
  TOPLEVEL_BINDING.pry
193
190
  end
194
191
 
195
- str_output.string.should =~ /define_method\(:yup\)/
192
+ @str_output.string.should =~ /define_method\(:yup\)/
196
193
  Object.remove_const :A
197
194
  end
198
195
  end
@@ -289,6 +286,9 @@ if !mri18_and_no_real_source_location?
289
286
  end
290
287
  end
291
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
292
  describe "show-source -a" do
293
293
  it 'should show the source for all monkeypatches defined in different files' do
294
294
  class TestClassForShowSource
@@ -300,7 +300,133 @@ if !mri18_and_no_real_source_location?
300
300
  result.should =~ /def alpha/
301
301
  result.should =~ /def beta/
302
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
303
428
  end
304
429
  end
305
430
  end
306
431
  end
432
+