pry 0.10.pre.1-i386-mingw32 → 0.10.0.pre3-i386-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (214) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +702 -0
  3. data/LICENSE +2 -2
  4. data/{README.markdown → README.md} +41 -35
  5. data/lib/pry.rb +82 -139
  6. data/lib/pry/cli.rb +77 -30
  7. data/lib/pry/code.rb +122 -183
  8. data/lib/pry/code/code_file.rb +103 -0
  9. data/lib/pry/code/code_range.rb +71 -0
  10. data/lib/pry/code/loc.rb +92 -0
  11. data/lib/pry/code_object.rb +172 -0
  12. data/lib/pry/color_printer.rb +55 -0
  13. data/lib/pry/command.rb +184 -28
  14. data/lib/pry/command_set.rb +113 -59
  15. data/lib/pry/commands.rb +4 -27
  16. data/lib/pry/commands/amend_line.rb +99 -0
  17. data/lib/pry/commands/bang.rb +20 -0
  18. data/lib/pry/commands/bang_pry.rb +17 -0
  19. data/lib/pry/commands/cat.rb +62 -0
  20. data/lib/pry/commands/cat/abstract_formatter.rb +27 -0
  21. data/lib/pry/commands/cat/exception_formatter.rb +77 -0
  22. data/lib/pry/commands/cat/file_formatter.rb +67 -0
  23. data/lib/pry/commands/cat/input_expression_formatter.rb +43 -0
  24. data/lib/pry/commands/cd.rb +41 -0
  25. data/lib/pry/commands/change_inspector.rb +27 -0
  26. data/lib/pry/commands/change_prompt.rb +26 -0
  27. data/lib/pry/commands/code_collector.rb +165 -0
  28. data/lib/pry/commands/disable_pry.rb +27 -0
  29. data/lib/pry/commands/disabled_commands.rb +2 -0
  30. data/lib/pry/commands/easter_eggs.rb +112 -0
  31. data/lib/pry/commands/edit.rb +195 -0
  32. data/lib/pry/commands/edit/exception_patcher.rb +25 -0
  33. data/lib/pry/commands/edit/file_and_line_locator.rb +36 -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 +23 -0
  37. data/lib/pry/commands/find_method.rb +193 -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 +32 -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 +101 -0
  44. data/lib/pry/commands/help.rb +164 -0
  45. data/lib/pry/commands/hist.rb +180 -0
  46. data/lib/pry/commands/import_set.rb +22 -0
  47. data/lib/pry/commands/install_command.rb +53 -0
  48. data/lib/pry/commands/jump_to.rb +29 -0
  49. data/lib/pry/commands/list_inspectors.rb +35 -0
  50. data/lib/pry/commands/list_prompts.rb +35 -0
  51. data/lib/pry/commands/ls.rb +114 -0
  52. data/lib/pry/commands/ls/constants.rb +47 -0
  53. data/lib/pry/commands/ls/formatter.rb +49 -0
  54. data/lib/pry/commands/ls/globals.rb +48 -0
  55. data/lib/pry/commands/ls/grep.rb +21 -0
  56. data/lib/pry/commands/ls/instance_vars.rb +39 -0
  57. data/lib/pry/commands/ls/interrogatable.rb +18 -0
  58. data/lib/pry/commands/ls/jruby_hacks.rb +49 -0
  59. data/lib/pry/commands/ls/local_names.rb +35 -0
  60. data/lib/pry/commands/ls/local_vars.rb +39 -0
  61. data/lib/pry/commands/ls/ls_entity.rb +70 -0
  62. data/lib/pry/commands/ls/methods.rb +57 -0
  63. data/lib/pry/commands/ls/methods_helper.rb +46 -0
  64. data/lib/pry/commands/ls/self_methods.rb +32 -0
  65. data/lib/pry/commands/nesting.rb +25 -0
  66. data/lib/pry/commands/play.rb +103 -0
  67. data/lib/pry/commands/pry_backtrace.rb +25 -0
  68. data/lib/pry/commands/pry_version.rb +17 -0
  69. data/lib/pry/commands/raise_up.rb +32 -0
  70. data/lib/pry/commands/reload_code.rb +62 -0
  71. data/lib/pry/commands/reset.rb +18 -0
  72. data/lib/pry/commands/ri.rb +60 -0
  73. data/lib/pry/commands/save_file.rb +61 -0
  74. data/lib/pry/commands/shell_command.rb +48 -0
  75. data/lib/pry/commands/shell_mode.rb +25 -0
  76. data/lib/pry/commands/show_doc.rb +83 -0
  77. data/lib/pry/commands/show_info.rb +195 -0
  78. data/lib/pry/commands/show_input.rb +17 -0
  79. data/lib/pry/commands/show_source.rb +50 -0
  80. data/lib/pry/commands/simple_prompt.rb +22 -0
  81. data/lib/pry/commands/stat.rb +40 -0
  82. data/lib/pry/commands/switch_to.rb +23 -0
  83. data/lib/pry/commands/toggle_color.rb +24 -0
  84. data/lib/pry/commands/watch_expression.rb +105 -0
  85. data/lib/pry/commands/watch_expression/expression.rb +38 -0
  86. data/lib/pry/commands/whereami.rb +190 -0
  87. data/lib/pry/commands/wtf.rb +57 -0
  88. data/lib/pry/config.rb +20 -229
  89. data/lib/pry/config/behavior.rb +139 -0
  90. data/lib/pry/config/convenience.rb +26 -0
  91. data/lib/pry/config/default.rb +165 -0
  92. data/lib/pry/core_extensions.rb +59 -38
  93. data/lib/pry/editor.rb +133 -0
  94. data/lib/pry/exceptions.rb +77 -0
  95. data/lib/pry/helpers.rb +1 -0
  96. data/lib/pry/helpers/base_helpers.rb +40 -154
  97. data/lib/pry/helpers/command_helpers.rb +19 -130
  98. data/lib/pry/helpers/documentation_helpers.rb +21 -11
  99. data/lib/pry/helpers/table.rb +109 -0
  100. data/lib/pry/helpers/text.rb +8 -9
  101. data/lib/pry/history.rb +61 -45
  102. data/lib/pry/history_array.rb +11 -1
  103. data/lib/pry/hooks.rb +10 -32
  104. data/lib/pry/indent.rb +110 -38
  105. data/lib/pry/input_completer.rb +242 -0
  106. data/lib/pry/input_lock.rb +132 -0
  107. data/lib/pry/inspector.rb +27 -0
  108. data/lib/pry/last_exception.rb +61 -0
  109. data/lib/pry/method.rb +199 -200
  110. data/lib/pry/method/disowned.rb +53 -0
  111. data/lib/pry/method/patcher.rb +125 -0
  112. data/lib/pry/method/weird_method_locator.rb +186 -0
  113. data/lib/pry/module_candidate.rb +39 -33
  114. data/lib/pry/object_path.rb +82 -0
  115. data/lib/pry/output.rb +50 -0
  116. data/lib/pry/pager.rb +234 -0
  117. data/lib/pry/plugins.rb +4 -3
  118. data/lib/pry/prompt.rb +26 -0
  119. data/lib/pry/pry_class.rb +199 -227
  120. data/lib/pry/pry_instance.rb +344 -403
  121. data/lib/pry/rbx_path.rb +1 -1
  122. data/lib/pry/repl.rb +202 -0
  123. data/lib/pry/repl_file_loader.rb +20 -26
  124. data/lib/pry/rubygem.rb +82 -0
  125. data/lib/pry/terminal.rb +79 -0
  126. data/lib/pry/test/helper.rb +170 -0
  127. data/lib/pry/version.rb +1 -1
  128. data/lib/pry/wrapped_module.rb +133 -48
  129. metadata +132 -197
  130. data/.document +0 -2
  131. data/.gemtest +0 -0
  132. data/.gitignore +0 -16
  133. data/.travis.yml +0 -17
  134. data/.yardopts +0 -1
  135. data/CHANGELOG +0 -387
  136. data/CONTRIBUTORS +0 -36
  137. data/Gemfile +0 -2
  138. data/Rakefile +0 -137
  139. data/TODO +0 -117
  140. data/examples/example_basic.rb +0 -15
  141. data/examples/example_command_override.rb +0 -32
  142. data/examples/example_commands.rb +0 -36
  143. data/examples/example_hooks.rb +0 -9
  144. data/examples/example_image_edit.rb +0 -67
  145. data/examples/example_input.rb +0 -7
  146. data/examples/example_input2.rb +0 -29
  147. data/examples/example_output.rb +0 -11
  148. data/examples/example_print.rb +0 -6
  149. data/examples/example_prompt.rb +0 -9
  150. data/examples/helper.rb +0 -6
  151. data/lib/pry/completion.rb +0 -221
  152. data/lib/pry/custom_completions.rb +0 -6
  153. data/lib/pry/default_commands/cd.rb +0 -81
  154. data/lib/pry/default_commands/commands.rb +0 -62
  155. data/lib/pry/default_commands/context.rb +0 -98
  156. data/lib/pry/default_commands/easter_eggs.rb +0 -95
  157. data/lib/pry/default_commands/editing.rb +0 -420
  158. data/lib/pry/default_commands/find_method.rb +0 -169
  159. data/lib/pry/default_commands/gems.rb +0 -84
  160. data/lib/pry/default_commands/gist.rb +0 -187
  161. data/lib/pry/default_commands/help.rb +0 -127
  162. data/lib/pry/default_commands/hist.rb +0 -120
  163. data/lib/pry/default_commands/input_and_output.rb +0 -306
  164. data/lib/pry/default_commands/introspection.rb +0 -410
  165. data/lib/pry/default_commands/ls.rb +0 -272
  166. data/lib/pry/default_commands/misc.rb +0 -38
  167. data/lib/pry/default_commands/navigating_pry.rb +0 -110
  168. data/lib/pry/default_commands/whereami.rb +0 -92
  169. data/lib/pry/extended_commands/experimental.rb +0 -7
  170. data/lib/pry/rbx_method.rb +0 -13
  171. data/man/pry.1 +0 -195
  172. data/man/pry.1.html +0 -204
  173. data/man/pry.1.ronn +0 -141
  174. data/pry.gemspec +0 -46
  175. data/test/candidate_helper1.rb +0 -11
  176. data/test/candidate_helper2.rb +0 -8
  177. data/test/helper.rb +0 -223
  178. data/test/test_cli.rb +0 -78
  179. data/test/test_code.rb +0 -201
  180. data/test/test_command.rb +0 -712
  181. data/test/test_command_helpers.rb +0 -9
  182. data/test/test_command_integration.rb +0 -668
  183. data/test/test_command_set.rb +0 -610
  184. data/test/test_completion.rb +0 -62
  185. data/test/test_control_d_handler.rb +0 -45
  186. data/test/test_default_commands/example.erb +0 -5
  187. data/test/test_default_commands/test_cd.rb +0 -318
  188. data/test/test_default_commands/test_context.rb +0 -280
  189. data/test/test_default_commands/test_documentation.rb +0 -314
  190. data/test/test_default_commands/test_find_method.rb +0 -50
  191. data/test/test_default_commands/test_gems.rb +0 -18
  192. data/test/test_default_commands/test_help.rb +0 -57
  193. data/test/test_default_commands/test_input.rb +0 -428
  194. data/test/test_default_commands/test_introspection.rb +0 -511
  195. data/test/test_default_commands/test_ls.rb +0 -151
  196. data/test/test_default_commands/test_shell.rb +0 -343
  197. data/test/test_default_commands/test_show_source.rb +0 -432
  198. data/test/test_exception_whitelist.rb +0 -21
  199. data/test/test_history_array.rb +0 -65
  200. data/test/test_hooks.rb +0 -521
  201. data/test/test_indent.rb +0 -277
  202. data/test/test_input_stack.rb +0 -86
  203. data/test/test_method.rb +0 -401
  204. data/test/test_pry.rb +0 -463
  205. data/test/test_pry_defaults.rb +0 -419
  206. data/test/test_pry_history.rb +0 -84
  207. data/test/test_pry_output.rb +0 -41
  208. data/test/test_sticky_locals.rb +0 -155
  209. data/test/test_syntax_checking.rb +0 -65
  210. data/test/test_wrapped_module.rb +0 -174
  211. data/test/testrc +0 -2
  212. data/test/testrcbad +0 -2
  213. data/wiki/Customizing-pry.md +0 -397
  214. data/wiki/Home.md +0 -4
data/test/test_command.rb DELETED
@@ -1,712 +0,0 @@
1
- require 'helper'
2
-
3
- describe "Pry::Command" do
4
-
5
- before do
6
- @set = Pry::CommandSet.new
7
- @set.import Pry::DefaultCommands::Help
8
- end
9
-
10
- describe 'call_safely' do
11
-
12
- it 'should display a message if gems are missing' do
13
- cmd = @set.create_command "ford-prefect", "From a planet near Beetlegeuse", :requires_gem => %w(ghijkl) do
14
- #
15
- end
16
-
17
- mock_command(cmd, %w(hello world)).output.should =~ /install-command ford-prefect/
18
- end
19
-
20
- it 'should abort early if arguments are required' do
21
- cmd = @set.create_command 'arthur-dent', "Doesn't understand Thursdays", :argument_required => true do
22
- #
23
- end
24
-
25
- lambda {
26
- mock_command(cmd, %w())
27
- }.should.raise(Pry::CommandError)
28
- end
29
-
30
- it 'should return VOID without keep_retval' do
31
- cmd = @set.create_command 'zaphod-beeblebrox', "Likes pan-Galactic Gargle Blasters" do
32
- def process
33
- 3
34
- end
35
- end
36
-
37
- mock_command(cmd).return.should == Pry::Command::VOID_VALUE
38
- end
39
-
40
- it 'should return the return value with keep_retval' do
41
- cmd = @set.create_command 'tricia-mcmillian', "a.k.a Trillian", :keep_retval => true do
42
- def process
43
- 5
44
- end
45
- end
46
-
47
- mock_command(cmd).return.should == 5
48
- end
49
-
50
- it 'should call hooks in the right order' do
51
- cmd = @set.create_command 'marvin', "Pained by the diodes in his left side" do
52
- def process
53
- output.puts 3 + args[0].to_i
54
- end
55
- end
56
-
57
- @set.before_command 'marvin' do |i|
58
- output.puts 2 + i.to_i
59
- end
60
- @set.before_command 'marvin' do |i|
61
- output.puts 1 + i.to_i
62
- end
63
-
64
- @set.after_command 'marvin' do |i|
65
- output.puts 4 + i.to_i
66
- end
67
-
68
- @set.after_command 'marvin' do |i|
69
- output.puts 5 + i.to_i
70
- end
71
-
72
- mock_command(cmd, %w(2)).output.should == "3\n4\n5\n6\n7\n"
73
- end
74
-
75
- # TODO: This strikes me as rather silly...
76
- it 'should return the value from the last hook with keep_retval' do
77
- cmd = @set.create_command 'slartibartfast', "Designs Fjords", :keep_retval => true do
78
- def process
79
- 22
80
- end
81
- end
82
-
83
- @set.after_command 'slartibartfast' do
84
- 10
85
- end
86
-
87
- mock_command(cmd).return.should == 10
88
- end
89
- end
90
-
91
- describe 'help' do
92
- it 'should default to the description for blocky commands' do
93
- @set.command 'oolon-colluphid', "Raving Atheist" do
94
- #
95
- end
96
-
97
- mock_command(@set.commands['help'], %w(oolon-colluphid), :command_set => @set).output.should =~ /Raving Atheist/
98
- end
99
-
100
- it 'should use slop to generate the help for classy commands' do
101
- @set.create_command 'eddie', "The ship-board computer" do
102
- def options(opt)
103
- opt.banner "Over-cheerful, and makes a ticking noise."
104
- end
105
- end
106
-
107
- mock_command(@set.commands['help'], %w(eddie), :command_set => @set).output.should =~ /Over-cheerful/
108
- end
109
-
110
- it 'should provide --help for classy commands' do
111
- cmd = @set.create_command 'agrajag', "Killed many times by Arthur" do
112
- def options(opt)
113
- opt.on :r, :retaliate, "Try to get Arthur back"
114
- end
115
- end
116
-
117
- mock_command(cmd, %w(--help)).output.should =~ /--retaliate/
118
- end
119
-
120
- it 'should provide a -h for classy commands' do
121
- cmd = @set.create_command 'zarniwoop', "On an intergalactic cruise, in his office." do
122
- def options(opt)
123
- opt.on :e, :escape, "Help zaphod escape the Total Perspective Vortex"
124
- end
125
- end
126
-
127
- mock_command(cmd, %w(--help)).output.should =~ /Total Perspective Vortex/
128
- end
129
-
130
- it 'should use the banner provided' do
131
- cmd = @set.create_command 'deep-thought', "The second-best computer ever" do
132
- banner <<-BANNER
133
- Who's merest operational parameters, I am not worthy to compute.
134
- BANNER
135
- end
136
-
137
- mock_command(cmd, %w(--help)).output.should =~ /Who\'s merest/
138
- end
139
- end
140
-
141
-
142
- describe 'context' do
143
- context = {
144
- :target => binding,
145
- :output => StringIO.new,
146
- :eval_string => "eval-string",
147
- :command_set => @set,
148
- :pry_instance => Object.new
149
- }
150
-
151
- it 'should capture lots of stuff from the hash passed to new before setup' do
152
- cmd = @set.create_command 'fenchurch', "Floats slightly off the ground" do
153
- define_method(:setup) do
154
- self.context.should == context
155
- target.should == context[:target]
156
- target_self.should == context[:target].eval('self')
157
- output.should == context[:output]
158
- end
159
-
160
- define_method(:process) do
161
- eval_string.should == "eval-string"
162
- command_set.should == @set
163
- _pry_.should == context[:pry_instance]
164
- end
165
- end
166
-
167
- cmd.new(context).call
168
- end
169
- end
170
-
171
- describe 'classy api' do
172
-
173
- it 'should call setup, then options, then process' do
174
- cmd = @set.create_command 'rooster', "Has a tasty towel" do
175
- def setup
176
- output.puts "setup"
177
- end
178
-
179
- def options(opt)
180
- output.puts "options"
181
- end
182
-
183
- def process
184
- output.puts "process"
185
- end
186
- end
187
-
188
- mock_command(cmd).output.should == "setup\noptions\nprocess\n"
189
- end
190
-
191
- it 'should raise a command error if process is not overridden' do
192
- cmd = @set.create_command 'jeltz', "Commander of a Vogon constructor fleet" do
193
- def proccces
194
- #
195
- end
196
- end
197
-
198
- lambda {
199
- mock_command(cmd)
200
- }.should.raise(Pry::CommandError)
201
- end
202
-
203
- it 'should work if neither options, nor setup is overridden' do
204
- cmd = @set.create_command 'wowbagger', "Immortal, insulting.", :keep_retval => true do
205
- def process
206
- 5
207
- end
208
- end
209
-
210
- mock_command(cmd).return.should == 5
211
- end
212
-
213
- it 'should provide opts and args as provided by slop' do
214
- cmd = @set.create_command 'lintilla', "One of 800,000,000 clones" do
215
- def options(opt)
216
- opt.on :f, :four, "A numeric four", :as => Integer, :optional_argument => true
217
- end
218
-
219
- def process
220
- args.should == ['four']
221
- opts[:f].should == 4
222
- end
223
- end
224
-
225
- mock_command(cmd, %w(--four 4 four))
226
- end
227
-
228
- it 'should allow overriding options after definition' do
229
- cmd = @set.create_command /number-(one|two)/, "Lieutenants of the Golgafrinchan Captain", :shellwords => false do
230
-
231
- command_options :listing => 'number-one'
232
- end
233
-
234
- cmd.command_options[:shellwords].should == false
235
- cmd.command_options[:listing].should == 'number-one'
236
- end
237
- end
238
-
239
- describe 'tokenize' do
240
- it 'should interpolate string with #{} in them' do
241
- cmd = @set.command 'random-dent' do |*args|
242
- args.should == ["3", "8"]
243
- end
244
-
245
- foo = 5
246
-
247
- cmd.new(:target => binding).process_line 'random-dent #{1 + 2} #{3 + foo}'
248
- end
249
-
250
- it 'should not fail if interpolation is not needed and target is not set' do
251
- cmd = @set.command 'the-book' do |*args|
252
- args.should == ['--help']
253
- end
254
-
255
- cmd.new.process_line 'the-book --help'
256
- end
257
-
258
- it 'should not interpolate commands with :interpolate => false' do
259
- cmd = @set.command 'thor', 'norse god', :interpolate => false do |*args|
260
- args.should == ['%(#{foo})']
261
- end
262
-
263
- cmd.new.process_line 'thor %(#{foo})'
264
- end
265
-
266
- it 'should use shell-words to split strings' do
267
- cmd = @set.command 'eccentrica' do |*args|
268
- args.should == ['gallumbits', 'eroticon', '6']
269
- end
270
-
271
- cmd.new.process_line %(eccentrica "gallumbits" 'erot''icon' 6)
272
- end
273
-
274
- it 'should split on spaces if shellwords is not used' do
275
- cmd = @set.command 'bugblatter-beast', 'would eat its grandmother', :shellwords => false do |*args|
276
- args.should == ['"of', 'traal"']
277
- end
278
-
279
- cmd.new.process_line %(bugblatter-beast "of traal")
280
- end
281
-
282
- it 'should add captures to arguments for regex commands' do
283
- cmd = @set.command /perfectly (normal)( beast)?/i do |*args|
284
- args.should == ['Normal', ' Beast', '(honest!)']
285
- end
286
-
287
- cmd.new.process_line %(Perfectly Normal Beast (honest!))
288
- end
289
- end
290
-
291
- describe 'process_line' do
292
- it 'should check for command name collisions if configured' do
293
- old = Pry.config.collision_warning
294
- Pry.config.collision_warning = true
295
-
296
- cmd = @set.command 'frankie' do
297
-
298
- end
299
-
300
- frankie = 'boyle'
301
- output = StringIO.new
302
- cmd.new(:target => binding, :output => output).process_line %(frankie mouse)
303
-
304
- output.string.should =~ /command .* conflicts/
305
-
306
- Pry.config.collision_warning = old
307
- end
308
-
309
- it 'should spot collision warnings on assignment if configured' do
310
- old = Pry.config.collision_warning
311
- Pry.config.collision_warning = true
312
-
313
- cmd = @set.command 'frankie' do
314
-
315
- end
316
-
317
- output = StringIO.new
318
- cmd.new(:target => binding, :output => output).process_line %(frankie = mouse)
319
-
320
- output.string.should =~ /command .* conflicts/
321
-
322
- Pry.config.collision_warning = old
323
- end
324
-
325
- it "should set the commands' arg_string and captures" do
326
-
327
- cmd = @set.command /benj(ie|ei)/ do |*args|
328
- self.arg_string.should == "mouse"
329
- self.captures.should == ['ie']
330
- args.should == ['ie', 'mouse']
331
- end
332
-
333
- cmd.new.process_line %(benjie mouse)
334
- end
335
-
336
- it "should raise an error if the line doesn't match the command" do
337
- cmd = @set.command 'grunthos', 'the flatulent'
338
-
339
- lambda {
340
- cmd.new.process_line %(grumpos)
341
- }.should.raise(Pry::CommandError)
342
- end
343
- end
344
-
345
- describe "block parameters" do
346
- before do
347
- @context = Object.new
348
- @set.command "walking-spanish", "down the hall", :takes_block => true do
349
- inject_var(:@x, command_block.call, target)
350
- end
351
- @set.import Pry::Commands
352
- end
353
-
354
- it 'should accept multiline blocks' do
355
- redirect_pry_io(InputTester.new("walking-spanish | do",
356
- " :jesus",
357
- "end",
358
- "exit-all"), out = StringIO.new) do
359
- Pry.start @context, :commands => @set
360
- end
361
- @context.instance_variable_get(:@x).should == :jesus
362
- end
363
-
364
- it 'should accept normal parameters along with block' do
365
- @set.block_command "walking-spanish", "litella's been screeching for a blind pig.", :takes_block => true do |x, y|
366
- inject_var(:@x, x, target)
367
- inject_var(:@y, y, target)
368
- inject_var(:@block_var, command_block.call, target)
369
- end
370
- redirect_pry_io(InputTester.new("walking-spanish john carl| { :jesus }",
371
- "exit-all")) do
372
- Pry.start @context, :commands => @set
373
- end
374
-
375
- @context.instance_variable_get(:@x).should == "john"
376
- @context.instance_variable_get(:@y).should == "carl"
377
- @context.instance_variable_get(:@block_var).should == :jesus
378
- end
379
-
380
- describe "single line blocks" do
381
- it 'should accept blocks with do ; end' do
382
- redirect_pry_io(InputTester.new("walking-spanish | do ; :jesus; end",
383
- "exit-all"), out = StringIO.new) do
384
- Pry.start @context, :commands => @set
385
- end
386
- @context.instance_variable_get(:@x).should == :jesus
387
- end
388
-
389
- it 'should accept blocks with do; end' do
390
- redirect_pry_io(InputTester.new("walking-spanish | do; :jesus; end",
391
- "exit-all"), out = StringIO.new) do
392
- Pry.start @context, :commands => @set
393
- end
394
- @context.instance_variable_get(:@x).should == :jesus
395
- end
396
-
397
- it 'should accept blocks with { }' do
398
- redirect_pry_io(InputTester.new("walking-spanish | { :jesus }",
399
- "exit-all"), out = StringIO.new) do
400
- Pry.start @context, :commands => @set
401
- end
402
- @context.instance_variable_get(:@x).should == :jesus
403
- end
404
-
405
- end
406
-
407
- describe "block-related content removed from arguments" do
408
-
409
- describe "arg_string" do
410
- it 'should remove block-related content from arg_string (with one normal arg)' do
411
- @set.block_command "walking-spanish", "down the hall", :takes_block => true do |x, y|
412
- inject_var(:@arg_string, arg_string, target)
413
- inject_var(:@x, x, target)
414
- end
415
- redirect_pry_io(InputTester.new("walking-spanish john| { :jesus }",
416
- "exit-all")) do
417
- Pry.start @context, :commands => @set
418
- end
419
- @context.instance_variable_get(:@arg_string).should == @context.instance_variable_get(:@x)
420
- end
421
-
422
- it 'should remove block-related content from arg_string (with no normal args)' do
423
- @set.block_command "walking-spanish", "down the hall", :takes_block => true do
424
- inject_var(:@arg_string, arg_string, target)
425
- end
426
- redirect_pry_io(InputTester.new("walking-spanish | { :jesus }",
427
- "exit-all")) do
428
- Pry.start @context, :commands => @set
429
- end
430
- @context.instance_variable_get(:@arg_string).should == ""
431
- end
432
-
433
- it 'should NOT remove block-related content from arg_string when :takes_block => false' do
434
- block_string = "| { :jesus }"
435
- @set.block_command "walking-spanish", "homemade special", :takes_block => false do
436
- inject_var(:@arg_string, arg_string, target)
437
- end
438
- redirect_pry_io(InputTester.new("walking-spanish #{block_string}",
439
- "exit-all")) do
440
- Pry.start @context, :commands => @set
441
- end
442
- @context.instance_variable_get(:@arg_string).should == block_string
443
- end
444
- end
445
-
446
- describe "args" do
447
- describe "block_command" do
448
- it "should remove block-related content from arguments" do
449
- @set.block_command "walking-spanish", "glass is full of sand", :takes_block => true do |x, y|
450
- inject_var(:@x, x, target)
451
- inject_var(:@y, y, target)
452
- end
453
- redirect_pry_io(InputTester.new("walking-spanish | { :jesus }",
454
- "exit-all"), out = StringIO.new) do
455
- Pry.start @context, :commands => @set
456
- end
457
- @context.instance_variable_get(:@x).should == nil
458
- @context.instance_variable_get(:@y).should == nil
459
- end
460
-
461
- it "should NOT remove block-related content from arguments if :takes_block => false" do
462
- @set.block_command "walking-spanish", "litella screeching for a blind pig", :takes_block => false do |x, y|
463
- inject_var(:@x, x, target)
464
- inject_var(:@y, y, target)
465
- end
466
- redirect_pry_io(InputTester.new("walking-spanish | { :jesus }",
467
- "exit-all"), out = StringIO.new) do
468
- Pry.start @context, :commands => @set
469
- end
470
- @context.instance_variable_get(:@x).should == "|"
471
- @context.instance_variable_get(:@y).should == "{"
472
- end
473
- end
474
-
475
- describe "create_command" do
476
- it "should remove block-related content from arguments" do
477
- @set.create_command "walking-spanish", "punk sanders carved one out of wood", :takes_block => true do
478
- def process(x, y)
479
- inject_var(:@x, x, target)
480
- inject_var(:@y, y, target)
481
- end
482
- end
483
- redirect_pry_io(InputTester.new("walking-spanish | { :jesus }",
484
- "exit-all"), out = StringIO.new) do
485
- Pry.start @context, :commands => @set
486
- end
487
- @context.instance_variable_get(:@x).should == nil
488
- @context.instance_variable_get(:@y).should == nil
489
- end
490
-
491
- it "should NOT remove block-related content from arguments if :takes_block => false" do
492
- @set.create_command "walking-spanish", "down the hall", :takes_block => false do
493
- def process(x, y)
494
- inject_var(:@x, x, target)
495
- inject_var(:@y, y, target)
496
- end
497
- end
498
- redirect_pry_io(InputTester.new("walking-spanish | { :jesus }",
499
- "exit-all")) do
500
- Pry.start @context, :commands => @set
501
- end
502
- @context.instance_variable_get(:@x).should == "|"
503
- @context.instance_variable_get(:@y).should == "{"
504
- end
505
- end
506
- end
507
- end
508
-
509
- describe "blocks can take parameters" do
510
- describe "{} style blocks" do
511
- it 'should accept multiple parameters' do
512
- @set.block_command "walking-spanish", "down the hall", :takes_block => true do
513
- inject_var(:@x, command_block.call(1, 2), target)
514
- end
515
-
516
- redirect_pry_io(InputTester.new("walking-spanish | { |x, y| [x, y] }",
517
- "exit-all")) do
518
- Pry.start @context, :commands => @set
519
- end
520
- @context.instance_variable_get(:@x).should == [1, 2]
521
- end
522
- end
523
-
524
- describe "do/end style blocks" do
525
- it 'should accept multiple parameters' do
526
- @set.create_command "walking-spanish", "litella", :takes_block => true do
527
- def process
528
- inject_var(:@x, command_block.call(1, 2), target)
529
- end
530
- end
531
-
532
- redirect_pry_io(InputTester.new("walking-spanish | do |x, y|",
533
- " [x, y]",
534
- "end",
535
- "exit-all")) do
536
- Pry.start @context, :commands => @set
537
- end
538
- @context.instance_variable_get(:@x).should == [1, 2]
539
- end
540
- end
541
- end
542
-
543
- describe "closure behaviour" do
544
- it 'should close over locals in the definition context' do
545
- redirect_pry_io(InputTester.new("var = :hello",
546
- "walking-spanish | { var }",
547
- "exit-all")) do
548
- Pry.start @context, :commands => @set
549
- end
550
- @context.instance_variable_get(:@x).should == :hello
551
- end
552
- end
553
-
554
- describe "exposing block parameter" do
555
- describe "block_command" do
556
- it "should expose block in command_block method" do
557
- @set.block_command "walking-spanish", "glass full of sand", :takes_block => true do
558
- inject_var(:@x, command_block.call, target)
559
- end
560
- redirect_pry_io(InputTester.new("walking-spanish | { :jesus }",
561
- "exit-all")) do
562
- Pry.start @context, :commands => @set
563
- end
564
- @context.instance_variable_get(:@x).should == :jesus
565
- end
566
- end
567
-
568
- describe "create_command" do
569
- it "should NOT expose &block in create_command's process method" do
570
- @set.create_command "walking-spanish", "down the hall", :takes_block => true do
571
- def process(&block)
572
- inject_var(:@x, block.call, target)
573
- end
574
- end
575
- redirect_pry_io(InputTester.new("walking-spanish | { :jesus }",
576
- "exit-all")) do
577
- Pry.start @context, :commands => @set
578
- end
579
- @context.instance_variable_get(:@x).should == nil
580
- end
581
-
582
- it "should expose block in command_block method" do
583
- @set.create_command "walking-spanish", "homemade special", :takes_block => true do
584
- def process
585
- inject_var(:@x, command_block.call, target)
586
- end
587
- end
588
- redirect_pry_io(InputTester.new("walking-spanish | { :jesus }",
589
- "exit-all"), out = StringIO.new) do
590
- Pry.start @context, :commands => @set
591
- end
592
- @context.instance_variable_get(:@x).should == :jesus
593
- end
594
- end
595
- end
596
- end
597
-
598
- describe "commands made with custom sub-classes" do
599
- before do
600
-
601
- class MyTestCommand < Pry::ClassCommand
602
- match /my-*test/
603
- description "So just how many sound technicians does it take to change a lightbulb? 1? 2? 3? 1-2-3? Testing?"
604
- options :shellwords => false, :listing => "my-test"
605
-
606
- def process
607
- output.puts command_name * 2
608
- end
609
- end
610
-
611
- Pry.commands.add_command MyTestCommand
612
- end
613
-
614
- after do
615
- Pry.commands.delete 'my-test'
616
- end
617
-
618
- it "should allow creating custom sub-classes of Pry::Command" do
619
- mock_pry("my---test").should =~ /my-testmy-test/
620
- end
621
-
622
- it "should show the source of the process method" do
623
- mock_pry("show-command my-test").should =~ /output.puts command_name/
624
- end
625
- end
626
-
627
- describe "commands can save state" do
628
- before do
629
- @set = Pry::CommandSet.new do
630
- create_command "litella", "desc" do
631
- def process
632
- state.my_state ||= 0
633
- state.my_state += 1
634
- end
635
- end
636
-
637
- create_command "sanders", "desc" do
638
- def process
639
- state.my_state = "wood"
640
- end
641
- end
642
-
643
- create_command /[Hh]ello-world/, "desc" do
644
- def process
645
- state.my_state ||= 0
646
- state.my_state += 2
647
- end
648
- end
649
-
650
- end.import Pry::Commands
651
- end
652
-
653
- it 'should save state for the command on the Pry#command_state hash' do
654
- instance = nil
655
- redirect_pry_io(InputTester.new("litella",
656
- "exit-all")) do
657
- instance = Pry.new(:commands => @set)
658
- instance.repl
659
- end
660
-
661
- instance.command_state["litella"].my_state.should == 1
662
- end
663
-
664
- it 'should ensure state is maintained between multiple invocations of command' do
665
- instance = nil
666
- redirect_pry_io(InputTester.new("litella", "litella",
667
- "exit-all")) do
668
- instance = Pry.new(:commands => @set)
669
- instance.repl
670
- end
671
-
672
- instance.command_state["litella"].my_state.should == 2
673
- end
674
-
675
- it 'should ensure state with same name stored seperately for each command' do
676
- instance = nil
677
- redirect_pry_io(InputTester.new("litella", "sanders", "exit-all")) do
678
- instance = Pry.new(:commands => @set)
679
- instance.repl
680
- end
681
-
682
- instance.command_state["litella"].my_state.should == 1
683
- instance.command_state["sanders"].my_state.should =="wood"
684
- end
685
-
686
- it 'should ensure state is properly saved for regex commands' do
687
- instance = nil
688
- redirect_pry_io(InputTester.new("hello-world", "Hello-world", "exit-all")) do
689
- instance = Pry.new(:commands => @set)
690
- instance.repl
691
- end
692
-
693
- instance.command_state[/[Hh]ello-world/].my_state.should == 4
694
- end
695
- end
696
-
697
- describe 'group' do
698
- before do
699
- @set.import Pry::DefaultCommands::Cd
700
- end
701
-
702
- it 'should not change once it is initialized' do
703
- @set.commands["cd"].group("-==CD COMMAND==-")
704
- @set.commands["cd"].group.should == "Context"
705
- end
706
-
707
- it 'should be correct for default commands' do
708
- @set.commands["cd"].group.should == "Context"
709
- @set.commands["help"].group.should == "Help"
710
- end
711
- end
712
- end