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,29 @@
1
+ require 'helper'
2
+
3
+ describe Pry::Helpers::CommandHelpers do
4
+ before do
5
+ @helper = Pry::Helpers::CommandHelpers
6
+ end
7
+
8
+ describe "unindent" do
9
+ it "should remove the same prefix from all lines" do
10
+ @helper.unindent(" one\n two\n").should == "one\ntwo\n"
11
+ end
12
+
13
+ it "should not be phased by empty lines" do
14
+ @helper.unindent(" one\n\n two\n").should == "one\n\ntwo\n"
15
+ end
16
+
17
+ it "should only remove a common prefix" do
18
+ @helper.unindent(" one\n two\n").should == " one\ntwo\n"
19
+ end
20
+
21
+ it "should also remove tabs if present" do
22
+ @helper.unindent("\tone\n\ttwo\n").should == "one\ntwo\n"
23
+ end
24
+
25
+ it "should ignore lines starting with --" do
26
+ @helper.unindent(" one\n--\n two\n").should == "one\n--\ntwo\n"
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,562 @@
1
+ require 'helper'
2
+
3
+
4
+ describe "commands" do
5
+ before do
6
+ @str_output = StringIO.new
7
+ @o = Object.new
8
+
9
+ # Shortcuts. They save a lot of typing.
10
+ @bs1 = "Pad.bs1 = _pry_.binding_stack.dup"
11
+ @bs2 = "Pad.bs2 = _pry_.binding_stack.dup"
12
+ @bs3 = "Pad.bs3 = _pry_.binding_stack.dup"
13
+
14
+ @self = "Pad.self = self"
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
+
26
+ Pad.bong = "bong"
27
+ end
28
+
29
+ after do
30
+ Pad.clear
31
+ Pry.reset_defaults
32
+ end
33
+
34
+ describe "alias_command" do
35
+ it 'should make an aliasd command behave like its original' do
36
+ set = Pry::CommandSet.new do
37
+ command "test-command" do
38
+ output.puts "testing 1, 2, 3"
39
+ end
40
+ alias_command "test-alias", "test-command"
41
+ end
42
+
43
+ pry_tester(:commands => set).tap do |t|
44
+ t.eval('test-command').should == t.eval('test-alias')
45
+ end
46
+ end
47
+
48
+ it 'should pass on arguments to original' do
49
+ set = Pry::CommandSet.new do
50
+ command "test-command" do |*args|
51
+ output.puts "testing #{args.join(' ')}"
52
+ end
53
+ alias_command "test-alias", "test-command"
54
+ end
55
+
56
+ t = pry_tester(:commands => set)
57
+
58
+ t.process_command "test-alias hello baby duck"
59
+ t.last_output.should =~ /testing hello baby duck/
60
+ end
61
+
62
+ it 'should pass option arguments to original' do
63
+ set = Pry::CommandSet.new do
64
+ import Pry::Commands
65
+ alias_command "test-alias", "ls"
66
+ end
67
+
68
+ obj = Class.new { @x = 10 }
69
+ t = pry_tester(obj, :commands => set)
70
+
71
+ t.process_command "test-alias -i"
72
+ t.last_output.should =~ /@x/
73
+ end
74
+
75
+ it 'should pass option arguments to original with additional parameters' do
76
+ set = Pry::CommandSet.new do
77
+ import Pry::Commands
78
+ alias_command "test-alias", "ls -M"
79
+ end
80
+
81
+ obj = Class.new { @x = Class.new { define_method(:plymouth) {} } }
82
+ t = pry_tester(obj, :commands => set)
83
+ t.process_command "test-alias @x"
84
+ t.last_output.should =~ /plymouth/
85
+ end
86
+
87
+ it 'should be able to alias a regex command' do
88
+ set = Pry::CommandSet.new do
89
+ command /du.k/ do
90
+ output.puts "ducky"
91
+ end
92
+ alias_command "test-alias", "duck"
93
+ end
94
+
95
+ t = pry_tester(:commands => set)
96
+ t.process_command "test-alias"
97
+ t.last_output.should =~ /ducky/
98
+ end
99
+
100
+ it 'should be able to make the alias a regex' do
101
+ set = Pry::CommandSet.new do
102
+ command /du.k/ do
103
+ output.puts "ducky"
104
+ end
105
+ alias_command /test-ali.s/, "duck"
106
+ end
107
+
108
+ redirect_pry_io(InputTester.new("test-alias"), out1 = StringIO.new) do
109
+ Pry.start self, :commands => set
110
+ end
111
+
112
+ out1.string.should =~ /ducky/
113
+ end
114
+ end
115
+
116
+ describe "Pry::Command#run" do
117
+ it 'should allow running of commands with following whitespace' do
118
+ set = Pry::CommandSet.new do
119
+ import Pry::Commands
120
+ command "test-run" do
121
+ run "cd / "
122
+ end
123
+ end
124
+
125
+ redirect_pry_io(InputTester.new("cd 1/2/3/4/5/6", @bs1, "test-run",
126
+ @self, @bs2, "exit-all")) do
127
+ Pry.start(@o, :commands => set)
128
+ end
129
+
130
+ Pad.bs1.size.should == 7
131
+ Pad.self.should == @o
132
+ Pad.bs2.size.should == 1
133
+ end
134
+
135
+ it 'should allow running of cd command when contained in a single string' do
136
+ set = Pry::CommandSet.new do
137
+ import Pry::Commands
138
+ command "test-run" do
139
+ run "cd /"
140
+ end
141
+ end
142
+ redirect_pry_io(InputTester.new("cd 1/2/3/4/5/6", @bs1, "test-run",
143
+ @self, @bs2, "exit-all")) do
144
+ Pry.start(@o, :commands => set)
145
+ end
146
+
147
+ Pad.bs1.size.should == 7
148
+ Pad.self.should == @o
149
+ Pad.bs2.size.should == 1
150
+ end
151
+
152
+ it 'should allow running of cd command when split into array' do
153
+ set = Pry::CommandSet.new do
154
+ import Pry::Commands
155
+ command "test-run" do
156
+ run "cd", "/"
157
+ end
158
+ end
159
+ redirect_pry_io(InputTester.new("cd 1/2/3/4/5/6", @bs1, "test-run",
160
+ @self, @bs2, "exit-all")) do
161
+ Pry.start(@o, :commands => set)
162
+ end
163
+
164
+ Pad.bs1.size.should == 7
165
+ Pad.self.should == @o
166
+ Pad.bs2.size.should == 1
167
+ end
168
+
169
+ it 'should run a command from within a command' do
170
+ klass = Pry::CommandSet.new do
171
+ command "v" do
172
+ output.puts "v command"
173
+ end
174
+
175
+ command "run_v" do
176
+ run "v"
177
+ end
178
+ end
179
+
180
+ pry_tester(:commands => klass).eval('run_v').should =~ /v command/
181
+ end
182
+
183
+ it 'should run a regex command from within a command' do
184
+ klass = Pry::CommandSet.new do
185
+ command /v(.*)?/ do |arg|
186
+ output.puts "v #{arg}"
187
+ end
188
+
189
+ command "run_v" do
190
+ run "vbaby"
191
+ end
192
+ end
193
+
194
+ pry_tester(:commands => klass).eval('run_v').should =~ /v baby/
195
+ end
196
+
197
+ it 'should run a command from within a command with arguments' do
198
+ klass = Pry::CommandSet.new do
199
+ command /v(\w+)/ do |arg1, arg2|
200
+ output.puts "v #{arg1} #{arg2}"
201
+ end
202
+
203
+ command "run_v_explicit_parameter" do
204
+ run "vbaby", "param"
205
+ end
206
+
207
+ command "run_v_embedded_parameter" do
208
+ run "vbaby param"
209
+ end
210
+ end
211
+
212
+ ["run_v_explicit_parameter", "run_v_embedded_parameter"].each do |cmd|
213
+ pry_tester(:commands => klass).eval(cmd).should =~ /v baby param/
214
+ end
215
+ end
216
+ end
217
+
218
+ describe "Pry#run_command" do
219
+ it 'should run a command that modifies the passed in eval_string' do
220
+ p = Pry.new(:output => @str_output)
221
+ p.eval "def hello\npeter pan\n"
222
+ p.run_command "amend-line !"
223
+ p.eval_string.should =~ /def hello/
224
+ p.eval_string.should.not =~ /peter pan/
225
+ end
226
+
227
+ it 'should run a command in the context of a session' do
228
+ pry_tester(Object.new).tap do |t|
229
+ t.eval "@session_ivar = 10", "_pry_.run_command('ls')"
230
+ t.last_output.should =~ /@session_ivar/
231
+ end
232
+ end
233
+ end
234
+
235
+ it 'should interpolate ruby code into commands' do
236
+ set = Pry::CommandSet.new do
237
+ command "hello", "", :keep_retval => true do |arg|
238
+ arg
239
+ end
240
+ end
241
+
242
+ pry_tester(:commands => set).eval('hello #{Pad.bong}').should =~ /bong/
243
+ end
244
+
245
+ # bug fix for https://github.com/pry/pry/issues/170
246
+ it 'should not choke on complex string interpolation when checking if ruby code is a command' do
247
+ redirect_pry_io(InputTester.new('/#{Regexp.escape(File.expand_path("."))}/'), @str_output) do
248
+ pry
249
+ end
250
+
251
+ @str_output.string.should.not =~ /SyntaxError/
252
+ end
253
+
254
+ it 'should NOT interpolate ruby code into commands if :interpolate => false' do
255
+ set = Pry::CommandSet.new do
256
+ command "hello", "", :keep_retval => true, :interpolate => false do |arg|
257
+ arg
258
+ end
259
+ end
260
+
261
+ pry_tester(:commands => set).eval('hello #{Pad.bong}').
262
+ should =~ /Pad\.bong/
263
+ end
264
+
265
+ it 'should NOT try to interpolate pure ruby code (no commands) ' do
266
+ # These should raise RuntimeError instead of NameError
267
+ proc {
268
+ pry_eval 'raise \'#{aggy}\''
269
+ }.should.raise(RuntimeError)
270
+
271
+ proc {
272
+ pry_eval 'raise #{aggy}'
273
+ }.should.raise(RuntimeError)
274
+
275
+ pry_eval('format \'#{my_var}\'').should == "\#{my_var}"
276
+ end
277
+
278
+ it 'should create a command with a space in its name zzz' do
279
+ set = Pry::CommandSet.new do
280
+ command "hello baby", "" do
281
+ output.puts "hello baby command"
282
+ end
283
+ end
284
+
285
+ pry_tester(:commands => set).eval('hello baby').
286
+ should =~ /hello baby command/
287
+ end
288
+
289
+ it 'should create a command with a space in its name and pass an argument' do
290
+ set = Pry::CommandSet.new do
291
+ command "hello baby", "" do |arg|
292
+ output.puts "hello baby command #{arg}"
293
+ end
294
+ end
295
+
296
+ pry_tester(:commands => set).eval('hello baby john').
297
+ should =~ /hello baby command john/
298
+ end
299
+
300
+ it 'should create a regex command and be able to invoke it' do
301
+ set = Pry::CommandSet.new do
302
+ command /hello(.)/, "" do
303
+ c = captures.first
304
+ output.puts "hello#{c}"
305
+ end
306
+ end
307
+
308
+ pry_tester(:commands => set).eval('hello1').should =~ /hello1/
309
+ end
310
+
311
+ it 'should create a regex command and pass captures into the args list before regular arguments' do
312
+ set = Pry::CommandSet.new do
313
+ command /hello(.)/, "" do |c1, a1|
314
+ output.puts "hello #{c1} #{a1}"
315
+ end
316
+ end
317
+
318
+ pry_tester(:commands => set).eval('hello1 baby').should =~ /hello 1 baby/
319
+ end
320
+
321
+ it 'should create a regex command and interpolate the captures' do
322
+ set = Pry::CommandSet.new do
323
+ command /hello (.*)/, "" do |c1|
324
+ output.puts "hello #{c1}"
325
+ end
326
+ end
327
+
328
+ bong = "bong"
329
+ pry_tester(binding, :commands => set).eval('hello #{bong}').
330
+ should =~ /hello bong/
331
+ end
332
+
333
+ it 'should create a regex command and arg_string should be interpolated' do
334
+ set = Pry::CommandSet.new do
335
+ command /hello(\w+)/, "" do |c1, a1, a2, a3|
336
+ output.puts "hello #{c1} #{a1} #{a2} #{a3}"
337
+ end
338
+ end
339
+
340
+ bing = 'bing'
341
+ bong = 'bong'
342
+ bang = 'bang'
343
+
344
+ pry_tester(binding, :commands => set).
345
+ eval('hellojohn #{bing} #{bong} #{bang}').
346
+ should =~ /hello john bing bong bang/
347
+ end
348
+
349
+ it 'if a regex capture is missing it should be nil' do
350
+ set = Pry::CommandSet.new do
351
+ command /hello(.)?/, "" do |c1, a1|
352
+ output.puts "hello #{c1.inspect} #{a1}"
353
+ end
354
+ end
355
+
356
+ pry_tester(:commands => set).eval('hello baby').should =~ /hello nil baby/
357
+ end
358
+
359
+ it 'should create a command in a nested context and that command should be accessible from the parent' do
360
+ pry_tester(Object.new).eval(*(<<-RUBY.split("\n"))).should =~ /instance variables:\s+@x/m
361
+ @x = nil
362
+ cd 7
363
+ _pry_.commands.instance_eval { command('bing') { |arg| run arg } }
364
+ cd ..
365
+ bing ls
366
+ RUBY
367
+ end
368
+
369
+ it 'should define a command that keeps its return value' do
370
+ klass = Pry::CommandSet.new do
371
+ command "hello", "", :keep_retval => true do
372
+ :kept_hello
373
+ end
374
+ end
375
+
376
+ t = pry_tester(:commands => klass)
377
+ t.eval("hello\n")
378
+ t.last_command_result.should == :kept_hello
379
+ end
380
+
381
+ it 'should define a command that does NOT keep its return value' do
382
+ klass = Pry::CommandSet.new do
383
+ command "hello", "", :keep_retval => false do
384
+ :kept_hello
385
+ end
386
+ end
387
+
388
+ t = pry_tester(:commands => klass)
389
+ t.eval("hello\n").should == ''
390
+ t.last_command_result.should == Pry::Command::VOID_VALUE
391
+ end
392
+
393
+ it 'should define a command that keeps its return value even when nil' do
394
+ klass = Pry::CommandSet.new do
395
+ command "hello", "", :keep_retval => true do
396
+ nil
397
+ end
398
+ end
399
+
400
+ t = pry_tester(:commands => klass)
401
+ t.eval("hello\n")
402
+ t.last_command_result.should == nil
403
+ end
404
+
405
+ it 'should define a command that keeps its return value but does not return when value is void' do
406
+ klass = Pry::CommandSet.new do
407
+ command "hello", "", :keep_retval => true do
408
+ void
409
+ end
410
+ end
411
+
412
+ pry_tester(:commands => klass).eval("hello\n").empty?.should == true
413
+ end
414
+
415
+ it 'a command (with :keep_retval => false) that replaces eval_string with a valid expression should not have the expression value suppressed' do
416
+ klass = Pry::CommandSet.new do
417
+ command "hello", "" do
418
+ eval_string.replace("6")
419
+ end
420
+ end
421
+
422
+ output = StringIO.new
423
+
424
+ redirect_pry_io(InputTester.new('def yo', 'hello'), output) do
425
+ Pry.start self, :commands => klass
426
+ end
427
+
428
+ output.string.should =~ /6/
429
+ end
430
+
431
+ 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
432
+ klass = Pry::CommandSet.new do
433
+ command "hello", "", :keep_retval => true do
434
+ eval_string.replace("6")
435
+ 7
436
+ end
437
+ end
438
+
439
+ pry_tester(:commands => klass).eval("def yo\nhello\n").should == 7
440
+ end
441
+
442
+ it 'a command that return a value in a multi-line expression should clear the expression and return the value' do
443
+ klass = Pry::CommandSet.new do
444
+ command "hello", "", :keep_retval => true do
445
+ 5
446
+ end
447
+ end
448
+
449
+ pry_tester(:commands => klass).eval("def yo\nhello\n").should == 5
450
+ end
451
+
452
+ it 'should set the commands default, and the default should be overridable' do
453
+ klass = Pry::CommandSet.new do
454
+ command "hello" do
455
+ output.puts "hello world"
456
+ end
457
+ end
458
+
459
+ other_klass = Pry::CommandSet.new do
460
+ command "goodbye", "" do
461
+ output.puts "goodbye world"
462
+ end
463
+ end
464
+
465
+ Pry.commands = klass
466
+ pry_tester.eval("hello").should == "hello world\n"
467
+ pry_tester(:commands => other_klass).eval("goodbye").should == "goodbye world\n"
468
+ end
469
+
470
+ it 'should inherit commands from Pry::Commands' do
471
+ klass = Pry::CommandSet.new Pry::Commands do
472
+ command "v" do
473
+ end
474
+ end
475
+
476
+ klass.commands.include?("nesting").should == true
477
+ klass.commands.include?("jump-to").should == true
478
+ klass.commands.include?("cd").should == true
479
+ klass.commands.include?("v").should == true
480
+ end
481
+
482
+ it 'should change description of a command using desc' do
483
+ klass = Pry::CommandSet.new do
484
+ import Pry::Commands
485
+ end
486
+ orig = klass.commands["help"].description
487
+ klass.instance_eval do
488
+ desc "help", "blah"
489
+ end
490
+ klass.commands["help"].description.should.not == orig
491
+ klass.commands["help"].description.should == "blah"
492
+ end
493
+
494
+ it 'should enable an inherited method to access opts and output and target, due to instance_exec' do
495
+ klass = Pry::CommandSet.new do
496
+ command "v" do
497
+ output.puts "#{target.eval('self')}"
498
+ end
499
+ end
500
+
501
+ child_klass = Pry::CommandSet.new klass do
502
+ end
503
+
504
+ mock_pry(Pry.binding_for('john'), "v", :print => proc {}, :commands => child_klass,
505
+ :output => @str_output)
506
+
507
+ @str_output.string.should == "john\n"
508
+ end
509
+
510
+ it 'should import commands from another command object' do
511
+ klass = Pry::CommandSet.new do
512
+ import_from Pry::Commands, "ls", "jump-to"
513
+ end
514
+
515
+ klass.commands.include?("ls").should == true
516
+ klass.commands.include?("jump-to").should == true
517
+ end
518
+
519
+ it 'should delete some inherited commands when using delete method' do
520
+ klass = Pry::CommandSet.new Pry::Commands do
521
+ command "v" do
522
+ end
523
+
524
+ delete "show-doc", "show-method"
525
+ delete "ls"
526
+ end
527
+
528
+ klass.commands.include?("nesting").should == true
529
+ klass.commands.include?("jump-to").should == true
530
+ klass.commands.include?("cd").should == true
531
+ klass.commands.include?("v").should == true
532
+ klass.commands.include?("show-doc").should == false
533
+ klass.commands.include?("show-method").should == false
534
+ klass.commands.include?("ls").should == false
535
+ end
536
+
537
+ it 'should override some inherited commands' do
538
+ klass = Pry::CommandSet.new Pry::Commands do
539
+ command "jump-to" do
540
+ output.puts "jump-to the music"
541
+ end
542
+
543
+ command "help" do
544
+ output.puts "help to the music"
545
+ end
546
+ end
547
+
548
+ t = pry_tester(:commands => klass)
549
+ t.eval('jump-to').should == "jump-to the music\n"
550
+ t.eval('help').should == "help to the music\n"
551
+ end
552
+
553
+ it 'should run a command with no parameter' do
554
+ pry_tester(:commands => @command_tester).eval('command1').
555
+ should == "command1\n"
556
+ end
557
+
558
+ it 'should run a command with one parameter' do
559
+ pry_tester(:commands => @command_tester).eval('command2 horsey').
560
+ should == "horsey\n"
561
+ end
562
+ end