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,821 +0,0 @@
1
- require 'helper'
2
-
3
- describe "Pry::Command" do
4
-
5
- before do
6
- @set = Pry::CommandSet.new
7
- @set.import Pry::Commands
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
- describe 'context' do
142
- context = {
143
- :target => binding,
144
- :output => StringIO.new,
145
- :eval_string => "eval-string",
146
- :command_set => @set,
147
- :pry_instance => Object.new
148
- }
149
-
150
- it 'should capture lots of stuff from the hash passed to new before setup' do
151
- cmd = @set.create_command 'fenchurch', "Floats slightly off the ground" do
152
- define_method(:setup) do
153
- self.context.should == context
154
- target.should == context[:target]
155
- target_self.should == context[:target].eval('self')
156
- output.should == context[:output]
157
- end
158
-
159
- define_method(:process) do
160
- eval_string.should == "eval-string"
161
- command_set.should == @set
162
- _pry_.should == context[:pry_instance]
163
- end
164
- end
165
-
166
- cmd.new(context).call
167
- end
168
- end
169
-
170
- describe 'classy api' do
171
-
172
- it 'should call setup, then subcommands, then options, then process' do
173
- cmd = @set.create_command 'rooster', "Has a tasty towel" do
174
- def setup
175
- output.puts "setup"
176
- end
177
-
178
- def subcommands(cmd)
179
- output.puts "subcommands"
180
- end
181
-
182
- def options(opt)
183
- output.puts "options"
184
- end
185
-
186
- def process
187
- output.puts "process"
188
- end
189
- end
190
-
191
- mock_command(cmd).output.should == "setup\nsubcommands\noptions\nprocess\n"
192
- end
193
-
194
- it 'should raise a command error if process is not overridden' do
195
- cmd = @set.create_command 'jeltz', "Commander of a Vogon constructor fleet" do
196
- def proccces
197
- #
198
- end
199
- end
200
-
201
- lambda {
202
- mock_command(cmd)
203
- }.should.raise(Pry::CommandError)
204
- end
205
-
206
- it 'should work if neither options, nor setup is overridden' do
207
- cmd = @set.create_command 'wowbagger', "Immortal, insulting.", :keep_retval => true do
208
- def process
209
- 5
210
- end
211
- end
212
-
213
- mock_command(cmd).return.should == 5
214
- end
215
-
216
- it 'should provide opts and args as provided by slop' do
217
- cmd = @set.create_command 'lintilla', "One of 800,000,000 clones" do
218
- def options(opt)
219
- opt.on :f, :four, "A numeric four", :as => Integer, :optional_argument => true
220
- end
221
-
222
- def process
223
- args.should == ['four']
224
- opts[:f].should == 4
225
- end
226
- end
227
-
228
- mock_command(cmd, %w(--four 4 four))
229
- end
230
-
231
- it 'should allow overriding options after definition' do
232
- cmd = @set.create_command /number-(one|two)/, "Lieutenants of the Golgafrinchan Captain", :shellwords => false do
233
-
234
- command_options :listing => 'number-one'
235
- end
236
-
237
- cmd.command_options[:shellwords].should == false
238
- cmd.command_options[:listing].should == 'number-one'
239
- end
240
-
241
- it "should create subcommands" do
242
- cmd = @set.create_command 'mum', 'Your mum' do
243
- def subcommands(cmd)
244
- cmd.command :yell
245
- end
246
-
247
- def process
248
- opts.fetch_command(:blahblah).should == nil
249
- opts.fetch_command(:yell).present?.should == true
250
- end
251
- end
252
-
253
- mock_command(cmd, ['yell'])
254
- end
255
-
256
- it "should create subcommand options" do
257
- cmd = @set.create_command 'mum', 'Your mum' do
258
- def subcommands(cmd)
259
- cmd.command :yell do
260
- on :p, :person
261
- end
262
- end
263
-
264
- def process
265
- args.should == ['papa']
266
- opts.fetch_command(:yell).present?.should == true
267
- opts.fetch_command(:yell).person?.should == true
268
- end
269
- end
270
-
271
- mock_command(cmd, %w|yell --person papa|)
272
- end
273
-
274
- it "should accept top-level arguments" do
275
- cmd = @set.create_command 'mum', 'Your mum' do
276
- def subcommands(cmd)
277
- cmd.on :yell
278
- end
279
-
280
- def process
281
- args.should == ['yell', 'papa', 'sonny', 'daughter']
282
- end
283
- end
284
-
285
- mock_command(cmd, %w|yell papa sonny daughter|)
286
- end
287
-
288
- describe "explicit classes" do
289
- before do
290
- @x = Class.new(Pry::ClassCommand) do
291
- options :baby => :pig
292
- match /goat/
293
- description "waaaninngggiiigygygygygy"
294
- end
295
- end
296
-
297
- it 'subclasses should inherit options, match and description from superclass' do
298
- k = Class.new(@x)
299
- k.options.should == @x.options
300
- k.match.should == @x.match
301
- k.description.should == @x.description
302
- end
303
- end
304
- end
305
-
306
- describe 'tokenize' do
307
- it 'should interpolate string with #{} in them' do
308
- cmd = @set.command 'random-dent' do |*args|
309
- args.should == ["3", "8"]
310
- end
311
-
312
- foo = 5
313
-
314
- cmd.new(:target => binding).process_line 'random-dent #{1 + 2} #{3 + foo}'
315
- end
316
-
317
- it 'should not fail if interpolation is not needed and target is not set' do
318
- cmd = @set.command 'the-book' do |*args|
319
- args.should == ['--help']
320
- end
321
-
322
- cmd.new.process_line 'the-book --help'
323
- end
324
-
325
- it 'should not interpolate commands with :interpolate => false' do
326
- cmd = @set.command 'thor', 'norse god', :interpolate => false do |*args|
327
- args.should == ['%(#{foo})']
328
- end
329
-
330
- cmd.new.process_line 'thor %(#{foo})'
331
- end
332
-
333
- it 'should use shell-words to split strings' do
334
- cmd = @set.command 'eccentrica' do |*args|
335
- args.should == ['gallumbits', 'eroticon', '6']
336
- end
337
-
338
- cmd.new.process_line %(eccentrica "gallumbits" 'erot''icon' 6)
339
- end
340
-
341
- it 'should split on spaces if shellwords is not used' do
342
- cmd = @set.command 'bugblatter-beast', 'would eat its grandmother', :shellwords => false do |*args|
343
- args.should == ['"of', 'traal"']
344
- end
345
-
346
- cmd.new.process_line %(bugblatter-beast "of traal")
347
- end
348
-
349
- it 'should add captures to arguments for regex commands' do
350
- cmd = @set.command /perfectly (normal)( beast)?/i do |*args|
351
- args.should == ['Normal', ' Beast', '(honest!)']
352
- end
353
-
354
- cmd.new.process_line %(Perfectly Normal Beast (honest!))
355
- end
356
- end
357
-
358
- describe 'process_line' do
359
- it 'should check for command name collisions if configured' do
360
- old = Pry.config.collision_warning
361
- Pry.config.collision_warning = true
362
-
363
- cmd = @set.command 'frankie' do
364
-
365
- end
366
-
367
- frankie = 'boyle'
368
- output = StringIO.new
369
- cmd.new(:target => binding, :output => output).process_line %(frankie mouse)
370
-
371
- output.string.should =~ /command .* conflicts/
372
-
373
- Pry.config.collision_warning = old
374
- end
375
-
376
- it 'should spot collision warnings on assignment if configured' do
377
- old = Pry.config.collision_warning
378
- Pry.config.collision_warning = true
379
-
380
- cmd = @set.command 'frankie' do
381
-
382
- end
383
-
384
- output = StringIO.new
385
- cmd.new(:target => binding, :output => output).process_line %(frankie = mouse)
386
-
387
- output.string.should =~ /command .* conflicts/
388
-
389
- Pry.config.collision_warning = old
390
- end
391
-
392
- it "should set the commands' arg_string and captures" do
393
-
394
- cmd = @set.command /benj(ie|ei)/ do |*args|
395
- self.arg_string.should == "mouse"
396
- self.captures.should == ['ie']
397
- args.should == ['ie', 'mouse']
398
- end
399
-
400
- cmd.new.process_line %(benjie mouse)
401
- end
402
-
403
- it "should raise an error if the line doesn't match the command" do
404
- cmd = @set.command 'grunthos', 'the flatulent'
405
-
406
- lambda {
407
- cmd.new.process_line %(grumpos)
408
- }.should.raise(Pry::CommandError)
409
- end
410
- end
411
-
412
- describe "block parameters" do
413
- before do
414
- @context = Object.new
415
- @set.command "walking-spanish", "down the hall", :takes_block => true do
416
- PryTestHelpers.inject_var(:@x, command_block.call, target)
417
- end
418
- @set.import Pry::Commands
419
-
420
- @t = pry_tester(@context, :commands => @set)
421
- end
422
-
423
- it 'should accept multiline blocks' do
424
- @t.eval <<-EOS
425
- walking-spanish | do
426
- :jesus
427
- end
428
- EOS
429
-
430
- @context.instance_variable_get(:@x).should == :jesus
431
- end
432
-
433
- it 'should accept normal parameters along with block' do
434
- @set.block_command "walking-spanish",
435
- "litella's been screeching for a blind pig.",
436
- :takes_block => true do |x, y|
437
- PryTestHelpers.inject_var(:@x, x, target)
438
- PryTestHelpers.inject_var(:@y, y, target)
439
- PryTestHelpers.inject_var(:@block_var, command_block.call, target)
440
- end
441
-
442
- @t.eval 'walking-spanish john carl| { :jesus }'
443
-
444
- @context.instance_variable_get(:@x).should == "john"
445
- @context.instance_variable_get(:@y).should == "carl"
446
- @context.instance_variable_get(:@block_var).should == :jesus
447
- end
448
-
449
- describe "single line blocks" do
450
- it 'should accept blocks with do ; end' do
451
- @t.eval 'walking-spanish | do ; :jesus; end'
452
- @context.instance_variable_get(:@x).should == :jesus
453
- end
454
-
455
- it 'should accept blocks with do; end' do
456
- @t.eval 'walking-spanish | do; :jesus; end'
457
- @context.instance_variable_get(:@x).should == :jesus
458
- end
459
-
460
- it 'should accept blocks with { }' do
461
- @t.eval 'walking-spanish | { :jesus }'
462
- @context.instance_variable_get(:@x).should == :jesus
463
- end
464
- end
465
-
466
- describe "block-related content removed from arguments" do
467
-
468
- describe "arg_string" do
469
- it 'should remove block-related content from arg_string (with one normal arg)' do
470
- @set.block_command "walking-spanish", "down the hall", :takes_block => true do |x, y|
471
- PryTestHelpers.inject_var(:@arg_string, arg_string, target)
472
- PryTestHelpers.inject_var(:@x, x, target)
473
- end
474
-
475
- @t.eval 'walking-spanish john| { :jesus }'
476
-
477
- @context.instance_variable_get(:@arg_string).should == @context.instance_variable_get(:@x)
478
- end
479
-
480
- it 'should remove block-related content from arg_string (with no normal args)' do
481
- @set.block_command "walking-spanish", "down the hall", :takes_block => true do
482
- PryTestHelpers.inject_var(:@arg_string, arg_string, target)
483
- end
484
-
485
- @t.eval 'walking-spanish | { :jesus }'
486
-
487
- @context.instance_variable_get(:@arg_string).should == ""
488
- end
489
-
490
- it 'should NOT remove block-related content from arg_string when :takes_block => false' do
491
- block_string = "| { :jesus }"
492
- @set.block_command "walking-spanish", "homemade special", :takes_block => false do
493
- PryTestHelpers.inject_var(:@arg_string, arg_string, target)
494
- end
495
-
496
- @t.eval "walking-spanish #{block_string}"
497
-
498
- @context.instance_variable_get(:@arg_string).should == block_string
499
- end
500
- end
501
-
502
- describe "args" do
503
- describe "block_command" do
504
- it "should remove block-related content from arguments" do
505
- @set.block_command "walking-spanish", "glass is full of sand", :takes_block => true do |x, y|
506
- PryTestHelpers.inject_var(:@x, x, target)
507
- PryTestHelpers.inject_var(:@y, y, target)
508
- end
509
-
510
- @t.eval 'walking-spanish | { :jesus }'
511
-
512
- @context.instance_variable_get(:@x).should == nil
513
- @context.instance_variable_get(:@y).should == nil
514
- end
515
-
516
- it "should NOT remove block-related content from arguments if :takes_block => false" do
517
- @set.block_command "walking-spanish", "litella screeching for a blind pig", :takes_block => false do |x, y|
518
- PryTestHelpers.inject_var(:@x, x, target)
519
- PryTestHelpers.inject_var(:@y, y, target)
520
- end
521
-
522
- @t.eval 'walking-spanish | { :jesus }'
523
-
524
- @context.instance_variable_get(:@x).should == "|"
525
- @context.instance_variable_get(:@y).should == "{"
526
- end
527
- end
528
-
529
- describe "create_command" do
530
- it "should remove block-related content from arguments" do
531
- @set.create_command "walking-spanish", "punk sanders carved one out of wood", :takes_block => true do
532
- def process(x, y)
533
- PryTestHelpers.inject_var(:@x, x, target)
534
- PryTestHelpers.inject_var(:@y, y, target)
535
- end
536
- end
537
-
538
- @t.eval 'walking-spanish | { :jesus }'
539
-
540
- @context.instance_variable_get(:@x).should == nil
541
- @context.instance_variable_get(:@y).should == nil
542
- end
543
-
544
- it "should NOT remove block-related content from arguments if :takes_block => false" do
545
- @set.create_command "walking-spanish", "down the hall", :takes_block => false do
546
- def process(x, y)
547
- PryTestHelpers.inject_var(:@x, x, target)
548
- PryTestHelpers.inject_var(:@y, y, target)
549
- end
550
- end
551
-
552
- @t.eval 'walking-spanish | { :jesus }'
553
-
554
- @context.instance_variable_get(:@x).should == "|"
555
- @context.instance_variable_get(:@y).should == "{"
556
- end
557
- end
558
- end
559
- end
560
-
561
- describe "blocks can take parameters" do
562
- describe "{} style blocks" do
563
- it 'should accept multiple parameters' do
564
- @set.block_command "walking-spanish", "down the hall", :takes_block => true do
565
- PryTestHelpers.inject_var(:@x, command_block.call(1, 2), target)
566
- end
567
-
568
- @t.eval 'walking-spanish | { |x, y| [x, y] }'
569
-
570
- @context.instance_variable_get(:@x).should == [1, 2]
571
- end
572
- end
573
-
574
- describe "do/end style blocks" do
575
- it 'should accept multiple parameters' do
576
- @set.create_command "walking-spanish", "litella", :takes_block => true do
577
- def process
578
- PryTestHelpers.inject_var(:@x, command_block.call(1, 2), target)
579
- end
580
- end
581
-
582
- @t.eval <<-EOS
583
- walking-spanish | do |x, y|
584
- [x, y]
585
- end
586
- EOS
587
-
588
- @context.instance_variable_get(:@x).should == [1, 2]
589
- end
590
- end
591
- end
592
-
593
- describe "closure behaviour" do
594
- it 'should close over locals in the definition context' do
595
- @t.eval 'var = :hello', 'walking-spanish | { var }'
596
- @context.instance_variable_get(:@x).should == :hello
597
- end
598
- end
599
-
600
- describe "exposing block parameter" do
601
- describe "block_command" do
602
- it "should expose block in command_block method" do
603
- @set.block_command "walking-spanish", "glass full of sand", :takes_block => true do
604
- PryTestHelpers.inject_var(:@x, command_block.call, target)
605
- end
606
-
607
- @t.eval 'walking-spanish | { :jesus }'
608
-
609
- @context.instance_variable_get(:@x).should == :jesus
610
- end
611
- end
612
-
613
- describe "create_command" do
614
- it "should NOT expose &block in create_command's process method" do
615
- @set.create_command "walking-spanish", "down the hall", :takes_block => true do
616
- def process(&block)
617
- block.call
618
- end
619
- end
620
- @out = StringIO.new
621
-
622
- proc {
623
- @t.eval 'walking-spanish | { :jesus }'
624
- }.should.raise(NoMethodError)
625
- end
626
-
627
- it "should expose block in command_block method" do
628
- @set.create_command "walking-spanish", "homemade special", :takes_block => true do
629
- def process
630
- PryTestHelpers.inject_var(:@x, command_block.call, target)
631
- end
632
- end
633
-
634
- @t.eval 'walking-spanish | { :jesus }'
635
-
636
- @context.instance_variable_get(:@x).should == :jesus
637
- end
638
- end
639
- end
640
- end
641
-
642
- describe "a command made with a custom sub-class" do
643
-
644
- before do
645
- class MyTestCommand < Pry::ClassCommand
646
- match /my-*test/
647
- description 'So just how many sound technicians does it take to' \
648
- 'change a lightbulb? 1? 2? 3? 1-2-3? Testing?'
649
- options :shellwords => false, :listing => 'my-test'
650
-
651
- def process
652
- output.puts command_name * 2
653
- end
654
- end
655
-
656
- Pry.commands.add_command MyTestCommand
657
- end
658
-
659
- after do
660
- Pry.commands.delete 'my-test'
661
- end
662
-
663
- it "allows creation of custom subclasses of Pry::Command" do
664
- pry_eval('my---test').should =~ /my-testmy-test/
665
- end
666
-
667
- if !mri18_and_no_real_source_location?
668
- it "shows the source of the process method" do
669
- pry_eval('show-source my-test').should =~ /output.puts command_name/
670
- end
671
- end
672
-
673
- describe "command options hash" do
674
- it "is always present" do
675
- options_hash = {
676
- :requires_gem => [],
677
- :keep_retval => false,
678
- :argument_required => false,
679
- :interpolate => true,
680
- :shellwords => false,
681
- :listing => 'my-test',
682
- :use_prefix => true,
683
- :takes_block => false
684
- }
685
- MyTestCommand.options.should == options_hash
686
- end
687
-
688
- describe ":listing option" do
689
- it "defaults to :match if not set explicitly" do
690
- class HappyNewYear < Pry::ClassCommand
691
- match 'happy-new-year'
692
- description 'Happy New Year 2013'
693
- end
694
- Pry.commands.add_command HappyNewYear
695
-
696
- HappyNewYear.options[:listing].should == 'happy-new-year'
697
-
698
- Pry.commands.delete 'happy-new-year'
699
- end
700
-
701
- it "can be set explicitly" do
702
- class MerryChristmas < Pry::ClassCommand
703
- match 'merry-christmas'
704
- description 'Merry Christmas!'
705
- command_options :listing => 'happy-holidays'
706
- end
707
- Pry.commands.add_command MerryChristmas
708
-
709
- MerryChristmas.options[:listing].should == 'happy-holidays'
710
-
711
- Pry.commands.delete 'merry-christmas'
712
- end
713
-
714
- it "equals to :match option's inspect, if :match is Regexp" do
715
- class CoolWinter < Pry::ClassCommand
716
- match /.*winter/
717
- description 'Is winter cool or cool?'
718
- end
719
- Pry.commands.add_command CoolWinter
720
-
721
- CoolWinter.options[:listing].should == '/.*winter/'
722
-
723
- Pry.commands.delete /.*winter/
724
- end
725
- end
726
- end
727
-
728
- end
729
-
730
- describe "commands can save state" do
731
- before do
732
- @set = Pry::CommandSet.new do
733
- create_command "litella", "desc" do
734
- def process
735
- state.my_state ||= 0
736
- state.my_state += 1
737
- end
738
- end
739
-
740
- create_command "sanders", "desc" do
741
- def process
742
- state.my_state = "wood"
743
- end
744
- end
745
-
746
- create_command /[Hh]ello-world/, "desc" do
747
- def process
748
- state.my_state ||= 0
749
- state.my_state += 2
750
- end
751
- end
752
-
753
- end.import Pry::Commands
754
-
755
- @t = pry_tester(:commands => @set)
756
- end
757
-
758
- it 'should save state for the command on the Pry#command_state hash' do
759
- @t.eval 'litella'
760
- @t.pry.command_state["litella"].my_state.should == 1
761
- end
762
-
763
- it 'should ensure state is maintained between multiple invocations of command' do
764
- @t.eval 'litella'
765
- @t.eval 'litella'
766
- @t.pry.command_state["litella"].my_state.should == 2
767
- end
768
-
769
- it 'should ensure state with same name stored seperately for each command' do
770
- @t.eval 'litella', 'sanders'
771
-
772
- @t.pry.command_state["litella"].my_state.should == 1
773
- @t.pry.command_state["sanders"].my_state.should =="wood"
774
- end
775
-
776
- it 'should ensure state is properly saved for regex commands' do
777
- @t.eval 'hello-world', 'Hello-world'
778
- @t.pry.command_state[/[Hh]ello-world/].my_state.should == 4
779
- end
780
- end
781
-
782
- if defined?(Bond)
783
- describe 'complete' do
784
- it 'should return the arguments that are defined' do
785
- @set.create_command "torrid" do
786
- def options(opt)
787
- opt.on :test
788
- opt.on :lest
789
- opt.on :pests
790
- end
791
- end
792
-
793
- @set.complete('torrid ').should.include('--test ')
794
- end
795
- end
796
- end
797
-
798
- describe 'group' do
799
- before do
800
- @set.import(
801
- Pry::CommandSet.new do
802
- create_command("magic") { group("Not for a public use") }
803
- end
804
- )
805
- end
806
-
807
- it 'should be correct for default commands' do
808
- @set.commands["help"].group.should == "Help"
809
- end
810
-
811
- it 'should not change once it is initialized' do
812
- @set.commands["magic"].group("-==CD COMMAND==-")
813
- @set.commands["magic"].group.should == "Not for a public use"
814
- end
815
-
816
- it 'should not disappear after the call without parameters' do
817
- @set.commands["magic"].group
818
- @set.commands["magic"].group.should == "Not for a public use"
819
- end
820
- end
821
- end