pry 0.9.8pre7-java → 0.9.8pre8-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/pry/plugins.rb CHANGED
@@ -9,7 +9,7 @@ class Pry
9
9
  end
10
10
 
11
11
  def method_missing(*args)
12
- $stderr.puts "Warning: The plugin '#{@name}' was not found! (no gem found)"
12
+ warn "Warning: The plugin '#{@name}' was not found! (no gem found)"
13
13
  end
14
14
  end
15
15
 
@@ -45,8 +45,8 @@ class Pry
45
45
  begin
46
46
  require gem_name if !active?
47
47
  rescue LoadError => e
48
- $stderr.puts "Warning: The plugin '#{gem_name}' was not found! (gem found but could not be loaded)"
49
- $stderr.puts e
48
+ warn "Warning: The plugin '#{gem_name}' was not found! (gem found but could not be loaded)"
49
+ warn e
50
50
  end
51
51
  self.active = true
52
52
  self.enabled = true
data/lib/pry/pry_class.rb CHANGED
@@ -89,7 +89,7 @@ class Pry
89
89
  # note these have to be loaded here rather than in pry_instance as
90
90
  # we only want them loaded once per entire Pry lifetime.
91
91
  load_rc if Pry.config.should_load_rc
92
- load_plugins if Pry.config.plugins.enabled
92
+ load_plugins if Pry.config.should_load_plugins
93
93
  load_requires if Pry.config.should_load_requires
94
94
  load_history if Pry.config.history.should_load
95
95
  load_traps if Pry.config.should_trap_interrupts
@@ -113,7 +113,10 @@ class Pry
113
113
  pry_instance = new(options)
114
114
 
115
115
  # save backtrace
116
- pry_instance.backtrace = caller.tap(&:shift)
116
+ pry_instance.backtrace = caller
117
+
118
+ # if Pry was started via binding.pry, elide that from the backtrace.
119
+ pry_instance.backtrace.shift if pry_instance.backtrace.first =~ /pry.*core_extensions.*pry/
117
120
 
118
121
  # yield the binding_stack to the hook for modification
119
122
  pry_instance.exec_hook(
@@ -238,8 +241,7 @@ class Pry
238
241
  config.gist ||= OpenStruct.new
239
242
  config.gist.inspecter = proc(&:pretty_inspect)
240
243
 
241
- config.plugins ||= OpenStruct.new
242
- config.plugins.enabled = true
244
+ config.should_load_plugins = true
243
245
 
244
246
  config.requires ||= []
245
247
  config.should_load_requires = true
@@ -7,7 +7,6 @@ class Pry
7
7
  attr_accessor :commands
8
8
  attr_accessor :print
9
9
  attr_accessor :exception_handler
10
- attr_accessor :hooks
11
10
  attr_accessor :input_stack
12
11
 
13
12
  attr_accessor :custom_completions
@@ -25,6 +24,22 @@ class Pry
25
24
 
26
25
  attr_accessor :backtrace
27
26
 
27
+ # Special treatment for hooks as we want to alert people of the
28
+ # changed API
29
+ attr_reader :hooks
30
+
31
+ # FIXME:
32
+ # This is a hack to alert people of the new API.
33
+ # @param [Pry::Hooks] v Only accept `Pry::Hooks` now!
34
+ def hooks=(v)
35
+ if v.is_a?(Hash)
36
+ warn "Hash-based hooks are now deprecated! Use a `Pry::Hooks` object instead! http://rubydoc.info/github/pry/pry/master/Pry/Hooks"
37
+ @hooks = Pry::Hooks.from_hash(v)
38
+ else
39
+ @hooks = v
40
+ end
41
+ end
42
+
28
43
  # Create a new `Pry` object.
29
44
  # @param [Hash] options The optional configuration parameters.
30
45
  # @option options [#readline] :input The object to use for input.
data/lib/pry/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Pry
2
- VERSION = "0.9.8pre7"
2
+ VERSION = "0.9.8pre8"
3
3
  end
data/test/helper.rb CHANGED
@@ -8,6 +8,11 @@ puts "Ruby v#{RUBY_VERSION} (#{defined?(RUBY_ENGINE) ? RUBY_ENGINE : "ruby"}), P
8
8
  require 'bacon'
9
9
  require 'open4'
10
10
 
11
+
12
+ # turn warnings off (esp for Pry::Hooks which will generate warnings
13
+ # in tests)
14
+ $VERBOSE = nil
15
+
11
16
  # Ensure we do not execute any rc files
12
17
  Pry::RC_FILES.clear
13
18
 
@@ -21,7 +26,7 @@ class << Pry
21
26
  Pry.color = false
22
27
  Pry.pager = false
23
28
  Pry.config.should_load_rc = false
24
- Pry.config.plugins.enabled = false
29
+ Pry.config.should_load_plugins = false
25
30
  Pry.config.history.should_load = false
26
31
  Pry.config.history.should_save = false
27
32
  Pry.config.auto_indent = false
data/test/test_command.rb CHANGED
@@ -9,7 +9,7 @@ describe "Pry::Command" do
9
9
  describe 'call_safely' do
10
10
 
11
11
  it 'should display a message if gems are missing' do
12
- cmd = @set.command_class "ford-prefect", "From a planet near Beetlegeuse", :requires_gem => %w(ghijkl) do
12
+ cmd = @set.create_command "ford-prefect", "From a planet near Beetlegeuse", :requires_gem => %w(ghijkl) do
13
13
  #
14
14
  end
15
15
 
@@ -17,7 +17,7 @@ describe "Pry::Command" do
17
17
  end
18
18
 
19
19
  it 'should abort early if arguments are required' do
20
- cmd = @set.command_class 'arthur-dent', "Doesn't understand Thursdays", :argument_required => true do
20
+ cmd = @set.create_command 'arthur-dent', "Doesn't understand Thursdays", :argument_required => true do
21
21
  #
22
22
  end
23
23
 
@@ -27,7 +27,7 @@ describe "Pry::Command" do
27
27
  end
28
28
 
29
29
  it 'should return VOID without keep_retval' do
30
- cmd = @set.command_class 'zaphod-beeblebrox', "Likes pan-Galactic Gargle Blasters" do
30
+ cmd = @set.create_command 'zaphod-beeblebrox', "Likes pan-Galactic Gargle Blasters" do
31
31
  def process
32
32
  3
33
33
  end
@@ -37,7 +37,7 @@ describe "Pry::Command" do
37
37
  end
38
38
 
39
39
  it 'should return the return value with keep_retval' do
40
- cmd = @set.command_class 'tricia-mcmillian', "a.k.a Trillian", :keep_retval => true do
40
+ cmd = @set.create_command 'tricia-mcmillian', "a.k.a Trillian", :keep_retval => true do
41
41
  def process
42
42
  5
43
43
  end
@@ -47,7 +47,7 @@ describe "Pry::Command" do
47
47
  end
48
48
 
49
49
  it 'should call hooks in the right order' do
50
- cmd = @set.command_class 'marvin', "Pained by the diodes in his left side" do
50
+ cmd = @set.create_command 'marvin', "Pained by the diodes in his left side" do
51
51
  def process
52
52
  output.puts 3 + args[0].to_i
53
53
  end
@@ -73,13 +73,13 @@ describe "Pry::Command" do
73
73
 
74
74
  # TODO: This strikes me as rather silly...
75
75
  it 'should return the value from the last hook with keep_retval' do
76
- cmd = @set.command_class 'slartibartfast', "Designs Fjords", :keep_retval => true do
76
+ cmd = @set.create_command 'slartibartfast', "Designs Fjords", :keep_retval => true do
77
77
  def process
78
78
  22
79
79
  end
80
80
  end
81
81
 
82
- @set.after_command 'slartibartfast' do
82
+ @set.after_command 'slartibartfast' do
83
83
  10
84
84
  end
85
85
 
@@ -97,7 +97,7 @@ describe "Pry::Command" do
97
97
  end
98
98
 
99
99
  it 'should use slop to generate the help for classy commands' do
100
- @set.command_class 'eddie', "The ship-board computer" do
100
+ @set.create_command 'eddie', "The ship-board computer" do
101
101
  def options(opt)
102
102
  opt.banner "Over-cheerful, and makes a ticking noise."
103
103
  end
@@ -107,7 +107,7 @@ describe "Pry::Command" do
107
107
  end
108
108
 
109
109
  it 'should provide --help for classy commands' do
110
- cmd = @set.command_class 'agrajag', "Killed many times by Arthur" do
110
+ cmd = @set.create_command 'agrajag', "Killed many times by Arthur" do
111
111
  def options(opt)
112
112
  opt.on :r, :retaliate, "Try to get Arthur back"
113
113
  end
@@ -117,7 +117,7 @@ describe "Pry::Command" do
117
117
  end
118
118
 
119
119
  it 'should provide a -h for classy commands' do
120
- cmd = @set.command_class 'zarniwoop', "On an intergalactic cruise, in his office." do
120
+ cmd = @set.create_command 'zarniwoop', "On an intergalactic cruise, in his office." do
121
121
  def options(opt)
122
122
  opt.on :e, :escape, "Help zaphod escape the Total Perspective Vortex"
123
123
  end
@@ -127,7 +127,7 @@ describe "Pry::Command" do
127
127
  end
128
128
 
129
129
  it 'should use the banner provided' do
130
- cmd = @set.command_class 'deep-thought', "The second-best computer ever" do
130
+ cmd = @set.create_command 'deep-thought', "The second-best computer ever" do
131
131
  banner <<-BANNER
132
132
  Who's merest operational parameters, I am not worthy to compute.
133
133
  BANNER
@@ -148,7 +148,7 @@ describe "Pry::Command" do
148
148
  }
149
149
 
150
150
  it 'should capture lots of stuff from the hash passed to new before setup' do
151
- cmd = @set.command_class 'fenchurch', "Floats slightly off the ground" do
151
+ cmd = @set.create_command 'fenchurch', "Floats slightly off the ground" do
152
152
  define_method(:setup) do
153
153
  self.context.should == context
154
154
  target.should == context[:target]
@@ -170,7 +170,7 @@ describe "Pry::Command" do
170
170
  describe 'classy api' do
171
171
 
172
172
  it 'should call setup, then options, then process' do
173
- cmd = @set.command_class 'rooster', "Has a tasty towel" do
173
+ cmd = @set.create_command 'rooster', "Has a tasty towel" do
174
174
  def setup
175
175
  output.puts "setup"
176
176
  end
@@ -188,7 +188,7 @@ describe "Pry::Command" do
188
188
  end
189
189
 
190
190
  it 'should raise a command error if process is not overridden' do
191
- cmd = @set.command_class 'jeltz', "Commander of a Vogon constructor fleet" do
191
+ cmd = @set.create_command 'jeltz', "Commander of a Vogon constructor fleet" do
192
192
  def proccces
193
193
  #
194
194
  end
@@ -200,7 +200,7 @@ describe "Pry::Command" do
200
200
  end
201
201
 
202
202
  it 'should work if neither options, nor setup is overridden' do
203
- cmd = @set.command_class 'wowbagger', "Immortal, insulting.", :keep_retval => true do
203
+ cmd = @set.create_command 'wowbagger', "Immortal, insulting.", :keep_retval => true do
204
204
  def process
205
205
  5
206
206
  end
@@ -210,7 +210,7 @@ describe "Pry::Command" do
210
210
  end
211
211
 
212
212
  it 'should provide opts and args as provided by slop' do
213
- cmd = @set.command_class 'lintilla', "One of 800,000,000 clones" do
213
+ cmd = @set.create_command 'lintilla', "One of 800,000,000 clones" do
214
214
  def options(opt)
215
215
  opt.on :f, :four, "A numeric four", :as => Integer, :optional => true
216
216
  end
@@ -225,7 +225,7 @@ describe "Pry::Command" do
225
225
  end
226
226
 
227
227
  it 'should allow overriding options after definition' do
228
- cmd = @set.command_class /number-(one|two)/, "Lieutenants of the Golgafrinchan Captain", :shellwords => false do
228
+ cmd = @set.create_command /number-(one|two)/, "Lieutenants of the Golgafrinchan Captain", :shellwords => false do
229
229
 
230
230
  command_options :listing => 'number-one'
231
231
  end
@@ -501,7 +501,7 @@ describe Pry::CommandSet do
501
501
  end
502
502
 
503
503
  it 'should return Result.new(true, VOID) if the command is not keep_retval' do
504
- @set.command_class('mrs-cake') do
504
+ @set.create_command('mrs-cake') do
505
505
  def process; 42; end
506
506
  end
507
507
 
@@ -512,7 +512,7 @@ describe Pry::CommandSet do
512
512
  end
513
513
 
514
514
  it 'should return Result.new(true, retval) if the command is keep_retval' do
515
- @set.command_class('magrat', 'the maiden', :keep_retval => true) do
515
+ @set.create_command('magrat', 'the maiden', :keep_retval => true) do
516
516
  def process; 42; end
517
517
  end
518
518
 
@@ -529,7 +529,7 @@ describe Pry::CommandSet do
529
529
  :output => StringIO.new,
530
530
  :target => binding
531
531
  }
532
- @set.command_class('agnes') do
532
+ @set.create_command('agnes') do
533
533
  define_method(:process) do
534
534
  eval_string.should == ctx[:eval_string]
535
535
  output.should == ctx[:output]
@@ -543,7 +543,7 @@ describe Pry::CommandSet do
543
543
 
544
544
  it 'should add command_set to context' do
545
545
  set = @set
546
- @set.command_class(/nann+y ogg+/) do
546
+ @set.create_command(/nann+y ogg+/) do
547
547
  define_method(:process) do
548
548
  command_set.should == set
549
549
  end
@@ -3,29 +3,41 @@ require 'helper'
3
3
  describe "Pry::DefaultCommands::Documentation" do
4
4
  describe "show-doc" do
5
5
  it 'should output a method\'s documentation' do
6
- str_output = StringIO.new
7
- redirect_pry_io(InputTester.new("show-doc sample_method", "exit-all"), str_output) do
6
+ redirect_pry_io(InputTester.new("show-doc sample_method", "exit-all"), str_output=StringIO.new) do
8
7
  pry
9
8
  end
10
9
 
11
10
  str_output.string.should =~ /sample doc/
12
11
  end
13
12
 
14
- it 'should output a method\'s documentation if inside method without needing to use method name' do
15
- $str_output = StringIO.new
13
+ it 'should output a method\'s documentation with line numbers' do
14
+ redirect_pry_io(InputTester.new("show-doc sample_method -l", "exit-all"), str_output=StringIO.new) do
15
+ pry
16
+ end
17
+
18
+ str_output.string.should =~ /\d: sample doc/
19
+ end
20
+
21
+ it 'should output a method\'s documentation with line numbers (base one)' do
22
+ redirect_pry_io(InputTester.new("show-doc sample_method -b", "exit-all"), str_output=StringIO.new) do
23
+ pry
24
+ end
25
+
26
+ str_output.string.should =~ /1: sample doc/
27
+ end
16
28
 
29
+ it 'should output a method\'s documentation if inside method without needing to use method name' do
17
30
  o = Object.new
18
31
 
19
32
  # sample comment
20
33
  def o.sample
21
- redirect_pry_io(InputTester.new("show-doc", "exit-all"), $str_output) do
34
+ redirect_pry_io(InputTester.new("show-doc", "exit-all"), $out=StringIO.new) do
22
35
  binding.pry
23
36
  end
24
37
  end
25
38
  o.sample
26
-
27
- $str_output.string.should =~ /sample comment/
28
- $str_output = nil
39
+ $out.string.should =~ /sample comment/
40
+ $out = nil
29
41
  end
30
42
 
31
43
  it "should be able to find super methods" do
@@ -170,59 +170,93 @@ describe "Pry::DefaultCommands::Input" do
170
170
  str_output.string.should.not =~ /goodbye/
171
171
  end
172
172
 
173
+ it 'should play documentation with the -d switch' do
174
+ o = Object.new
175
+
176
+ # @v = 10
177
+ # @y = 20
178
+ def o.test_method
179
+ :test_method_content
180
+ end
181
+
182
+ redirect_pry_io(InputTester.new('play -d test_method', "exit-all"), str_output = StringIO.new) do
183
+ o.pry
184
+ end
185
+
186
+ o.instance_variable_get(:@v).should == 10
187
+ o.instance_variable_get(:@y).should == 20
188
+ end
189
+
190
+ it 'should play documentation with the -d switch (restricted by --lines)' do
191
+ o = Object.new
192
+
193
+ # @x = 0
194
+ # @v = 10
195
+ # @y = 20
196
+ # @z = 30
197
+ def o.test_method
198
+ :test_method_content
199
+ end
200
+
201
+ redirect_pry_io(InputTester.new('play -d test_method --lines 2..3', "exit-all"), str_output = StringIO.new) do
202
+ o.pry
203
+ end
204
+
205
+ o.instance_variable_get(:@x).should == nil
206
+ o.instance_variable_get(:@z).should == nil
207
+ o.instance_variable_get(:@v).should == 10
208
+ o.instance_variable_get(:@y).should == 20
209
+ end
210
+
211
+
173
212
  it 'should play a method with the -m switch (a single line)' do
174
- $o = Object.new
175
- def $o.test_method
213
+ o = Object.new
214
+ def o.test_method
176
215
  :test_method_content
177
216
  end
178
217
 
179
- redirect_pry_io(InputTester.new('play -m $o.test_method --lines 2', "exit-all"), str_output = StringIO.new) do
180
- pry
218
+ redirect_pry_io(InputTester.new('play -m test_method --lines 2', "exit-all"), str_output = StringIO.new) do
219
+ o.pry
181
220
  end
182
221
 
183
222
  str_output.string.should =~ /:test_method_content/
184
- $o = nil
185
223
  end
186
224
 
187
225
  it 'should APPEND to the input buffer when playing a line with play -m, not replace it' do
188
- $o = Object.new
189
- def $o.test_method
226
+ o = Object.new
227
+ def o.test_method
190
228
  :test_method_content
191
229
  end
192
230
 
193
- redirect_pry_io(InputTester.new('def another_test_method', 'play -m $o.test_method --lines 2', 'show-input', 'exit-all'), str_output = StringIO.new) do
194
- pry
231
+ redirect_pry_io(InputTester.new('def another_test_method', 'play -m test_method --lines 2', 'show-input', 'exit-all'), str_output = StringIO.new) do
232
+ o.pry
195
233
  end
196
234
  str_output.string.should =~ /def another_test_method/
197
235
  str_output.string.should =~ /:test_method_content/
198
- $o = nil
199
236
  end
200
237
 
201
238
 
202
239
  it 'should play a method with the -m switch (multiple line)' do
203
- $o = Object.new
204
- class << $o
205
- attr_accessor :var1, :var2
206
- end
240
+ o = Object.new
207
241
 
208
- def $o.test_method
242
+ def o.test_method
243
+ @var0 = 10
209
244
  @var1 = 20
210
245
  @var2 = 30
246
+ @var3 = 40
211
247
  end
212
248
 
213
- obj = Object.new
214
- b = Pry.binding_for(obj)
215
-
216
- redirect_pry_io(InputTester.new('play -m $o.test_method --lines 2..3', "exit-all"), str_output = StringIO.new) do
217
- b.pry
249
+ redirect_pry_io(InputTester.new('play -m test_method --lines 3..4', "exit-all"), str_output = StringIO.new) do
250
+ o.pry
218
251
  end
219
252
 
220
- obj.instance_variable_get(:@var1).should == 20
221
- obj.instance_variable_get(:@var2).should == 30
253
+ o.instance_variable_get(:@var0).should == nil
254
+ o.instance_variable_get(:@var1).should == 20
255
+ o.instance_variable_get(:@var2).should == 30
256
+ o.instance_variable_get(:@var3).should == nil
222
257
  str_output.string.should =~ /30/
223
258
  str_output.string.should.not =~ /20/
224
259
  end
225
-
226
260
  end
227
261
 
228
262
  describe "hist" do
@@ -242,24 +276,29 @@ describe "Pry::DefaultCommands::Input" do
242
276
  end
243
277
 
244
278
  it 'should replay history correctly (single item)' do
245
- @hist.push ":blah"
246
- @hist.push ":bucket"
247
- @hist.push ":ostrich"
279
+ o = Object.new
280
+ @hist.push "@x = 10"
281
+ @hist.push "@y = 20"
282
+ @hist.push "@z = 30"
248
283
  str_output = StringIO.new
249
284
  redirect_pry_io(InputTester.new("hist --replay -1", "exit-all"), str_output) do
250
- pry
285
+ o.pry
251
286
  end
252
- str_output.string.should =~ /ostrich/
287
+ o.instance_variable_get(:@x).should == nil
288
+ o.instance_variable_get(:@y).should == nil
289
+ o.instance_variable_get(:@z).should == 30
253
290
  end
254
291
 
255
292
  it 'should replay a range of history correctly (range of items)' do
256
- @hist.push ":hello"
257
- @hist.push ":carl"
293
+ o = Object.new
294
+ @hist.push "@x = 10"
295
+ @hist.push "@y = 20"
258
296
  str_output = StringIO.new
259
297
  redirect_pry_io(InputTester.new("hist --replay 0..2", "exit-all"), str_output) do
260
- pry
298
+ o.pry
261
299
  end
262
- str_output.string.should =~ /:hello\n.*:carl/
300
+ o.instance_variable_get(:@x).should == 10
301
+ o.instance_variable_get(:@y).should == 20
263
302
  end
264
303
 
265
304
  it 'should grep for correct lines in history' do