pry 0.9.12.6-i386-mingw32 → 0.10.0-i386-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (187) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +702 -0
  3. data/LICENSE +2 -2
  4. data/{README.markdown → README.md} +37 -31
  5. data/lib/pry.rb +38 -151
  6. data/lib/pry/cli.rb +35 -17
  7. data/lib/pry/code.rb +19 -63
  8. data/lib/pry/code/code_file.rb +103 -0
  9. data/lib/pry/code/code_range.rb +2 -1
  10. data/lib/pry/code/loc.rb +2 -2
  11. data/lib/pry/code_object.rb +40 -21
  12. data/lib/pry/color_printer.rb +55 -0
  13. data/lib/pry/command.rb +12 -9
  14. data/lib/pry/command_set.rb +81 -38
  15. data/lib/pry/commands.rb +1 -1
  16. data/lib/pry/commands/amend_line.rb +2 -2
  17. data/lib/pry/commands/bang.rb +1 -1
  18. data/lib/pry/commands/cat.rb +11 -2
  19. data/lib/pry/commands/cat/exception_formatter.rb +6 -7
  20. data/lib/pry/commands/cat/file_formatter.rb +15 -32
  21. data/lib/pry/commands/cat/input_expression_formatter.rb +1 -1
  22. data/lib/pry/commands/cd.rb +14 -3
  23. data/lib/pry/commands/change_inspector.rb +27 -0
  24. data/lib/pry/commands/change_prompt.rb +26 -0
  25. data/lib/pry/commands/code_collector.rb +4 -4
  26. data/lib/pry/commands/easter_eggs.rb +3 -3
  27. data/lib/pry/commands/edit.rb +10 -22
  28. data/lib/pry/commands/edit/exception_patcher.rb +2 -2
  29. data/lib/pry/commands/edit/file_and_line_locator.rb +0 -2
  30. data/lib/pry/commands/exit_program.rb +0 -1
  31. data/lib/pry/commands/find_method.rb +16 -22
  32. data/lib/pry/commands/gem_install.rb +5 -2
  33. data/lib/pry/commands/gem_open.rb +1 -1
  34. data/lib/pry/commands/gist.rb +10 -11
  35. data/lib/pry/commands/help.rb +14 -14
  36. data/lib/pry/commands/hist.rb +27 -8
  37. data/lib/pry/commands/install_command.rb +14 -12
  38. data/lib/pry/commands/list_inspectors.rb +35 -0
  39. data/lib/pry/commands/list_prompts.rb +35 -0
  40. data/lib/pry/commands/ls.rb +72 -296
  41. data/lib/pry/commands/ls/constants.rb +47 -0
  42. data/lib/pry/commands/ls/formatter.rb +49 -0
  43. data/lib/pry/commands/ls/globals.rb +48 -0
  44. data/lib/pry/commands/ls/grep.rb +21 -0
  45. data/lib/pry/commands/ls/instance_vars.rb +39 -0
  46. data/lib/pry/commands/ls/interrogatable.rb +18 -0
  47. data/lib/pry/commands/ls/jruby_hacks.rb +49 -0
  48. data/lib/pry/commands/ls/local_names.rb +35 -0
  49. data/lib/pry/commands/ls/local_vars.rb +39 -0
  50. data/lib/pry/commands/ls/ls_entity.rb +70 -0
  51. data/lib/pry/commands/ls/methods.rb +57 -0
  52. data/lib/pry/commands/ls/methods_helper.rb +46 -0
  53. data/lib/pry/commands/ls/self_methods.rb +32 -0
  54. data/lib/pry/commands/play.rb +44 -10
  55. data/lib/pry/commands/pry_backtrace.rb +1 -2
  56. data/lib/pry/commands/raise_up.rb +2 -2
  57. data/lib/pry/commands/reload_code.rb +16 -19
  58. data/lib/pry/commands/ri.rb +7 -3
  59. data/lib/pry/commands/shell_command.rb +18 -13
  60. data/lib/pry/commands/shell_mode.rb +2 -4
  61. data/lib/pry/commands/show_doc.rb +5 -0
  62. data/lib/pry/commands/show_info.rb +8 -13
  63. data/lib/pry/commands/show_source.rb +15 -3
  64. data/lib/pry/commands/simple_prompt.rb +1 -1
  65. data/lib/pry/commands/toggle_color.rb +8 -4
  66. data/lib/pry/commands/watch_expression.rb +105 -0
  67. data/lib/pry/commands/watch_expression/expression.rb +38 -0
  68. data/lib/pry/commands/whereami.rb +18 -10
  69. data/lib/pry/commands/wtf.rb +3 -3
  70. data/lib/pry/config.rb +20 -254
  71. data/lib/pry/config/behavior.rb +139 -0
  72. data/lib/pry/config/convenience.rb +26 -0
  73. data/lib/pry/config/default.rb +165 -0
  74. data/lib/pry/core_extensions.rb +31 -21
  75. data/lib/pry/editor.rb +107 -103
  76. data/lib/pry/exceptions.rb +77 -0
  77. data/lib/pry/helpers/base_helpers.rb +22 -109
  78. data/lib/pry/helpers/command_helpers.rb +10 -8
  79. data/lib/pry/helpers/documentation_helpers.rb +1 -2
  80. data/lib/pry/helpers/text.rb +4 -5
  81. data/lib/pry/history.rb +46 -45
  82. data/lib/pry/history_array.rb +6 -1
  83. data/lib/pry/hooks.rb +9 -29
  84. data/lib/pry/indent.rb +6 -6
  85. data/lib/pry/input_completer.rb +242 -0
  86. data/lib/pry/input_lock.rb +132 -0
  87. data/lib/pry/inspector.rb +27 -0
  88. data/lib/pry/last_exception.rb +61 -0
  89. data/lib/pry/method.rb +82 -87
  90. data/lib/pry/{commands/edit/method_patcher.rb → method/patcher.rb} +41 -38
  91. data/lib/pry/module_candidate.rb +4 -14
  92. data/lib/pry/object_path.rb +82 -0
  93. data/lib/pry/output.rb +50 -0
  94. data/lib/pry/pager.rb +193 -48
  95. data/lib/pry/plugins.rb +1 -1
  96. data/lib/pry/prompt.rb +26 -0
  97. data/lib/pry/pry_class.rb +149 -230
  98. data/lib/pry/pry_instance.rb +302 -413
  99. data/lib/pry/rbx_path.rb +1 -1
  100. data/lib/pry/repl.rb +202 -0
  101. data/lib/pry/repl_file_loader.rb +20 -26
  102. data/lib/pry/rubygem.rb +13 -5
  103. data/lib/pry/terminal.rb +2 -1
  104. data/lib/pry/test/helper.rb +26 -41
  105. data/lib/pry/version.rb +1 -1
  106. data/lib/pry/wrapped_module.rb +45 -59
  107. metadata +62 -225
  108. data/.document +0 -2
  109. data/.gitignore +0 -16
  110. data/.travis.yml +0 -25
  111. data/.yardopts +0 -1
  112. data/CHANGELOG +0 -534
  113. data/CONTRIBUTORS +0 -55
  114. data/Gemfile +0 -12
  115. data/Rakefile +0 -140
  116. data/TODO +0 -117
  117. data/lib/pry/completion.rb +0 -321
  118. data/lib/pry/custom_completions.rb +0 -6
  119. data/lib/pry/rbx_method.rb +0 -13
  120. data/man/pry.1 +0 -195
  121. data/man/pry.1.html +0 -204
  122. data/man/pry.1.ronn +0 -141
  123. data/pry.gemspec +0 -29
  124. data/spec/Procfile +0 -3
  125. data/spec/cli_spec.rb +0 -78
  126. data/spec/code_object_spec.rb +0 -277
  127. data/spec/code_spec.rb +0 -219
  128. data/spec/command_helpers_spec.rb +0 -29
  129. data/spec/command_integration_spec.rb +0 -644
  130. data/spec/command_set_spec.rb +0 -627
  131. data/spec/command_spec.rb +0 -821
  132. data/spec/commands/amend_line_spec.rb +0 -247
  133. data/spec/commands/bang_spec.rb +0 -19
  134. data/spec/commands/cat_spec.rb +0 -164
  135. data/spec/commands/cd_spec.rb +0 -250
  136. data/spec/commands/disable_pry_spec.rb +0 -25
  137. data/spec/commands/edit_spec.rb +0 -727
  138. data/spec/commands/exit_all_spec.rb +0 -34
  139. data/spec/commands/exit_program_spec.rb +0 -19
  140. data/spec/commands/exit_spec.rb +0 -34
  141. data/spec/commands/find_method_spec.rb +0 -70
  142. data/spec/commands/gem_list_spec.rb +0 -26
  143. data/spec/commands/gist_spec.rb +0 -79
  144. data/spec/commands/help_spec.rb +0 -56
  145. data/spec/commands/hist_spec.rb +0 -181
  146. data/spec/commands/jump_to_spec.rb +0 -15
  147. data/spec/commands/ls_spec.rb +0 -181
  148. data/spec/commands/play_spec.rb +0 -140
  149. data/spec/commands/raise_up_spec.rb +0 -56
  150. data/spec/commands/save_file_spec.rb +0 -177
  151. data/spec/commands/show_doc_spec.rb +0 -510
  152. data/spec/commands/show_input_spec.rb +0 -17
  153. data/spec/commands/show_source_spec.rb +0 -782
  154. data/spec/commands/whereami_spec.rb +0 -203
  155. data/spec/completion_spec.rb +0 -241
  156. data/spec/control_d_handler_spec.rb +0 -58
  157. data/spec/documentation_helper_spec.rb +0 -73
  158. data/spec/editor_spec.rb +0 -79
  159. data/spec/exception_whitelist_spec.rb +0 -21
  160. data/spec/fixtures/candidate_helper1.rb +0 -11
  161. data/spec/fixtures/candidate_helper2.rb +0 -8
  162. data/spec/fixtures/example.erb +0 -5
  163. data/spec/fixtures/example_nesting.rb +0 -33
  164. data/spec/fixtures/show_source_doc_examples.rb +0 -15
  165. data/spec/fixtures/testrc +0 -2
  166. data/spec/fixtures/testrcbad +0 -2
  167. data/spec/fixtures/whereami_helper.rb +0 -6
  168. data/spec/helper.rb +0 -34
  169. data/spec/helpers/bacon.rb +0 -86
  170. data/spec/helpers/mock_pry.rb +0 -43
  171. data/spec/helpers/table_spec.rb +0 -105
  172. data/spec/history_array_spec.rb +0 -67
  173. data/spec/hooks_spec.rb +0 -522
  174. data/spec/indent_spec.rb +0 -301
  175. data/spec/input_stack_spec.rb +0 -90
  176. data/spec/method_spec.rb +0 -482
  177. data/spec/prompt_spec.rb +0 -60
  178. data/spec/pry_defaults_spec.rb +0 -419
  179. data/spec/pry_history_spec.rb +0 -99
  180. data/spec/pry_output_spec.rb +0 -95
  181. data/spec/pry_spec.rb +0 -515
  182. data/spec/run_command_spec.rb +0 -25
  183. data/spec/sticky_locals_spec.rb +0 -157
  184. data/spec/syntax_checking_spec.rb +0 -81
  185. data/spec/wrapped_module_spec.rb +0 -261
  186. data/wiki/Customizing-pry.md +0 -397
  187. data/wiki/Home.md +0 -4
@@ -1,29 +0,0 @@
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
@@ -1,644 +0,0 @@
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
- end
32
-
33
- describe "alias_command" do
34
- it 'should make an aliasd command behave like its original' do
35
- set = Pry::CommandSet.new do
36
- command "test-command" do
37
- output.puts "testing 1, 2, 3"
38
- end
39
- alias_command "test-alias", "test-command"
40
- end
41
- redirect_pry_io(InputTester.new("test-alias"), out1 = StringIO.new) do
42
- Pry.start self, :commands => set
43
- end
44
-
45
- redirect_pry_io(InputTester.new("test-command"), out2 = StringIO.new) do
46
- Pry.start self, :commands => set
47
- end
48
-
49
- out1.string.should == out2.string
50
- end
51
-
52
- it 'should pass on arguments to original' do
53
- set = Pry::CommandSet.new do
54
- command "test-command" do |*args|
55
- output.puts "testing #{args.join(' ')}"
56
- end
57
- alias_command "test-alias", "test-command"
58
- end
59
-
60
- t = pry_tester(:commands => set)
61
-
62
- t.process_command "test-alias hello baby duck"
63
- t.last_output.should =~ /testing hello baby duck/
64
- end
65
-
66
- it 'should pass option arguments to original' do
67
- set = Pry::CommandSet.new do
68
- import Pry::Commands
69
- alias_command "test-alias", "ls"
70
- end
71
-
72
- obj = Class.new { @x = 10 }
73
- t = pry_tester(obj, :commands => set)
74
-
75
- t.process_command "test-alias -i"
76
- t.last_output.should =~ /@x/
77
- end
78
-
79
- it 'should pass option arguments to original with additional parameters' do
80
- set = Pry::CommandSet.new do
81
- import Pry::Commands
82
- alias_command "test-alias", "ls -M"
83
- end
84
-
85
- obj = Class.new { @x = Class.new { define_method(:plymouth) {} } }
86
- t = pry_tester(obj, :commands => set)
87
- t.process_command "test-alias @x"
88
- t.last_output.should =~ /plymouth/
89
- end
90
-
91
- it 'should be able to alias a regex command' do
92
- set = Pry::CommandSet.new do
93
- command /du.k/ do
94
- output.puts "ducky"
95
- end
96
- alias_command "test-alias", "duck"
97
- end
98
-
99
- t = pry_tester(:commands => set)
100
- t.process_command "test-alias"
101
- t.last_output.should =~ /ducky/
102
- end
103
-
104
- it 'should be able to make the alias a regex' do
105
- set = Pry::CommandSet.new do
106
- command /du.k/ do
107
- output.puts "ducky"
108
- end
109
- alias_command /test-ali.s/, "duck"
110
- end
111
-
112
- redirect_pry_io(InputTester.new("test-alias"), out1 = StringIO.new) do
113
- Pry.start self, :commands => set
114
- end
115
-
116
- out1.string.should =~ /ducky/
117
- end
118
- end
119
-
120
- describe "Pry::Command#run" do
121
- it 'should allow running of commands with following whitespace' do
122
- set = Pry::CommandSet.new do
123
- import Pry::Commands
124
- command "test-run" do
125
- run "cd / "
126
- end
127
- end
128
-
129
- redirect_pry_io(InputTester.new("cd 1/2/3/4/5/6", @bs1, "test-run",
130
- @self, @bs2, "exit-all")) do
131
- Pry.start(@o, :commands => set)
132
- end
133
-
134
- Pad.bs1.size.should == 7
135
- Pad.self.should == @o
136
- Pad.bs2.size.should == 1
137
- end
138
-
139
- it 'should allow running of cd command when contained in a single string' do
140
- set = Pry::CommandSet.new do
141
- import Pry::Commands
142
- command "test-run" do
143
- run "cd /"
144
- end
145
- end
146
- redirect_pry_io(InputTester.new("cd 1/2/3/4/5/6", @bs1, "test-run",
147
- @self, @bs2, "exit-all")) do
148
- Pry.start(@o, :commands => set)
149
- end
150
-
151
- Pad.bs1.size.should == 7
152
- Pad.self.should == @o
153
- Pad.bs2.size.should == 1
154
- end
155
-
156
- it 'should allow running of cd command when split into array' do
157
- set = Pry::CommandSet.new do
158
- import Pry::Commands
159
- command "test-run" do
160
- run "cd", "/"
161
- end
162
- end
163
- redirect_pry_io(InputTester.new("cd 1/2/3/4/5/6", @bs1, "test-run",
164
- @self, @bs2, "exit-all")) do
165
- Pry.start(@o, :commands => set)
166
- end
167
-
168
- Pad.bs1.size.should == 7
169
- Pad.self.should == @o
170
- Pad.bs2.size.should == 1
171
- end
172
-
173
- it 'should run a command from within a command' do
174
- klass = Pry::CommandSet.new do
175
- command "v" do
176
- output.puts "v command"
177
- end
178
-
179
- command "run_v" do
180
- run "v"
181
- end
182
- end
183
-
184
- Pry.new(:input => InputTester.new("run_v"), :output => @str_output, :commands => klass).rep
185
-
186
- @str_output.string.should =~ /v command/
187
- end
188
-
189
- it 'should run a regex command from within a command' do
190
- klass = Pry::CommandSet.new do
191
- command /v(.*)?/ do |arg|
192
- output.puts "v #{arg}"
193
- end
194
-
195
- command "run_v" do
196
- run "vbaby"
197
- end
198
- end
199
-
200
- redirect_pry_io(InputTester.new("run_v"), @str_output) do
201
- Pry.new(:commands => klass).rep
202
- end
203
-
204
- @str_output.string.should =~ /v baby/
205
- end
206
-
207
- it 'should run a command from within a command with arguments' do
208
- klass = Pry::CommandSet.new do
209
- command /v(\w+)/ do |arg1, arg2|
210
- output.puts "v #{arg1} #{arg2}"
211
- end
212
-
213
- command "run_v_explicit_parameter" do
214
- run "vbaby", "param"
215
- end
216
-
217
- command "run_v_embedded_parameter" do
218
- run "vbaby param"
219
- end
220
- end
221
-
222
- ["run_v_explicit_parameter", "run_v_embedded_parameter"].each do |cmd|
223
- redirect_pry_io(InputTester.new(cmd), @str_output) do
224
- Pry.new(:commands => klass).rep
225
- end
226
- @str_output.string.should =~ /v baby param/
227
- end
228
- end
229
- end
230
-
231
- describe "Pry#run_command" do
232
- it 'should run a command in a specified context' do
233
- b = Pry.binding_for('seven')
234
- p = Pry.new(:output => @str_output)
235
- p.run_command("ls -m", "", b)
236
- p.output.string.should =~ /downcase/
237
- end
238
-
239
- it 'should run a command that modifies the passed in eval_string' do
240
- b = Pry.binding_for(7)
241
- p = Pry.new(:output => @str_output)
242
- eval_string = "def hello\npeter pan\n"
243
- p.run_command("amend-line !", eval_string, b)
244
- eval_string.should =~ /def hello/
245
- eval_string.should.not =~ /peter pan/
246
- end
247
-
248
- it 'should run a command in the context of a session' do
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
253
- end
254
- end
255
-
256
- it 'should interpolate ruby code into commands' do
257
- set = Pry::CommandSet.new do
258
- command "hello", "", :keep_retval => true do |arg|
259
- arg
260
- end
261
- end
262
-
263
- str_input = StringIO.new('hello #{Pad.bong}')
264
- Pry.new(:input => str_input, :output => @str_output, :commands => set).rep
265
-
266
- @str_output.string.should =~ /bong/
267
- end
268
-
269
- # bug fix for https://github.com/pry/pry/issues/170
270
- it 'should not choke on complex string interpolation when checking if ruby code is a command' do
271
- redirect_pry_io(InputTester.new('/#{Regexp.escape(File.expand_path("."))}/'), @str_output) do
272
- pry
273
- end
274
-
275
- @str_output.string.should.not =~ /SyntaxError/
276
- end
277
-
278
- it 'should NOT interpolate ruby code into commands if :interpolate => false' do
279
- set = Pry::CommandSet.new do
280
- command "hello", "", :keep_retval => true, :interpolate => false do |arg|
281
- arg
282
- end
283
- end
284
-
285
- str_input = StringIO.new('hello #{Pad.bong}')
286
- Pry.new(:input => str_input, :output => @str_output, :commands => set).rep
287
-
288
- @str_output.string.should =~ /Pad\.bong/
289
- end
290
-
291
- it 'should NOT try to interpolate pure ruby code (no commands) ' do
292
- Pry.new(:input => StringIO.new('format \'#{aggy}\''), :output => @str_output).rep
293
- @str_output.string.should.not =~ /NameError/
294
-
295
- @str_output = StringIO.new
296
- Pry.new(:input => StringIO.new('format #{aggy}'), :output => @str_output).rep
297
- @str_output.string.should.not =~ /NameError/
298
-
299
- @str_output = StringIO.new
300
- Pad.interp = "bong"
301
- Pry.new(:input => StringIO.new('format \'#{Pad.interp}\''), :output => @str_output).rep
302
-
303
- @str_output.string.should.not =~ /bong/
304
- end
305
-
306
- it 'should create a command with a space in its name' do
307
- set = Pry::CommandSet.new do
308
- command "hello baby", "" do
309
- output.puts "hello baby command"
310
- end
311
- end
312
-
313
- redirect_pry_io(InputTester.new("hello baby", "exit-all"), @str_output) do
314
- Pry.new(:commands => set).rep
315
- end
316
-
317
- @str_output.string.should =~ /hello baby command/
318
- end
319
-
320
- it 'should create a command with a space in its name and pass an argument' do
321
- set = Pry::CommandSet.new do
322
- command "hello baby", "" do |arg|
323
- output.puts "hello baby command #{arg}"
324
- end
325
- end
326
-
327
- redirect_pry_io(InputTester.new("hello baby john"), @str_output) do
328
- Pry.new(:commands => set).rep
329
- end
330
-
331
- @str_output.string.should =~ /hello baby command john/
332
- end
333
-
334
- it 'should create a regex command and be able to invoke it' do
335
- set = Pry::CommandSet.new do
336
- command /hello(.)/, "" do
337
- c = captures.first
338
- output.puts "hello#{c}"
339
- end
340
- end
341
-
342
- redirect_pry_io(InputTester.new("hello1"), @str_output) do
343
- Pry.new(:commands => set).rep
344
- end
345
-
346
- @str_output.string.should =~ /hello1/
347
- end
348
-
349
- it 'should create a regex command and pass captures into the args list before regular arguments' do
350
- set = Pry::CommandSet.new do
351
- command /hello(.)/, "" do |c1, a1|
352
- output.puts "hello #{c1} #{a1}"
353
- end
354
- end
355
-
356
- redirect_pry_io(InputTester.new("hello1 baby"), @str_output) do
357
- Pry.new(:commands => set).rep
358
- end
359
-
360
- @str_output.string.should =~ /hello 1 baby/
361
- end
362
-
363
- it 'should create a regex command and interpolate the captures' do
364
- set = Pry::CommandSet.new do
365
- command /hello (.*)/, "" do |c1|
366
- output.puts "hello #{c1}"
367
- end
368
- end
369
-
370
- redirect_pry_io(InputTester.new('hello #{Pad.bong}'), @str_output) do
371
- Pry.new(:commands => set).rep
372
- end
373
-
374
- @str_output.string.should =~ /hello bong/
375
- end
376
-
377
- it 'should create a regex command and arg_string should be interpolated' do
378
- set = Pry::CommandSet.new do
379
- command /hello(\w+)/, "" do |c1, a1, a2, a3|
380
- output.puts "hello #{c1} #{a1} #{a2} #{a3}"
381
- end
382
- end
383
-
384
- Pad.bing = "bing"
385
- Pad.bang = "bang"
386
- redirect_pry_io(InputTester.new('hellojohn #{Pad.bing} #{Pad.bong} #{Pad.bang}'),
387
- @str_output) do
388
- Pry.new(:commands => set).rep
389
- end
390
-
391
- @str_output.string.should =~ /hello john bing bong bang/
392
- end
393
-
394
- it 'if a regex capture is missing it should be nil' do
395
- set = Pry::CommandSet.new do
396
- command /hello(.)?/, "" do |c1, a1|
397
- output.puts "hello #{c1.inspect} #{a1}"
398
- end
399
- end
400
-
401
- redirect_pry_io(InputTester.new("hello baby"), @str_output) do
402
- Pry.new(:commands => set).rep
403
- end
404
-
405
- @str_output.string.should =~ /hello nil baby/
406
- end
407
-
408
- it 'should create a command in a nested context and that command should be accessible from the parent' do
409
- x = "@x=nil\ncd 7\n_pry_.commands.instance_eval {\ncommand('bing') { |arg| run arg }\n}\ncd ..\nbing ls\nexit-all"
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
411
- Pry.new.repl('0')
412
- end
413
-
414
- @str_output.string.should =~ /@x/
415
- end
416
-
417
- it 'should define a command that keeps its return value' do
418
- klass = Pry::CommandSet.new do
419
- command "hello", "", :keep_retval => true do
420
- :kept_hello
421
- end
422
- end
423
-
424
- Pry.new(:input => StringIO.new("hello\n"), :output => @str_output, :commands => klass).rep
425
- @str_output.string.should =~ /:kept_hello/
426
- @str_output.string.should =~ /=>/
427
- end
428
-
429
- it 'should define a command that does NOT keep its return value' do
430
- klass = Pry::CommandSet.new do
431
- command "hello", "", :keep_retval => false do
432
- :kept_hello
433
- end
434
- end
435
-
436
- Pry.new(:input => StringIO.new("hello\n"), :output => @str_output, :commands => klass).rep
437
- (@str_output.string =~ /:kept_hello/).should == nil
438
- @str_output.string !~ /=>/
439
- end
440
-
441
- it 'should define a command that keeps its return value even when nil' do
442
- klass = Pry::CommandSet.new do
443
- command "hello", "", :keep_retval => true do
444
- nil
445
- end
446
- end
447
-
448
- Pry.new(:input => StringIO.new("hello\n"), :output => @str_output, :commands => klass).rep
449
-
450
- @str_output.string.should =~ /nil/
451
- @str_output.string.should =~ /=>/
452
- end
453
-
454
- it 'should define a command that keeps its return value but does not return when value is void' do
455
- klass = Pry::CommandSet.new do
456
- command "hello", "", :keep_retval => true do
457
- void
458
- end
459
- end
460
-
461
- Pry.new(:input => StringIO.new("hello\n"), :output => @str_output, :commands => klass).rep
462
- @str_output.string.empty?.should == true
463
- end
464
-
465
- it 'a command (with :keep_retval => false) that replaces eval_string with a valid expression should not have the expression value suppressed' do
466
- klass = Pry::CommandSet.new do
467
- command "hello", "" do
468
- eval_string.replace("6")
469
- end
470
- end
471
-
472
- Pry.new(:input => StringIO.new("def yo\nhello\n"), :output => @str_output, :commands => klass).rep
473
- @str_output.string.should =~ /6/
474
- end
475
-
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
477
- klass = Pry::CommandSet.new do
478
- command "hello", "", :keep_retval => true do
479
- eval_string.replace("6")
480
- 7
481
- end
482
- end
483
-
484
- Pry.new(:input => StringIO.new("def yo\nhello\n"), :output => @str_output, :commands => klass).rep
485
-
486
- @str_output.string.should =~ /7/
487
- @str_output.string.should.not =~ /6/
488
- end
489
-
490
- it 'a command that return a value in a multi-line expression should clear the expression and return the value' do
491
- klass = Pry::CommandSet.new do
492
- command "hello", "", :keep_retval => true do
493
- 5
494
- end
495
- end
496
-
497
- Pry.new(:input => StringIO.new("def yo\nhello\n"), :output => @str_output, :commands => klass).rep
498
-
499
- @str_output.string.should =~ /5/
500
- end
501
-
502
- it 'should set the commands default, and the default should be overridable' do
503
- klass = Pry::CommandSet.new do
504
- command "hello" do
505
- output.puts "hello world"
506
- end
507
- end
508
-
509
- Pry.commands = klass
510
-
511
- Pry.new(:input => InputTester.new("hello"), :output => @str_output).rep
512
- @str_output.string.should =~ /hello world/
513
-
514
- other_klass = Pry::CommandSet.new do
515
- command "goodbye", "" do
516
- output.puts "goodbye world"
517
- end
518
- end
519
-
520
- @str_output = StringIO.new
521
-
522
- Pry.new(:input => InputTester.new("goodbye"), :output => @str_output, :commands => other_klass).rep
523
- @str_output.string.should =~ /goodbye world/
524
- end
525
-
526
- it 'should inherit commands from Pry::Commands' do
527
- klass = Pry::CommandSet.new Pry::Commands do
528
- command "v" do
529
- end
530
- end
531
-
532
- klass.commands.include?("nesting").should == true
533
- klass.commands.include?("jump-to").should == true
534
- klass.commands.include?("cd").should == true
535
- klass.commands.include?("v").should == true
536
- end
537
-
538
- it 'should change description of a command using desc' do
539
- klass = Pry::CommandSet.new do
540
- import Pry::Commands
541
- end
542
- orig = klass.commands["help"].description
543
- klass.instance_eval do
544
- desc "help", "blah"
545
- end
546
- klass.commands["help"].description.should.not == orig
547
- klass.commands["help"].description.should == "blah"
548
- end
549
-
550
- it 'should enable an inherited method to access opts and output and target, due to instance_exec' do
551
- klass = Pry::CommandSet.new do
552
- command "v" do
553
- output.puts "#{target.eval('self')}"
554
- end
555
- end
556
-
557
- child_klass = Pry::CommandSet.new klass do
558
- end
559
-
560
- Pry.new(:print => proc {}, :input => InputTester.new("v"),
561
- :output => @str_output, :commands => child_klass).rep("john")
562
-
563
- @str_output.string.rstrip.should == "john"
564
- end
565
-
566
- it 'should import commands from another command object' do
567
- klass = Pry::CommandSet.new do
568
- import_from Pry::Commands, "ls", "jump-to"
569
- end
570
-
571
- klass.commands.include?("ls").should == true
572
- klass.commands.include?("jump-to").should == true
573
- end
574
-
575
- it 'should delete some inherited commands when using delete method' do
576
- klass = Pry::CommandSet.new Pry::Commands do
577
- command "v" do
578
- end
579
-
580
- delete "show-doc", "show-method"
581
- delete "ls"
582
- end
583
-
584
- klass.commands.include?("nesting").should == true
585
- klass.commands.include?("jump-to").should == true
586
- klass.commands.include?("cd").should == true
587
- klass.commands.include?("v").should == true
588
- klass.commands.include?("show-doc").should == false
589
- klass.commands.include?("show-method").should == false
590
- klass.commands.include?("ls").should == false
591
- end
592
-
593
- it 'should override some inherited commands' do
594
- klass = Pry::CommandSet.new Pry::Commands do
595
- command "jump-to" do
596
- output.puts "jump-to the music"
597
- end
598
-
599
- command "help" do
600
- output.puts "help to the music"
601
- end
602
- end
603
-
604
- # suppress evaluation output
605
- Pry.print = proc {}
606
-
607
- Pry.new(:input => InputTester.new("jump-to"), :output => @str_output, :commands => klass).rep
608
- @str_output.string.rstrip.should == "jump-to the music"
609
-
610
- @str_output = StringIO.new
611
- Pry.new(:input => InputTester.new("help"), :output => @str_output, :commands => klass).rep
612
- @str_output.string.should == "help to the music\n"
613
-
614
-
615
- Pry.reset_defaults
616
- Pry.color = false
617
- end
618
-
619
- it 'should run a command with no parameter' do
620
- pry_tester = Pry.new
621
- pry_tester.commands = @command_tester
622
- pry_tester.input = InputTester.new("command1", "exit-all")
623
- pry_tester.commands = @command_tester
624
-
625
- pry_tester.output = @str_output
626
-
627
- pry_tester.rep
628
-
629
- @str_output.string.should =~ /command1/
630
- end
631
-
632
- it 'should run a command with one parameter' do
633
- pry_tester = Pry.new
634
- pry_tester.commands = @command_tester
635
- pry_tester.input = InputTester.new("command2 horsey", "exit-all")
636
- pry_tester.commands = @command_tester
637
-
638
- pry_tester.output = @str_output
639
-
640
- pry_tester.rep
641
-
642
- @str_output.string.should =~ /horsey/
643
- end
644
- end