pry 0.9.8pre5-java → 0.9.8pre6-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,7 @@ describe "Pry::DefaultCommands::Shell" do
5
5
 
6
6
  describe "on receiving a file that does not exist" do
7
7
  it 'should display an error message' do
8
- mock_pry("cat supercalifragilicious66").should =~ /Could not find file/
8
+ mock_pry("cat supercalifragilicious66").should =~ /Cannot open/
9
9
  end
10
10
  end
11
11
 
@@ -65,7 +65,7 @@ describe "Pry::DefaultCommands::Shell" do
65
65
  temp_file do |f|
66
66
  f << "bt number 1"
67
67
  f.flush
68
- pry_instance.last_exception = MockPryException.new("#{f.path}:1", "x", "x")
68
+ pry_instance.last_exception = mock_exception("#{f.path}:1", "x", "x")
69
69
  pry_instance.rep(self)
70
70
  end
71
71
 
@@ -78,7 +78,7 @@ describe "Pry::DefaultCommands::Shell" do
78
78
  temp_file do |f|
79
79
  f << "bt number 1"
80
80
  f.flush
81
- pry_instance.last_exception = MockPryException.new("#{f.path}:1", "x", "x")
81
+ pry_instance.last_exception = mock_exception("#{f.path}:1", "x", "x")
82
82
  pry_instance.rep(self)
83
83
  end
84
84
 
@@ -91,31 +91,31 @@ describe "Pry::DefaultCommands::Shell" do
91
91
  temp_file do |f|
92
92
  f << "bt number 2"
93
93
  f.flush
94
- pry_instance.last_exception = MockPryException.new("x", "#{f.path}:1", "x")
94
+ pry_instance.last_exception = mock_exception("x", "#{f.path}:1", "x")
95
95
  pry_instance.rep(self)
96
96
  end
97
97
 
98
98
  str_output.string.should =~ /bt number 2/
99
99
  end
100
100
 
101
- it 'should cat third level of backtrace when --ex 2 used ' do
101
+ it 'should cat third level of backtrace when --ex 2 used' do
102
102
  pry_instance = Pry.new(:input => StringIO.new("cat --ex 2"), :output => str_output = StringIO.new)
103
103
 
104
104
  temp_file do |f|
105
105
  f << "bt number 3"
106
106
  f.flush
107
- pry_instance.last_exception = MockPryException.new("x", "x", "#{f.path}:1")
107
+ pry_instance.last_exception = mock_exception("x", "x", "#{f.path}:1")
108
108
  pry_instance.rep(self)
109
109
  end
110
110
 
111
111
  str_output.string.should =~ /bt number 3/
112
112
  end
113
113
 
114
- it 'should show error when backtrace level out of bounds ' do
114
+ it 'should show error when backtrace level out of bounds' do
115
115
  pry_instance = Pry.new(:input => StringIO.new("cat --ex 3"), :output => str_output = StringIO.new)
116
- pry_instance.last_exception = MockPryException.new("x", "x", "x")
116
+ pry_instance.last_exception = mock_exception("x", "x", "x")
117
117
  pry_instance.rep(self)
118
- str_output.string.should =~ /No Exception or Exception has no associated file/
118
+ str_output.string.should =~ /out of bounds/
119
119
  end
120
120
 
121
121
  it 'each successive cat --ex should show the next level of backtrace, and going past the final level should return to the first' do
@@ -129,7 +129,7 @@ describe "Pry::DefaultCommands::Shell" do
129
129
  pry_instance = Pry.new(:input => StringIO.new("cat --ex\n" * 4),
130
130
  :output => (str_output = StringIO.new))
131
131
 
132
- pry_instance.last_exception = MockPryException.new(*temp_files.map { |f| "#{f.path}:1" })
132
+ pry_instance.last_exception = mock_exception(*temp_files.map { |f| "#{f.path}:1" })
133
133
 
134
134
  3.times do |i|
135
135
  pry_instance.rep(self)
@@ -290,6 +290,21 @@ describe Pry::Hooks do
290
290
  @hooks.add_hook(:test_hook, :my_name3) { 3 }
291
291
  @hooks.exec_hook(:test_hook).should == 3
292
292
  end
293
+
294
+ it 'should add exceptions to the errors array' do
295
+ @hooks.add_hook(:test_hook, :foo1) { raise 'one' }
296
+ @hooks.add_hook(:test_hook, :foo2) { raise 'two' }
297
+ @hooks.add_hook(:test_hook, :foo3) { raise 'three' }
298
+ @hooks.exec_hook(:test_hook)
299
+ @hooks.errors.map(&:message).should == ['one', 'two', 'three']
300
+ end
301
+
302
+ it 'should return the last exception raised as the return value' do
303
+ @hooks.add_hook(:test_hook, :foo1) { raise 'one' }
304
+ @hooks.add_hook(:test_hook, :foo2) { raise 'two' }
305
+ @hooks.add_hook(:test_hook, :foo3) { raise 'three' }
306
+ @hooks.exec_hook(:test_hook).should == @hooks.errors.last
307
+ end
293
308
  end
294
309
 
295
310
  describe "integration tests" do
@@ -385,6 +400,27 @@ describe Pry::Hooks do
385
400
  # cleanup after test
386
401
  Pry.config.exception_whitelist = old_ew
387
402
  end
403
+
404
+ describe "exceptions" do
405
+ before do
406
+ Pry.config.hooks.add_hook(:after_eval, :baddums){ raise "Baddums" }
407
+ Pry.config.hooks.add_hook(:after_eval, :simbads){ raise "Simbads" }
408
+ end
409
+
410
+ after do
411
+ Pry.config.hooks.delete_hook(:after_eval, :baddums)
412
+ Pry.config.hooks.delete_hook(:after_eval, :simbads)
413
+ end
414
+ it "should not raise exceptions" do
415
+ lambda{
416
+ mock_pry("1", "2", "3")
417
+ }.should.not.raise
418
+ end
419
+
420
+ it "should print out a notice for each exception raised" do
421
+ mock_pry("1").should =~ /after_eval hook failed: RuntimeError: Baddums\n.*after_eval hook failed: RuntimeError: Simbads/m
422
+ end
423
+ end
388
424
  end
389
425
 
390
426
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.8pre5
4
+ version: 0.9.8pre6
5
5
  prerelease: 5
6
6
  platform: java
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-01-19 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: coderay
16
- requirement: &70205700513740 !ruby/object:Gem::Requirement
16
+ requirement: &70213409119240 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,24 +21,24 @@ dependencies:
21
21
  version: 1.0.5
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70205700513740
24
+ version_requirements: *70213409119240
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: slop
27
- requirement: &70205700513120 !ruby/object:Gem::Requirement
27
+ requirement: &70213409118240 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
31
31
  - !ruby/object:Gem::Version
32
- version: 2.4.1
32
+ version: 2.4.3
33
33
  - - <
34
34
  - !ruby/object:Gem::Version
35
35
  version: '3'
36
36
  type: :runtime
37
37
  prerelease: false
38
- version_requirements: *70205700513120
38
+ version_requirements: *70213409118240
39
39
  - !ruby/object:Gem::Dependency
40
40
  name: method_source
41
- requirement: &70205700512160 !ruby/object:Gem::Requirement
41
+ requirement: &70213409110100 !ruby/object:Gem::Requirement
42
42
  none: false
43
43
  requirements:
44
44
  - - ~>
@@ -46,10 +46,10 @@ dependencies:
46
46
  version: '0.7'
47
47
  type: :runtime
48
48
  prerelease: false
49
- version_requirements: *70205700512160
49
+ version_requirements: *70213409110100
50
50
  - !ruby/object:Gem::Dependency
51
51
  name: bacon
52
- requirement: &70205700511580 !ruby/object:Gem::Requirement
52
+ requirement: &70213409107260 !ruby/object:Gem::Requirement
53
53
  none: false
54
54
  requirements:
55
55
  - - ~>
@@ -57,10 +57,10 @@ dependencies:
57
57
  version: '1.1'
58
58
  type: :development
59
59
  prerelease: false
60
- version_requirements: *70205700511580
60
+ version_requirements: *70213409107260
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: open4
63
- requirement: &70205700511000 !ruby/object:Gem::Requirement
63
+ requirement: &70213409103000 !ruby/object:Gem::Requirement
64
64
  none: false
65
65
  requirements:
66
66
  - - ~>
@@ -68,10 +68,10 @@ dependencies:
68
68
  version: '1.3'
69
69
  type: :development
70
70
  prerelease: false
71
- version_requirements: *70205700511000
71
+ version_requirements: *70213409103000
72
72
  - !ruby/object:Gem::Dependency
73
73
  name: rake
74
- requirement: &70205700510480 !ruby/object:Gem::Requirement
74
+ requirement: &70213409098300 !ruby/object:Gem::Requirement
75
75
  none: false
76
76
  requirements:
77
77
  - - ~>
@@ -79,10 +79,10 @@ dependencies:
79
79
  version: '0.9'
80
80
  type: :development
81
81
  prerelease: false
82
- version_requirements: *70205700510480
82
+ version_requirements: *70213409098300
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: spoon
85
- requirement: &70205700509980 !ruby/object:Gem::Requirement
85
+ requirement: &70213409096060 !ruby/object:Gem::Requirement
86
86
  none: false
87
87
  requirements:
88
88
  - - ~>
@@ -90,7 +90,7 @@ dependencies:
90
90
  version: '0.0'
91
91
  type: :runtime
92
92
  prerelease: false
93
- version_requirements: *70205700509980
93
+ version_requirements: *70213409096060
94
94
  description: An IRB alternative and runtime developer console
95
95
  email: jrmair@gmail.com
96
96
  executables:
@@ -124,6 +124,7 @@ files:
124
124
  - examples/helper.rb
125
125
  - lib/pry.rb
126
126
  - lib/pry/cli.rb
127
+ - lib/pry/code.rb
127
128
  - lib/pry/command.rb
128
129
  - lib/pry/command_set.rb
129
130
  - lib/pry/commands.rb
@@ -141,7 +142,6 @@ files:
141
142
  - lib/pry/default_commands/ls.rb
142
143
  - lib/pry/default_commands/shell.rb
143
144
  - lib/pry/extended_commands/experimental.rb
144
- - lib/pry/extended_commands/user_command_api.rb
145
145
  - lib/pry/helpers.rb
146
146
  - lib/pry/helpers/base_helpers.rb
147
147
  - lib/pry/helpers/command_helpers.rb
@@ -165,6 +165,7 @@ files:
165
165
  - pry.gemspec
166
166
  - test/helper.rb
167
167
  - test/test_cli.rb
168
+ - test/test_code.rb
168
169
  - test/test_command.rb
169
170
  - test/test_command_helpers.rb
170
171
  - test/test_command_integration.rb
@@ -222,6 +223,7 @@ summary: An IRB alternative and runtime developer console
222
223
  test_files:
223
224
  - test/helper.rb
224
225
  - test/test_cli.rb
226
+ - test/test_code.rb
225
227
  - test/test_command.rb
226
228
  - test/test_command_helpers.rb
227
229
  - test/test_command_integration.rb
@@ -1,122 +0,0 @@
1
- class Pry
2
- module ExtendedCommands
3
-
4
- UserCommandAPI = Pry::CommandSet.new do
5
-
6
- command "define-command", "Define a command in the session, use same syntax as `command` method for command API" do |arg|
7
- if arg.nil?
8
- raise CommandError, "Provide an arg!"
9
- end
10
-
11
- prime_string = "command #{arg_string}\n"
12
- command_string = _pry_.r(target, prime_string)
13
-
14
- eval_string.replace <<-HERE
15
- _pry_.commands.instance_eval do
16
- #{command_string}
17
- end
18
- HERE
19
-
20
- end
21
-
22
- command_class "reload-command", "Reload a Pry command." do
23
- banner <<-BANNER
24
- Usage: reload-command command
25
- Reload a Pry command.
26
- BANNER
27
-
28
- def process
29
- command = _pry_.commands.find_command(args.first)
30
-
31
- if command.nil?
32
- raise Pry::CommandError, 'No command found.'
33
- end
34
-
35
- source_code = command.block.source
36
- file, lineno = command.block.source_location
37
-
38
- set = Pry::CommandSet.new do
39
- eval(source_code, binding, file, lineno)
40
- end
41
-
42
- _pry_.commands.delete(command.name)
43
- _pry_.commands.import(set)
44
- end
45
- end
46
-
47
- command_class "edit-command", "Edit a Pry command." do
48
- banner <<-BANNER
49
- Usage: edit-command [options] command
50
- Edit a Pry command.
51
- BANNER
52
-
53
- def initialize env
54
- @pry = env[:pry_instance]
55
- @command = nil
56
- super(env)
57
- end
58
-
59
- def options(opt)
60
- opt.on :p, :patch, 'Perform a in-memory edit of a command'
61
- end
62
-
63
- def process
64
- @command = @pry.commands.find_command(args.first)
65
-
66
- if @command.nil?
67
- raise Pry::CommandError, 'Command not found.'
68
- end
69
-
70
- case
71
- when opts.present?(:patch)
72
- edit_temporarily
73
- else
74
- edit_permanently
75
- end
76
- end
77
-
78
- def edit_permanently
79
- file, lineno = @command.block.source_location
80
- invoke_editor(file, lineno)
81
-
82
- command_set = silence_warnings do
83
- eval File.read(file), TOPLEVEL_BINDING, file, 1
84
- end
85
-
86
- unless command_set.is_a?(Pry::CommandSet)
87
- raise Pry::CommandError,
88
- "Expected file '#{file}' to return a CommandSet"
89
- end
90
-
91
- @pry.commands.delete(@command.name)
92
- @pry.commands.import(command_set)
93
- set_file_and_dir_locals(file)
94
- end
95
-
96
- def edit_temporarily
97
- source_code = Pry::Method(@command.block).source
98
- modified_code = nil
99
-
100
- temp_file do |f|
101
- f.write(source_code)
102
- f.flush
103
-
104
- invoke_editor(f.path, 1)
105
- modified_code = File.read(f.path)
106
- end
107
-
108
- command_set = CommandSet.new do
109
- silence_warnings do
110
- pry = Pry.new :input => StringIO.new(modified_code)
111
- pry.rep(binding)
112
- end
113
- end
114
-
115
- @pry.commands.delete(@command.name)
116
- @pry.commands.import(command_set)
117
- end
118
- end
119
-
120
- end
121
- end
122
- end