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
@@ -40,7 +40,7 @@ describe "test Pry defaults" do
40
40
  end
41
41
  end.new
42
42
 
43
- Pry.start(self, :input => arity_one_input, :output => Pry::NullOutput)
43
+ Pry.start(self, :input => arity_one_input, :output => StringIO.new)
44
44
  arity_one_input.prompt.should == Pry.prompt.call
45
45
  end
46
46
 
@@ -53,7 +53,7 @@ describe "test Pry defaults" do
53
53
  end
54
54
  end.new
55
55
 
56
- lambda { Pry.start(self, :input => arity_zero_input, :output => Pry::NullOutput) }.should.not.raise Exception
56
+ lambda { Pry.start(self, :input => arity_zero_input, :output => StringIO.new) }.should.not.raise Exception
57
57
  end
58
58
 
59
59
  it 'should not pass in the prompt if the arity is -1' do
@@ -68,7 +68,7 @@ describe "test Pry defaults" do
68
68
  end
69
69
  end.new
70
70
 
71
- Pry.start(self, :input => arity_multi_input, :output => Pry::NullOutput)
71
+ Pry.start(self, :input => arity_multi_input, :output => StringIO.new)
72
72
  arity_multi_input.prompt.should == nil
73
73
  end
74
74
 
@@ -92,12 +92,12 @@ describe "test Pry defaults" do
92
92
  end
93
93
 
94
94
  it "should set the print default, and the default should be overridable" do
95
- new_print = proc { |out, value| out.puts value }
95
+ new_print = proc { |out, value| out.puts "=> LOL" }
96
96
  Pry.print = new_print
97
97
 
98
98
  Pry.new.print.should == Pry.print
99
99
  Pry.new(:input => InputTester.new("\"test\""), :output => @str_output).rep
100
- @str_output.string.should == "test\n"
100
+ @str_output.string.should == "=> LOL\n"
101
101
 
102
102
  @str_output = StringIO.new
103
103
  Pry.new(:input => InputTester.new("\"test\""), :output => @str_output,
@@ -107,28 +107,28 @@ describe "test Pry defaults" do
107
107
  Pry.new.print.should == Pry.print
108
108
  @str_output = StringIO.new
109
109
  Pry.new(:input => InputTester.new("\"test\""), :output => @str_output).rep
110
- @str_output.string.should == "test\n"
110
+ @str_output.string.should == "=> LOL\n"
111
111
  end
112
112
 
113
113
  describe "pry return values" do
114
114
  it 'should return nil' do
115
- Pry.start(self, :input => StringIO.new("exit-all"), :output => Pry::NullOutput).should == nil
115
+ Pry.start(self, :input => StringIO.new("exit-all"), :output => StringIO.new).should == nil
116
116
  end
117
117
 
118
118
  it 'should return the parameter given to exit-all' do
119
- Pry.start(self, :input => StringIO.new("exit-all 10"), :output => Pry::NullOutput).should == 10
119
+ Pry.start(self, :input => StringIO.new("exit-all 10"), :output => StringIO.new).should == 10
120
120
  end
121
121
 
122
122
  it 'should return the parameter (multi word string) given to exit-all' do
123
- Pry.start(self, :input => StringIO.new("exit-all \"john mair\""), :output => Pry::NullOutput).should == "john mair"
123
+ Pry.start(self, :input => StringIO.new("exit-all \"john mair\""), :output => StringIO.new).should == "john mair"
124
124
  end
125
125
 
126
126
  it 'should return the parameter (function call) given to exit-all' do
127
- Pry.start(self, :input => StringIO.new("exit-all 'abc'.reverse"), :output => Pry::NullOutput).should == 'cba'
127
+ Pry.start(self, :input => StringIO.new("exit-all 'abc'.reverse"), :output => StringIO.new).should == 'cba'
128
128
  end
129
129
 
130
130
  it 'should return the parameter (self) given to exit-all' do
131
- Pry.start("carl", :input => StringIO.new("exit-all self"), :output => Pry::NullOutput).should == "carl"
131
+ Pry.start("carl", :input => StringIO.new("exit-all self"), :output => StringIO.new).should == "carl"
132
132
  end
133
133
  end
134
134
 
@@ -355,17 +355,17 @@ describe "test Pry defaults" do
355
355
 
356
356
  describe 'toplevel_binding' do
357
357
  it 'should be devoid of local variables' do
358
- mock_pry(Pry.toplevel_binding, "ls -l").should.not =~ /version/
358
+ pry_eval(Pry.toplevel_binding, "ls -l").should.not =~ /version/
359
359
  end
360
360
 
361
361
  it 'should have self the same as TOPLEVEL_BINDING' do
362
- mock_pry(Pry.toplevel_binding, "self.equal? TOPLEVEL_BINDING.eval('self')").should =~ /=> true/
362
+ Pry.toplevel_binding.eval('self').should.equal? TOPLEVEL_BINDING.eval('self')
363
363
  end
364
364
 
365
365
  # https://github.com/rubinius/rubinius/issues/1779
366
366
  unless Pry::Helpers::BaseHelpers.rbx?
367
367
  it 'should define private methods on Object' do
368
- mock_pry(TOPLEVEL_BINDING, "def gooey_fooey; end")
368
+ TOPLEVEL_BINDING.eval 'def gooey_fooey; end'
369
369
  method(:gooey_fooey).owner.should == Object
370
370
  Pry::Method(method(:gooey_fooey)).visibility.should == :private
371
371
  end
@@ -23,6 +23,21 @@ describe Pry do
23
23
  Pry.history.restore_default_behavior
24
24
  end
25
25
 
26
+ describe '#push' do
27
+ it "should not record duplicated lines" do
28
+ Pry.history << '3'
29
+ Pry.history << '_ += 1'
30
+ Pry.history << '_ += 1'
31
+ Pry.history.to_a.grep('_ += 1').count.should == 1
32
+ end
33
+
34
+ it "should not record empty lines" do
35
+ c = Pry.history.to_a.count
36
+ Pry.history << ''
37
+ Pry.history.to_a.count.should == c
38
+ end
39
+ end
40
+
26
41
  describe ".load_history" do
27
42
  it "should read the contents of the file" do
28
43
  Pry.history.to_a[-2..-1].should == %w(2 3)
@@ -0,0 +1,95 @@
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("[1]").should =~ /^=> \[1\]/
35
+ end
36
+
37
+ it "should include the =>" do
38
+ accumulator = StringIO.new
39
+ Pry.config.print.call(accumulator, [1])
40
+ accumulator.string.should == "=> \[1\]\n"
41
+ end
42
+
43
+ it "should not be phased by un-inspectable things" do
44
+ mock_pry("class NastyClass; undef pretty_inspect; end", "NastyClass.new").should =~ /#<.*NastyClass:0x.*?>/
45
+ end
46
+ end
47
+
48
+ describe "color" do
49
+ before do
50
+ Pry.color = true
51
+ end
52
+
53
+ after do
54
+ Pry.color = false
55
+ end
56
+
57
+ it "should colorize strings as though they were ruby" do
58
+ accumulator = StringIO.new
59
+ Pry.config.print.call(accumulator, [1])
60
+ accumulator.string.should == "=> [\e[1;34m1\e[0m]\e[0m\n"
61
+ end
62
+
63
+ it "should not colorize strings that already include color" do
64
+ f = Object.new
65
+ def f.inspect
66
+ "\e[1;31mFoo\e[0m"
67
+ end
68
+ accumulator = StringIO.new
69
+ Pry.config.print.call(accumulator, f)
70
+ # We add an extra \e[0m to prevent color leak
71
+ accumulator.string.should == "=> \e[1;31mFoo\e[0m\e[0m\n"
72
+ end
73
+ end
74
+
75
+ describe "output suppression" do
76
+ before do
77
+ @t = pry_tester
78
+ end
79
+ it "should normally output the result" do
80
+ mock_pry("1 + 2").should == "=> 3\n\n"
81
+ end
82
+
83
+ it "should not output anything if the input ends with a semicolon" do
84
+ mock_pry("1 + 2;").should == "\n"
85
+ end
86
+
87
+ it "should output something if the input ends with a comment" do
88
+ mock_pry("1 + 2 # basic addition").should == "=> 3\n\n"
89
+ end
90
+
91
+ it "should not output something if the input is only a comment" do
92
+ mock_pry("# basic addition").should == "\n"
93
+ end
94
+ end
95
+ end
@@ -20,6 +20,35 @@ describe Pry do
20
20
  end
21
21
  end
22
22
 
23
+ describe 'DISABLE_PRY' do
24
+ before do
25
+ ENV['DISABLE_PRY'] = 'true'
26
+ end
27
+
28
+ after do
29
+ ENV.delete 'DISABLE_PRY'
30
+ end
31
+
32
+ it 'should not binding.pry' do
33
+ binding.pry.should == nil
34
+ end
35
+
36
+ it 'should not Pry.start' do
37
+ Pry.start.should == nil
38
+ end
39
+ end
40
+
41
+ describe "Pry.critical_section" do
42
+ it "should prevent Pry being called" do
43
+ output = StringIO.new
44
+ Pry.output = output
45
+ Pry.critical_section do
46
+ Pry.start
47
+ end
48
+ output.string.should =~ /Pry started inside Pry/
49
+ end
50
+ end
51
+
23
52
  describe "Pry.binding_for" do
24
53
 
25
54
  # regression test for burg's bug (see git history)
@@ -31,6 +60,12 @@ describe Pry do
31
60
 
32
61
  lambda { Pry.binding_for(o) }.should.not.raise Exception
33
62
  end
63
+
64
+ it "should not leak local variables" do
65
+ [Object.new, Array, 3].each do |obj|
66
+ Pry.binding_for(obj).eval("local_variables").should.be.empty
67
+ end
68
+ end
34
69
  end
35
70
 
36
71
  describe "open a Pry session on an object" do
@@ -72,16 +107,14 @@ describe Pry do
72
107
  input = InputTester.new(input_string)
73
108
  o = Object.new
74
109
 
75
- pry_tester = Pry.new(:input => input, :output => Pry::NullOutput)
110
+ pry_tester = Pry.new(:input => input, :output => StringIO.new)
76
111
  pry_tester.rep(o)
77
112
  o.instance_variable_get(:@x).should == 10
78
113
  end
79
114
 
80
- it 'should display error and throw(:breakout) if Pry instance runs out of input' do
81
- catch(:breakout) do
82
- redirect_pry_io(StringIO.new(":nothing\n"), @str_output) do
83
- Pry.new.repl
84
- end
115
+ it 'should display error if Pry instance runs out of input' do
116
+ redirect_pry_io(StringIO.new, @str_output) do
117
+ Pry.new.repl
85
118
  end
86
119
  @str_output.string.should =~ /Error: Pry ran out of things to read/
87
120
  end
@@ -103,7 +136,7 @@ describe Pry do
103
136
  end
104
137
 
105
138
  it 'should define a nested class under Hello and not on top-level or Pry' do
106
- pry_tester = Pry.new(:input => InputTester.new("class Nested", "end"), :output => Pry::NullOutput)
139
+ pry_tester = Pry.new(:input => InputTester.new("class Nested", "end"), :output => StringIO.new)
107
140
  pry_tester.rep(Hello)
108
141
  Hello.const_defined?(:Nested).should == true
109
142
  end
@@ -171,7 +204,7 @@ describe Pry do
171
204
 
172
205
  o = Object.new
173
206
 
174
- pry_tester = Pry.start(o, :input => input, :output => Pry::NullOutput)
207
+ pry_tester = Pry.start(o, :input => input, :output => StringIO.new)
175
208
 
176
209
  o.instance_variable_get(:@x).should == 10
177
210
  end
@@ -190,7 +223,7 @@ describe Pry do
190
223
  it 'sets _ to the last result' do
191
224
  res = []
192
225
  input = InputTester.new *[":foo", "self << _", "42", "self << _"]
193
- pry = Pry.new(:input => input, :output => Pry::NullOutput)
226
+ pry = Pry.new(:input => input, :output => StringIO.new)
194
227
  pry.repl(res)
195
228
 
196
229
  res.should == [:foo, 42]
@@ -199,7 +232,7 @@ describe Pry do
199
232
  it 'sets out to an array with the result' do
200
233
  res = {}
201
234
  input = InputTester.new *[":foo", "42", "self[:res] = _out_"]
202
- pry = Pry.new(:input => input, :output => Pry::NullOutput)
235
+ pry = Pry.new(:input => input, :output => StringIO.new)
203
236
  pry.repl(res)
204
237
 
205
238
  res[:res].should.be.kind_of Pry::HistoryArray
@@ -209,7 +242,7 @@ describe Pry do
209
242
  it 'sets _in_ to an array with the entered lines' do
210
243
  res = {}
211
244
  input = InputTester.new *[":foo", "42", "self[:res] = _in_"]
212
- pry = Pry.new(:input => input, :output => Pry::NullOutput)
245
+ pry = Pry.new(:input => input, :output => StringIO.new)
213
246
  pry.repl(res)
214
247
 
215
248
  res[:res].should.be.kind_of Pry::HistoryArray
@@ -219,7 +252,7 @@ describe Pry do
219
252
  it 'uses 100 as the size of _in_ and _out_' do
220
253
  res = []
221
254
  input = InputTester.new *["self << _out_.max_size << _in_.max_size"]
222
- pry = Pry.new(:input => input, :output => Pry::NullOutput)
255
+ pry = Pry.new(:input => input, :output => StringIO.new)
223
256
  pry.repl(res)
224
257
 
225
258
  res.should == [100, 100]
@@ -228,7 +261,7 @@ describe Pry do
228
261
  it 'can change the size of the history arrays' do
229
262
  res = []
230
263
  input = InputTester.new *["self << _out_.max_size << _in_.max_size"]
231
- pry = Pry.new(:input => input, :output => Pry::NullOutput,
264
+ pry = Pry.new(:input => input, :output => StringIO.new,
232
265
  :memory_size => 1000)
233
266
  pry.repl(res)
234
267
 
@@ -238,7 +271,7 @@ describe Pry do
238
271
  it 'store exceptions' do
239
272
  res = []
240
273
  input = InputTester.new *["foo!","self << _in_[-1] << _out_[-1]"]
241
- pry = Pry.new(:input => input, :output => Pry::NullOutput,
274
+ pry = Pry.new(:input => input, :output => StringIO.new,
242
275
  :memory_size => 1000)
243
276
  pry.repl(res)
244
277
 
@@ -249,44 +282,51 @@ describe Pry do
249
282
 
250
283
  describe "last_result" do
251
284
  it "should be set to the most recent value" do
252
- mock_pry("2", "_ + 82").should =~ /84/
285
+ pry_eval("2", "_ + 82").should == 84
253
286
  end
254
287
 
288
+ # This test needs mock_pry because the command retvals work by
289
+ # replacing the eval_string, so _ won't be modified without Pry doing
290
+ # a REPL loop.
255
291
  it "should be set to the result of a command with :keep_retval" do
256
- mock_pry("Pry::Commands.block_command '++', '', {:keep_retval => true} do |a| a.to_i + 1; end", '++ 86', '++ #{_}').should =~ /88/
292
+ Pry::Commands.block_command '++', '', :keep_retval => true do |a|
293
+ a.to_i + 1
294
+ end
295
+
296
+ mock_pry('++ 86', '++ #{_}').should =~ /88/
257
297
  end
258
298
 
259
299
  it "should be preserved over an empty line" do
260
- mock_pry("2 + 2", " ", "\t", " ", "_ + 92").should =~ /96/
300
+ pry_eval("2 + 2", " ", "\t", " ", "_ + 92").should == 96
261
301
  end
262
302
 
263
303
  it "should be preserved when evalling a command without :keep_retval" do
264
- mock_pry("2 + 2", "ls -l", "_ + 96").should =~ /100/
304
+ pry_eval("2 + 2", "ls -l", "_ + 96").should == 100
265
305
  end
266
306
  end
267
307
 
268
308
  describe "test loading rc files" do
269
-
270
309
  before do
310
+ Pry::HOME_RC_FILE.replace "spec/fixtures/testrc"
311
+ Pry::LOCAL_RC_FILE.replace "spec/fixtures/testrc/../testrc"
271
312
  Pry.instance_variable_set(:@initial_session, true)
272
313
  end
273
314
 
274
315
  after do
275
- Pry::RC_FILES.clear
316
+ Pry::HOME_RC_FILE.replace "~/.pryrc"
317
+ Pry::LOCAL_RC_FILE.replace "./.pryrc"
276
318
  Pry.config.should_load_rc = false
319
+ Object.remove_const(:TEST_RC) if defined?(TEST_RC)
277
320
  end
278
321
 
279
- it "should run the rc file only once" do
322
+ it "should never run the rc file twice" do
280
323
  Pry.config.should_load_rc = true
281
- 2.times { Pry::RC_FILES << File.expand_path("../testrc", __FILE__) }
282
324
 
283
- Pry.start(self, :input => StringIO.new("exit-all\n"), :output => Pry::NullOutput)
325
+ Pry.start(self, :input => StringIO.new("exit-all\n"), :output => StringIO.new)
284
326
  TEST_RC.should == [0]
285
327
 
286
- Pry.start(self, :input => StringIO.new("exit-all\n"), :output => Pry::NullOutput)
328
+ Pry.start(self, :input => StringIO.new("exit-all\n"), :output => StringIO.new)
287
329
  TEST_RC.should == [0]
288
-
289
- Object.remove_const(:TEST_RC)
290
330
  end
291
331
 
292
332
  it "should not load the pryrc if it cannot expand ENV[HOME]" do
@@ -294,7 +334,7 @@ describe Pry do
294
334
  old_rc = Pry.config.should_load_rc
295
335
  ENV['HOME'] = nil
296
336
  Pry.config.should_load_rc = true
297
- lambda { Pry.start(self, :input => StringIO.new("exit-all\n"), :output => Pry::NullOutput) }.should.not.raise
337
+ lambda { Pry.start(self, :input => StringIO.new("exit-all\n"), :output => StringIO.new) }.should.not.raise
298
338
 
299
339
  ENV['HOME'] = old_home
300
340
  Pry.config.should_load_rc = old_rc
@@ -302,21 +342,22 @@ describe Pry do
302
342
 
303
343
  it "should not run the rc file at all if Pry.config.should_load_rc is false" do
304
344
  Pry.config.should_load_rc = false
305
- Pry.start(self, :input => StringIO.new("exit-all\n"), :output => Pry::NullOutput)
345
+ Pry.start(self, :input => StringIO.new("exit-all\n"), :output => StringIO.new)
306
346
  Object.const_defined?(:TEST_RC).should == false
307
347
  end
308
348
 
309
349
  it "should not load the rc file if #repl method invoked" do
310
350
  Pry.config.should_load_rc = true
311
- Pry.new(:input => StringIO.new("exit-all\n"), :output => Pry::NullOutput).repl(self)
351
+ Pry.new(:input => StringIO.new("exit-all\n"), :output => StringIO.new).repl(self)
312
352
  Object.const_defined?(:TEST_RC).should == false
313
353
  Pry.config.should_load_rc = false
314
354
  end
315
355
 
316
356
  describe "that raise exceptions" do
317
357
  before do
318
- Pry::RC_FILES << File.expand_path("../testrcbad", __FILE__)
358
+ Pry::HOME_RC_FILE = "spec/fixtures/testrcbad"
319
359
  Pry.config.should_load_rc = true
360
+ Pry.config.should_load_local_rc = false
320
361
 
321
362
  putsed = nil
322
363
 
@@ -327,7 +368,7 @@ describe Pry do
327
368
  }
328
369
 
329
370
  @doing_it = lambda{
330
- Pry.start(self, :input => StringIO.new("Object::TEST_AFTER_RAISE=1\nexit-all\n"), :output => Pry::NullOutput)
371
+ Pry.start(self, :input => StringIO.new("Object::TEST_AFTER_RAISE=1\nexit-all\n"), :output => StringIO.new)
331
372
  putsed
332
373
  }
333
374
  end
@@ -349,7 +390,8 @@ describe Pry do
349
390
  end
350
391
 
351
392
  it "should output an error" do
352
- @doing_it[].should =~ /Error loading #{File.expand_path("../testrcbad", __FILE__)}: messin with ya/
393
+ @doing_it.call.split("\n").first.should ==
394
+ "Error loading spec/fixtures/testrcbad: messin with ya"
353
395
  end
354
396
  end
355
397
  end