pry 0.9.8.2-i386-mingw32 → 0.9.8.3-i386-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. data/CHANGELOG +8 -0
  2. data/README.markdown +20 -13
  3. data/Rakefile +1 -1
  4. data/lib/pry.rb +1 -2
  5. data/lib/pry/command.rb +88 -2
  6. data/lib/pry/command_set.rb +15 -85
  7. data/lib/pry/commands.rb +12 -8
  8. data/lib/pry/default_commands/cd.rb +58 -0
  9. data/lib/pry/default_commands/commands.rb +62 -0
  10. data/lib/pry/default_commands/context.rb +48 -165
  11. data/lib/pry/default_commands/editing.rb +385 -0
  12. data/lib/pry/default_commands/help.rb +127 -0
  13. data/lib/pry/default_commands/hist.rb +116 -0
  14. data/lib/pry/default_commands/{shell.rb → input_and_output.rb} +137 -15
  15. data/lib/pry/default_commands/introspection.rb +79 -232
  16. data/lib/pry/default_commands/ls.rb +4 -2
  17. data/lib/pry/default_commands/{basic.rb → misc.rb} +1 -14
  18. data/lib/pry/default_commands/navigating_pry.rb +114 -0
  19. data/lib/pry/helpers/base_helpers.rb +15 -3
  20. data/lib/pry/helpers/command_helpers.rb +16 -0
  21. data/lib/pry/history.rb +12 -4
  22. data/lib/pry/method.rb +2 -2
  23. data/lib/pry/pry_class.rb +7 -1
  24. data/lib/pry/pry_instance.rb +6 -0
  25. data/lib/pry/rbx_path.rb +6 -18
  26. data/lib/pry/version.rb +1 -1
  27. data/pry.gemspec +8 -8
  28. data/test/helper.rb +8 -0
  29. data/test/test_command.rb +256 -2
  30. data/test/test_command_integration.rb +2 -13
  31. data/test/test_command_set.rb +13 -23
  32. data/test/test_default_commands/test_help.rb +57 -0
  33. data/test/test_default_commands/test_introspection.rb +23 -0
  34. data/test/test_pry.rb +11 -0
  35. metadata +13 -9
  36. data/lib/pry/default_commands/documentation.rb +0 -209
  37. data/lib/pry/default_commands/input.rb +0 -247
  38. data/test/test_default_commands.rb +0 -58
@@ -287,18 +287,6 @@ describe "commands" do
287
287
  str_output.string.should =~ /goodbye world/
288
288
  end
289
289
 
290
- it 'should inherit "help" command from Pry::CommandBase' do
291
- klass = Pry::CommandSet.new do
292
- command "h", "h command" do
293
- end
294
- end
295
-
296
- klass.commands.keys.size.should == 3
297
- klass.commands.keys.include?("help").should == true
298
- klass.commands.keys.include?("install-command").should == true
299
- klass.commands.keys.include?("h").should == true
300
- end
301
-
302
290
  it 'should inherit commands from Pry::Commands' do
303
291
  klass = Pry::CommandSet.new Pry::Commands do
304
292
  command "v" do
@@ -313,13 +301,14 @@ describe "commands" do
313
301
 
314
302
  it 'should alias a command with another command' do
315
303
  klass = Pry::CommandSet.new do
304
+ import Pry::DefaultCommands::Help
316
305
  alias_command "help2", "help"
317
306
  end
318
307
  klass.commands["help2"].block.should == klass.commands["help"].block
319
308
  end
320
309
 
321
310
  it 'should change description of a command using desc' do
322
- klass = Pry::CommandSet.new do; end
311
+ klass = Pry::CommandSet.new do; import Pry::DefaultCommands::Help; end
323
312
  orig = klass.commands["help"].description
324
313
  klass.instance_eval do
325
314
  desc "help", "blah"
@@ -2,7 +2,7 @@ require 'helper'
2
2
 
3
3
  describe Pry::CommandSet do
4
4
  before do
5
- @set = Pry::CommandSet.new
5
+ @set = Pry::CommandSet.new{ import Pry::DefaultCommands::Help }
6
6
  @ctx = {
7
7
  :target => binding,
8
8
  :command_set => @set
@@ -252,27 +252,6 @@ describe Pry::CommandSet do
252
252
  }.should.not.raise
253
253
  end
254
254
 
255
- it "should sort the output of the 'help' command" do
256
- @set.command 'foo', "Fooerizes" do; end
257
- @set.command 'goo', "Gooerizes" do; end
258
- @set.command 'moo', "Mooerizes" do; end
259
- @set.command 'boo', "Booerizes" do; end
260
-
261
- @ctx[:command_set] = @set
262
- @ctx[:output] = StringIO.new
263
-
264
- @set.run_command(@ctx, 'help')
265
-
266
- doc = @ctx[:output].string
267
-
268
- order = [doc.index("boo"),
269
- doc.index("foo"),
270
- doc.index("goo"),
271
- doc.index("help"),
272
- doc.index("moo")]
273
-
274
- order.should == order.sort
275
- end
276
255
 
277
256
  describe "renaming a command" do
278
257
  it 'should be able to rename and run a command' do
@@ -301,7 +280,6 @@ describe Pry::CommandSet do
301
280
  lambda { @set.run_command(@ctx, 'foo') }.should.raise Pry::NoCommandError
302
281
  end
303
282
 
304
-
305
283
  it 'should be able to pass in options when renaming command' do
306
284
  desc = "hello"
307
285
  listing = "bing"
@@ -471,6 +449,18 @@ describe Pry::CommandSet do
471
449
  @set.find_command('colon').should == cmd
472
450
  Pry.config.command_prefix = ''
473
451
  end
452
+
453
+ it "should find the command that has the longest match" do
454
+ cmd = @set.command(/\.(.*)/){ }
455
+ cmd2 = @set.command(/\.\|\|(.*)/){ }
456
+ @set.find_command('.||').should == cmd2
457
+ end
458
+
459
+ it "should find the command that has the longest name" do
460
+ cmd = @set.command(/\.(.*)/){ }
461
+ cmd2 = @set.command('.||'){ }
462
+ @set.find_command('.||').should == cmd2
463
+ end
474
464
  end
475
465
 
476
466
  describe '.valid_command?' do
@@ -0,0 +1,57 @@
1
+ require 'helper'
2
+
3
+ describe "'help' command" do
4
+ before do
5
+ @oldset = Pry.config.commands
6
+ @set = Pry.config.commands = Pry::CommandSet.new do
7
+ import Pry::DefaultCommands::Help
8
+ import Pry::DefaultCommands::Ls
9
+ end
10
+ end
11
+
12
+ after do
13
+ Pry.config.commands = @oldset
14
+ end
15
+
16
+ it 'should display help for a specific command' do
17
+ mock_pry('help ls').should =~ /Usage: ls/
18
+ end
19
+
20
+ it 'should display help for a regex command with a "listing"' do
21
+ @set.command /bar(.*)/, "Test listing", :listing => "foo" do; end
22
+ mock_pry('help foo').should =~ /Test listing/
23
+ end
24
+
25
+ it 'should display help for a command with a spaces in its name' do
26
+ @set.command "command with spaces", "description of a command with spaces" do; end
27
+ mock_pry('help "command with spaces"').should =~ /description of a command with spaces/
28
+ end
29
+
30
+ it 'should display help for all commands with a description' do
31
+ @set.command /bar(.*)/, "Test listing", :listing => "foo" do; end
32
+ @set.command "b", "description for b", :listing => "foo" do; end
33
+ @set.command "c" do;end
34
+ @set.command "d", "" do;end
35
+
36
+ output = mock_pry('help')
37
+ output.should =~ /Test listing/
38
+ output.should =~ /description for b/
39
+ output.should =~ /No description/
40
+ end
41
+
42
+ it "should sort the output of the 'help' command" do
43
+ @set.command 'faa', "Fooerizes" do; end
44
+ @set.command 'gaa', "Gooerizes" do; end
45
+ @set.command 'maa', "Mooerizes" do; end
46
+ @set.command 'baa', "Booerizes" do; end
47
+
48
+ doc = mock_pry('help')
49
+
50
+ order = [doc.index("baa"),
51
+ doc.index("faa"),
52
+ doc.index("gaa"),
53
+ doc.index("maa")]
54
+
55
+ order.should == order.sort
56
+ end
57
+ end
@@ -320,6 +320,29 @@ describe "Pry::DefaultCommands::Introspection" do
320
320
  str_output.string.should =~ /Mr flibble/
321
321
  end
322
322
 
323
+ it "should find methods even if the object has an overridden method method" do
324
+ c = Class.new{
325
+ def method;
326
+ 98
327
+ end
328
+ }
329
+
330
+ mock_pry(binding, "show-method c.new.method").should =~ /98/
331
+ end
332
+
333
+ it "should find instance_methods even if the class has an override instance_method method" do
334
+ c = Class.new{
335
+ def method;
336
+ 98
337
+ end
338
+
339
+ def self.instance_method; 789; end
340
+ }
341
+
342
+ mock_pry(binding, "show-method c#method").should =~ /98/
343
+
344
+ end
345
+
323
346
  it "should find instance methods with -M" do
324
347
  c = Class.new{ def moo; "ve over!"; end }
325
348
  mock_pry(binding, "cd c","show-method -M moo").should =~ /ve over/
data/test/test_pry.rb CHANGED
@@ -296,6 +296,17 @@ describe Pry do
296
296
  Object.remove_const(:TEST_RC)
297
297
  end
298
298
 
299
+ it "should not load the pryrc if it cannot expand ENV[HOME]" do
300
+ old_home = ENV['HOME']
301
+ old_rc = Pry.config.should_load_rc
302
+ ENV['HOME'] = nil
303
+ Pry.config.should_load_rc = true
304
+ lambda { Pry.start(self, :input => StringIO.new("exit-all\n"), :output => Pry::NullOutput) }.should.not.raise
305
+
306
+ ENV['HOME'] = old_home
307
+ Pry.config.should_load_rc = old_rc
308
+ end
309
+
299
310
  it "should not run the rc file at all if Pry.config.should_load_rc is false" do
300
311
  Pry.config.should_load_rc = false
301
312
  Pry.start(self, :input => StringIO.new("exit-all\n"), :output => Pry::NullOutput)
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: pry
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.9.8.2
5
+ version: 0.9.8.3
6
6
  platform: i386-mingw32
7
7
  authors:
8
8
  - John Mair (banisterfiend)
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-02-09 00:00:00 Z
13
+ date: 2012-03-02 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: coderay
@@ -45,7 +45,7 @@ dependencies:
45
45
  requirements:
46
46
  - - ~>
47
47
  - !ruby/object:Gem::Version
48
- version: "0.7"
48
+ version: 0.7.1
49
49
  type: :runtime
50
50
  version_requirements: *id003
51
51
  - !ruby/object:Gem::Dependency
@@ -135,15 +135,19 @@ files:
135
135
  - lib/pry/config.rb
136
136
  - lib/pry/core_extensions.rb
137
137
  - lib/pry/custom_completions.rb
138
- - lib/pry/default_commands/basic.rb
138
+ - lib/pry/default_commands/cd.rb
139
+ - lib/pry/default_commands/commands.rb
139
140
  - lib/pry/default_commands/context.rb
140
- - lib/pry/default_commands/documentation.rb
141
141
  - lib/pry/default_commands/easter_eggs.rb
142
+ - lib/pry/default_commands/editing.rb
142
143
  - lib/pry/default_commands/gems.rb
143
- - lib/pry/default_commands/input.rb
144
+ - lib/pry/default_commands/help.rb
145
+ - lib/pry/default_commands/hist.rb
146
+ - lib/pry/default_commands/input_and_output.rb
144
147
  - lib/pry/default_commands/introspection.rb
145
148
  - lib/pry/default_commands/ls.rb
146
- - lib/pry/default_commands/shell.rb
149
+ - lib/pry/default_commands/misc.rb
150
+ - lib/pry/default_commands/navigating_pry.rb
147
151
  - lib/pry/extended_commands/experimental.rb
148
152
  - lib/pry/helpers.rb
149
153
  - lib/pry/helpers/base_helpers.rb
@@ -174,10 +178,10 @@ files:
174
178
  - test/test_command_integration.rb
175
179
  - test/test_command_set.rb
176
180
  - test/test_completion.rb
177
- - test/test_default_commands.rb
178
181
  - test/test_default_commands/test_context.rb
179
182
  - test/test_default_commands/test_documentation.rb
180
183
  - test/test_default_commands/test_gems.rb
184
+ - test/test_default_commands/test_help.rb
181
185
  - test/test_default_commands/test_input.rb
182
186
  - test/test_default_commands/test_introspection.rb
183
187
  - test/test_default_commands/test_ls.rb
@@ -235,10 +239,10 @@ test_files:
235
239
  - test/test_command_integration.rb
236
240
  - test/test_command_set.rb
237
241
  - test/test_completion.rb
238
- - test/test_default_commands.rb
239
242
  - test/test_default_commands/test_context.rb
240
243
  - test/test_default_commands/test_documentation.rb
241
244
  - test/test_default_commands/test_gems.rb
245
+ - test/test_default_commands/test_help.rb
242
246
  - test/test_default_commands/test_input.rb
243
247
  - test/test_default_commands/test_introspection.rb
244
248
  - test/test_default_commands/test_ls.rb
@@ -1,209 +0,0 @@
1
- class Pry
2
- module DefaultCommands
3
-
4
- Documentation = Pry::CommandSet.new do
5
-
6
- create_command "ri", "View ri documentation. e.g `ri Array#each`" do
7
- banner <<-BANNER
8
- Usage: ri [spec]
9
- e.g. ri Array#each
10
-
11
- Relies on the ri executable being available. See also: show-doc.
12
- BANNER
13
-
14
- def process
15
- run ".ri", *args
16
- end
17
- end
18
-
19
- create_command "show-doc", "Show the comments above METH. Type `show-doc --help` for more info. Aliases: \?", :shellwords => false do |*args|
20
- banner <<-BANNER
21
- Usage: show-doc [OPTIONS] [METH]
22
- Show the comments above method METH. Tries instance methods first and then methods by default.
23
- e.g show-doc hello_method
24
- BANNER
25
-
26
- def options(opt)
27
- method_options(opt)
28
- opt.on :l, "line-numbers", "Show line numbers."
29
- opt.on :b, "base-one", "Show line numbers but start numbering at 1 (useful for `amend-line` and `play` commands)."
30
- opt.on :f, :flood, "Do not use a pager to view text longer than one screen."
31
- end
32
-
33
- def process
34
- meth = method_object
35
- raise Pry::CommandError, "No documentation found." if meth.doc.nil? || meth.doc.empty?
36
-
37
- doc = process_comment_markup(meth.doc, meth.source_type)
38
- output.puts make_header(meth, doc)
39
- output.puts "#{text.bold("Owner:")} #{meth.owner || "N/A"}"
40
- output.puts "#{text.bold("Visibility:")} #{meth.visibility}"
41
- output.puts "#{text.bold("Signature:")} #{meth.signature}"
42
- output.puts
43
-
44
- if opts.present?(:b) || opts.present?(:l)
45
- doc = Code.new(doc, start_line, :text).
46
- with_line_numbers(true)
47
- end
48
-
49
- render_output(doc, opts)
50
- end
51
-
52
- def start_line
53
- if opts.present?(:'base-one')
54
- 1
55
- else
56
- (method_object.source_line - method_object.doc.lines.count) || 1
57
- end
58
- end
59
-
60
- end
61
-
62
- alias_command "?", "show-doc"
63
-
64
- create_command "stat", "View method information and set _file_ and _dir_ locals. Type `stat --help` for more info.", :shellwords => false do |*args|
65
- banner <<-BANNER
66
- Usage: stat [OPTIONS] [METH]
67
- Show method information for method METH and set _file_ and _dir_ locals.
68
- e.g: stat hello_method
69
- BANNER
70
-
71
- def options(opt)
72
- method_options(opt)
73
- end
74
-
75
- def process
76
- meth = method_object
77
- output.puts unindent <<-EOS
78
- Method Information:
79
- --
80
- Name: #{meth.name}
81
- Owner: #{meth.owner ? meth.owner : "Unknown"}
82
- Visibility: #{meth.visibility}
83
- Type: #{meth.is_a?(::Method) ? "Bound" : "Unbound"}
84
- Arity: #{meth.arity}
85
- Method Signature: #{meth.signature}
86
- Source Location: #{meth.source_location ? meth.source_location.join(":") : "Not found."}
87
- EOS
88
- end
89
- end
90
-
91
- create_command "gist", "Gist a method or expression history to github. Type `gist --help` for more info.", :requires_gem => "gist", :shellwords => false do
92
- banner <<-USAGE
93
- Usage: gist [OPTIONS] [METH]
94
- Gist method (doc or source) or input expression to github.
95
- Ensure the `gist` gem is properly working before use. http://github.com/defunkt/gist for instructions.
96
- e.g: gist -m my_method
97
- e.g: gist -d my_method
98
- e.g: gist -i 1..10
99
- e.g: gist -c show-method
100
- e.g: gist -m hello_world --lines 2..-2
101
- USAGE
102
-
103
- attr_accessor :content
104
- attr_accessor :code_type
105
-
106
- def setup
107
- require 'gist'
108
- self.content = ""
109
- self.code_type = :ruby
110
- end
111
-
112
- def options(opt)
113
- opt.on :m, :method, "Gist a method's source.", true do |meth_name|
114
- meth = get_method_or_raise(meth_name, target, {})
115
- self.content << meth.source
116
- self.code_type = meth.source_type
117
- end
118
- opt.on :d, :doc, "Gist a method's documentation.", true do |meth_name|
119
- meth = get_method_or_raise(meth_name, target, {})
120
- text.no_color do
121
- self.content << process_comment_markup(meth.doc, self.code_type)
122
- end
123
- self.code_type = :plain
124
- end
125
- opt.on :c, :command, "Gist a command's source.", true do |command_name|
126
- command = find_command(command_name)
127
- block = Pry::Method.new(find_command(command_name).block)
128
- self.content << block.source
129
- end
130
- opt.on :f, :file, "Gist a file.", true do |file|
131
- self.content << File.read(File.expand_path(file))
132
- end
133
- opt.on :p, :public, "Create a public gist (default: false)", :default => false
134
- opt.on :l, :lines, "Only gist a subset of lines.", :optional => true, :as => Range, :default => 1..-1
135
- opt.on :i, :in, "Gist entries from Pry's input expression history. Takes an index or range.", :optional => true,
136
- :as => Range, :default => -5..-1 do |range|
137
- range = convert_to_range(range)
138
- input_expressions = _pry_.input_array[range] || []
139
- Array(input_expressions).each_with_index do |code, index|
140
- corrected_index = index + range.first
141
- if code && code != ""
142
- self.content << code
143
- if code !~ /;\Z/
144
- self.content << "#{comment_expression_result_for_gist(Pry.config.gist.inspecter.call(_pry_.output_array[corrected_index]))}"
145
- end
146
- end
147
- end
148
- end
149
- end
150
-
151
- def process
152
- perform_gist
153
- end
154
-
155
- def perform_gist
156
- type_map = { :ruby => "rb", :c => "c", :plain => "plain" }
157
-
158
- if self.content =~ /\A\s*\z/
159
- raise CommandError, "Found no code to gist."
160
- end
161
-
162
- # prevent Gist from exiting the session on error
163
- begin
164
- extname = opts.present?(:file) ? ".#{gist_file_extension(opts[:f])}" : ".#{type_map[self.code_type]}"
165
-
166
- if opts.present?(:lines)
167
- self.content = restrict_to_lines(content, opts[:l])
168
- end
169
-
170
- link = Gist.write([:extension => extname,
171
- :input => self.content],
172
- !opts[:p])
173
- rescue SystemExit
174
- end
175
-
176
- if link
177
- Gist.copy(link)
178
- output.puts "Gist created at #{link} and added to clipboard."
179
- end
180
- end
181
-
182
- def gist_file_extension(file_name)
183
- file_name.split(".").last
184
- end
185
-
186
- def convert_to_range(n)
187
- if !n.is_a?(Range)
188
- (n..n)
189
- else
190
- n
191
- end
192
- end
193
-
194
- def comment_expression_result_for_gist(result)
195
- content = ""
196
- result.lines.each_with_index do |line, index|
197
- if index == 0
198
- content << "# => #{line}"
199
- else
200
- content << "# #{line}"
201
- end
202
- end
203
- content
204
- end
205
- end
206
- end
207
- end
208
- end
209
-