pry 0.9.10pre1-java → 0.9.11-java

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
File without changes
@@ -0,0 +1,277 @@
1
+ require 'helper'
2
+
3
+ describe Pry::CodeObject do
4
+ describe "basic lookups" do
5
+ before do
6
+ @obj = Object.new
7
+ def @obj.ziggy
8
+ "a flight of scarlet pigeons thunders round my thoughts"
9
+ end
10
+
11
+ class ClassyWassy
12
+ def piggy
13
+ binding
14
+ end
15
+ end
16
+
17
+ @p = Pry.new
18
+ @p.binding_stack = [binding]
19
+ end
20
+
21
+ after do
22
+ Object.remove_const(:ClassyWassy)
23
+ end
24
+
25
+ it 'should lookup methods' do
26
+ m = Pry::CodeObject.lookup("@obj.ziggy", @p)
27
+ m.is_a?(Pry::Method).should == true
28
+ m.name.to_sym.should == :ziggy
29
+ end
30
+
31
+ it 'should lookup modules' do
32
+ m = Pry::CodeObject.lookup("ClassyWassy", @p)
33
+ m.is_a?(Pry::WrappedModule).should == true
34
+ m.source.should =~ /piggy/
35
+ end
36
+
37
+ it 'should lookup procs' do
38
+ my_proc = proc { :hello }
39
+ @p.binding_stack = [binding]
40
+ m = Pry::CodeObject.lookup("my_proc", @p)
41
+ m.is_a?(Pry::Method).should == true
42
+ m.source.should =~ /hello/
43
+ end
44
+
45
+ describe 'commands lookup' do
46
+ before do
47
+ @p = Pry.new
48
+ @p.binding_stack = [binding]
49
+ end
50
+
51
+ it 'should return command class' do
52
+ @p.commands.command "jeremy-jones" do
53
+ "lobster"
54
+ end
55
+ m = Pry::CodeObject.lookup("jeremy-jones", @p)
56
+ (m <= Pry::Command).should == true
57
+ m.source.should =~ /lobster/
58
+ end
59
+
60
+ describe "class commands" do
61
+ before do
62
+ class LobsterLady < Pry::ClassCommand
63
+ match "lobster-lady"
64
+ description "nada."
65
+ def process
66
+ "lobster"
67
+ end
68
+ end
69
+ end
70
+
71
+ after do
72
+ Object.remove_const(:LobsterLady)
73
+ end
74
+
75
+ it 'should return Pry::ClassCommand class when looking up class command' do
76
+ Pry.commands.add_command(LobsterLady)
77
+ m = Pry::CodeObject.lookup("lobster-lady", @p)
78
+ (m <= Pry::ClassCommand).should == true
79
+ m.source.should =~ /class LobsterLady/
80
+ Pry.commands.delete("lobster-lady")
81
+ end
82
+
83
+ it 'should return Pry::WrappedModule when looking up command class directly (as a class, not as a command)' do
84
+ Pry.commands.add_command(LobsterLady)
85
+ m = Pry::CodeObject.lookup("LobsterLady", @p)
86
+ m.is_a?(Pry::WrappedModule).should == true
87
+ m.source.should =~ /class LobsterLady/
88
+ Pry.commands.delete("lobster-lady")
89
+ end
90
+ end
91
+
92
+ it 'looks up commands by :listing name as well' do
93
+ @p.commands.command /jeremy-.*/, "", :listing => "jeremy-baby" do
94
+ "lobster"
95
+ end
96
+ m = Pry::CodeObject.lookup("jeremy-baby", @p)
97
+ (m <= Pry::Command).should == true
98
+ m.source.should =~ /lobster/
99
+ end
100
+
101
+ it 'finds nothing when passing nil as the first argument' do
102
+ Pry::CodeObject.lookup(nil, @p).should == nil
103
+ end
104
+
105
+ end
106
+
107
+ it 'should lookup instance methods defined on classes accessed via local variable' do
108
+ o = Class.new do
109
+ def princess_bubblegum
110
+ "mathematic!"
111
+ end
112
+ end
113
+
114
+ @p.binding_stack = [binding]
115
+ m = Pry::CodeObject.lookup("o#princess_bubblegum", @p)
116
+ m.is_a?(Pry::Method).should == true
117
+ m.source.should =~ /mathematic!/
118
+ end
119
+
120
+ it 'should lookup class methods defined on classes accessed via local variable' do
121
+ o = Class.new do
122
+ def self.finn
123
+ "4 realzies"
124
+ end
125
+ end
126
+ @p.binding_stack = [binding]
127
+ m = Pry::CodeObject.lookup("o.finn", @p)
128
+ m.is_a?(Pry::Method).should == true
129
+ m.source.should =~ /4 realzies/
130
+ end
131
+
132
+ it 'should lookup the class of an object (when given a variable)' do
133
+ moddy = ClassyWassy.new
134
+ @p.binding_stack = [binding]
135
+ m = Pry::CodeObject.lookup("moddy", @p)
136
+ m.is_a?(Pry::WrappedModule).should == true
137
+ m.source.should =~ /piggy/
138
+ end
139
+
140
+ describe "inferring object from binding when lookup str is empty/nil" do
141
+ before do
142
+ @b1 = Pry.binding_for(ClassyWassy)
143
+ @b2 = Pry.binding_for(ClassyWassy.new)
144
+ end
145
+
146
+ describe "infer module objects" do
147
+ it 'should infer module object when binding self is a module' do
148
+ ["", nil].each do |v|
149
+ @p.binding_stack = [@b1]
150
+ m = Pry::CodeObject.lookup(v, @p)
151
+ m.is_a?(Pry::WrappedModule).should == true
152
+ m.name.should =~ /ClassyWassy/
153
+ end
154
+ end
155
+
156
+ it 'should infer module object when binding self is an instance' do
157
+ ["", nil].each do |v|
158
+ @p.binding_stack = [@b2]
159
+ m = Pry::CodeObject.lookup(v, @p)
160
+ m.is_a?(Pry::WrappedModule).should == true
161
+ m.name.should =~ /ClassyWassy/
162
+ end
163
+ end
164
+ end
165
+
166
+ describe "infer method objects" do
167
+ it 'should infer method object from binding when inside method context' do
168
+ b = ClassyWassy.new.piggy
169
+
170
+ ["", nil].each do |v|
171
+ @p.binding_stack = [b]
172
+ m = Pry::CodeObject.lookup(v, @p)
173
+ m.is_a?(Pry::Method).should == true
174
+ m.name.should =~ /piggy/
175
+ end
176
+ end
177
+ end
178
+ end
179
+ end
180
+
181
+ describe "lookups with :super" do
182
+ before do
183
+ class MyClassyWassy; end
184
+ class CuteSubclass < MyClassyWassy; end
185
+ @p = Pry.new
186
+ @p.binding_stack = [binding]
187
+ end
188
+
189
+ after do
190
+ Object.remove_const(:MyClassyWassy)
191
+ Object.remove_const(:CuteSubclass)
192
+ end
193
+
194
+ it 'should lookup original class with :super => 0' do
195
+ m = Pry::CodeObject.lookup("CuteSubclass", @p, :super => 0)
196
+ m.is_a?(Pry::WrappedModule).should == true
197
+ m.wrapped.should == CuteSubclass
198
+ end
199
+
200
+ it 'should lookup immediate super class with :super => 1' do
201
+ m = Pry::CodeObject.lookup("CuteSubclass", @p, :super => 1)
202
+ m.is_a?(Pry::WrappedModule).should == true
203
+ m.wrapped.should == MyClassyWassy
204
+ end
205
+
206
+ it 'should ignore :super parameter for commands' do
207
+ p = Pry.new
208
+ p.commands.command "jeremy-jones" do
209
+ "lobster"
210
+ end
211
+ p.binding_stack = [binding]
212
+ m = Pry::CodeObject.lookup("jeremy-jones", p, :super => 10)
213
+ m.source.should =~ /lobster/
214
+ end
215
+ end
216
+
217
+ describe "precedence" do
218
+ before do
219
+ class ClassyWassy
220
+ class Puff
221
+ def tiggy
222
+ end
223
+ end
224
+
225
+ def Puff
226
+ end
227
+
228
+ def piggy
229
+ end
230
+ end
231
+
232
+ Object.class_eval do
233
+ def ClassyWassy
234
+ :ducky
235
+ end
236
+ end
237
+
238
+ @p = Pry.new
239
+ @p.binding_stack = [binding]
240
+ end
241
+
242
+ after do
243
+ Object.remove_const(:ClassyWassy)
244
+ Object.remove_method(:ClassyWassy)
245
+ end
246
+
247
+ it 'should look up methods before classes (at top-level)' do
248
+ m = Pry::CodeObject.lookup("ClassyWassy", @p)
249
+ m.is_a?(Pry::Method).should == true
250
+ m.source.should =~ /ducky/
251
+ end
252
+
253
+ it 'should look up classes before methods when namespaced' do
254
+ m = Pry::CodeObject.lookup("ClassyWassy::Puff", @p)
255
+ m.is_a?(Pry::WrappedModule).should == true
256
+ m.source.should =~ /tiggy/
257
+ end
258
+
259
+ it 'should look up locals before methods' do
260
+ b = Pry.binding_for(ClassyWassy)
261
+ b.eval("piggy = Puff.new")
262
+ @p.binding_stack = [b]
263
+ o = Pry::CodeObject.lookup("piggy", @p)
264
+ o.is_a?(Pry::WrappedModule).should == true
265
+ end
266
+
267
+ # actually locals are never looked up (via co.default_lookup) when they're classes, it
268
+ # just falls through to co.method_or_class
269
+ it 'should look up classes before locals' do
270
+ c = ClassyWassy
271
+ @p.binding_stack = [binding]
272
+ o = Pry::CodeObject.lookup("c", @p)
273
+ o.is_a?(Pry::WrappedModule).should == true
274
+ o.wrapped.should == ClassyWassy
275
+ end
276
+ end
277
+ end
@@ -7,7 +7,7 @@ describe Pry::Code do
7
7
  end
8
8
 
9
9
  should 'read lines from Pry\'s line buffer' do
10
- mock_pry(':hay_guys')
10
+ pry_eval ':hay_guys'
11
11
  Pry::Code.from_file('(pry)').grep(/:hay_guys/).length.should == 1
12
12
  end
13
13
 
@@ -23,11 +23,29 @@ describe Pry::Code do
23
23
  end
24
24
  end
25
25
 
26
+ should 'use the provided extension' do
27
+ temp_file('.c') do |f|
28
+ Pry::Code.from_file(f.path, :ruby).code_type.should == :ruby
29
+ end
30
+ end
31
+
26
32
  should 'raise an error if the file doesn\'t exist' do
27
33
  proc do
28
34
  Pry::Code.from_file('/knalkjsdnalsd/alkjdlkq')
29
35
  end.should.raise(MethodSource::SourceNotFoundError)
30
36
  end
37
+
38
+ should 'check for files relative to origin pwd' do
39
+ Dir.chdir('spec') do |f|
40
+ Pry::Code.from_file('spec/' + File.basename(__FILE__)).code_type.should == :ruby
41
+ end
42
+ end
43
+
44
+ should 'find files that are relative to the current working directory' do
45
+ Dir.chdir('spec') do |f|
46
+ Pry::Code.from_file(File.basename(__FILE__)).code_type.should == :ruby
47
+ end
48
+ end
31
49
  end
32
50
 
33
51
  describe '.from_method' do
@@ -1,5 +1,6 @@
1
1
  require 'helper'
2
2
 
3
+
3
4
  describe "commands" do
4
5
  before do
5
6
  @str_output = StringIO.new
@@ -12,6 +13,16 @@ describe "commands" do
12
13
 
13
14
  @self = "Pad.self = self"
14
15
 
16
+ @command_tester = Pry::CommandSet.new do
17
+ command "command1", "command 1 test" do
18
+ output.puts "command1"
19
+ end
20
+
21
+ command "command2", "command 2 test" do |arg|
22
+ output.puts arg
23
+ end
24
+ end
25
+
15
26
  Pad.bong = "bong"
16
27
  end
17
28
 
@@ -46,17 +57,10 @@ describe "commands" do
46
57
  alias_command "test-alias", "test-command"
47
58
  end
48
59
 
49
- redirect_pry_io(InputTester.new("test-command hello baby duck"), out1 = StringIO.new) do
50
- Pry.start self, :commands => set
51
- end
52
-
53
- out1.string.should =~ /hello baby duck/
54
-
55
- redirect_pry_io(InputTester.new("test-alias hello baby duck"), out2 = StringIO.new) do
56
- Pry.start self, :commands => set
57
- end
60
+ t = pry_tester(:commands => set)
58
61
 
59
- out2.string.should == out1.string
62
+ t.process_command "test-alias hello baby duck"
63
+ t.last_output.should =~ /testing hello baby duck/
60
64
  end
61
65
 
62
66
  it 'should pass option arguments to original' do
@@ -66,17 +70,10 @@ describe "commands" do
66
70
  end
67
71
 
68
72
  obj = Class.new { @x = 10 }
69
- redirect_pry_io(InputTester.new("ls -i"), out1 = StringIO.new) do
70
- Pry.start obj, :commands => set
71
- end
72
-
73
- out1.string.should =~ /@x/
74
-
75
- redirect_pry_io(InputTester.new("test-alias -i"), out2 = StringIO.new) do
76
- Pry.start obj, :commands => set
77
- end
73
+ t = pry_tester(obj, :commands => set)
78
74
 
79
- out2.string.should == out1.string
75
+ t.process_command "test-alias -i"
76
+ t.last_output.should =~ /@x/
80
77
  end
81
78
 
82
79
  it 'should pass option arguments to original with additional parameters' do
@@ -86,17 +83,9 @@ describe "commands" do
86
83
  end
87
84
 
88
85
  obj = Class.new { @x = Class.new { define_method(:plymouth) {} } }
89
- redirect_pry_io(InputTester.new("ls -M @x"), out1 = StringIO.new) do
90
- Pry.start obj, :commands => set
91
- end
92
-
93
- out1.string.should =~ /plymouth/
94
-
95
- redirect_pry_io(InputTester.new("test-alias @x"), out2 = StringIO.new) do
96
- Pry.start obj, :commands => set
97
- end
98
-
99
- out2.string.should == out1.string
86
+ t = pry_tester(obj, :commands => set)
87
+ t.process_command "test-alias @x"
88
+ t.last_output.should =~ /plymouth/
100
89
  end
101
90
 
102
91
  it 'should be able to alias a regex command' do
@@ -107,11 +96,9 @@ describe "commands" do
107
96
  alias_command "test-alias", "duck"
108
97
  end
109
98
 
110
- redirect_pry_io(InputTester.new("test-alias"), out1 = StringIO.new) do
111
- Pry.start self, :commands => set
112
- end
113
-
114
- out1.string.should =~ /ducky/
99
+ t = pry_tester(:commands => set)
100
+ t.process_command "test-alias"
101
+ t.last_output.should =~ /ducky/
115
102
  end
116
103
 
117
104
  it 'should be able to make the alias a regex' do
@@ -138,6 +125,7 @@ describe "commands" do
138
125
  run "cd / "
139
126
  end
140
127
  end
128
+
141
129
  redirect_pry_io(InputTester.new("cd 1/2/3/4/5/6", @bs1, "test-run",
142
130
  @self, @bs2, "exit-all")) do
143
131
  Pry.start(@o, :commands => set)
@@ -242,10 +230,10 @@ describe "commands" do
242
230
 
243
231
  describe "Pry#run_command" do
244
232
  it 'should run a command in a specified context' do
245
- b = Pry.binding_for(7)
233
+ b = Pry.binding_for('seven')
246
234
  p = Pry.new(:output => @str_output)
247
235
  p.run_command("ls -m", "", b)
248
- p.output.string.should =~ /divmod/
236
+ p.output.string.should =~ /downcase/
249
237
  end
250
238
 
251
239
  it 'should run a command that modifies the passed in eval_string' do
@@ -258,7 +246,10 @@ describe "commands" do
258
246
  end
259
247
 
260
248
  it 'should run a command in the context of a session' do
261
- mock_pry("@session_ivar = 10", "_pry_.run_command('ls')").should =~ /@session_ivar/
249
+ pry_tester.tap do |t|
250
+ t.eval "@session_ivar = 10", "_pry_.run_command('ls')"
251
+ t.last_output.should =~ /@session_ivar/
252
+ end
262
253
  end
263
254
  end
264
255
 
@@ -417,7 +408,7 @@ describe "commands" do
417
408
  it 'should create a command in a nested context and that command should be accessible from the parent' do
418
409
  x = "@x=nil\ncd 7\n_pry_.commands.instance_eval {\ncommand('bing') { |arg| run arg }\n}\ncd ..\nbing ls\nexit-all"
419
410
  redirect_pry_io(StringIO.new("@x=nil\ncd 7\n_pry_.commands.instance_eval {\ncommand('bing') { |arg| run arg }\n}\ncd ..\nbing ls\nexit-all"), @str_output) do
420
- Pry.new.repl(0)
411
+ Pry.new.repl('0')
421
412
  end
422
413
 
423
414
  @str_output.string.should =~ /@x/
@@ -482,7 +473,6 @@ describe "commands" do
482
473
  @str_output.string.should =~ /6/
483
474
  end
484
475
 
485
-
486
476
  it 'a command (with :keep_retval => true) that replaces eval_string with a valid expression should overwrite the eval_string with the return value' do
487
477
  klass = Pry::CommandSet.new do
488
478
  command "hello", "", :keep_retval => true do
@@ -546,7 +536,9 @@ describe "commands" do
546
536
  end
547
537
 
548
538
  it 'should change description of a command using desc' do
549
- klass = Pry::CommandSet.new do; import Pry::DefaultCommands::Help; end
539
+ klass = Pry::CommandSet.new do
540
+ import Pry::Commands
541
+ end
550
542
  orig = klass.commands["help"].description
551
543
  klass.instance_eval do
552
544
  desc "help", "blah"
@@ -626,9 +618,9 @@ describe "commands" do
626
618
 
627
619
  it 'should run a command with no parameter' do
628
620
  pry_tester = Pry.new
629
- pry_tester.commands = CommandTester
621
+ pry_tester.commands = @command_tester
630
622
  pry_tester.input = InputTester.new("command1", "exit-all")
631
- pry_tester.commands = CommandTester
623
+ pry_tester.commands = @command_tester
632
624
 
633
625
  pry_tester.output = @str_output
634
626
 
@@ -639,9 +631,9 @@ describe "commands" do
639
631
 
640
632
  it 'should run a command with one parameter' do
641
633
  pry_tester = Pry.new
642
- pry_tester.commands = CommandTester
634
+ pry_tester.commands = @command_tester
643
635
  pry_tester.input = InputTester.new("command2 horsey", "exit-all")
644
- pry_tester.commands = CommandTester
636
+ pry_tester.commands = @command_tester
645
637
 
646
638
  pry_tester.output = @str_output
647
639