pry-rescue 1.4.5 → 1.5.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f8498adfc62776fab874402fd91ff59f7a0b3811
4
- data.tar.gz: 2efe1214b7acb9361f5c84754bad36aebfc769bd
3
+ metadata.gz: 936ad34711f6f4e6084c959c7e6e1431873cc549
4
+ data.tar.gz: 44befec5ee09418f9c459c8b548a5840da6c8cc0
5
5
  SHA512:
6
- metadata.gz: a60814bf969deba350559387f5a11c79fa6b03e86bb90656cee06f1ec26dd52e3db99ea815dbe033cb10fd65dcce59a932959c838a2b1b70a40d238057f2be54
7
- data.tar.gz: 94c9e761195dcd0c7eb01c17af7670b0eea83fa9d59e36d4b24a1612f4b49807f6f12f0463072c4f5a7838d5ff256f54fb2d4629fb896d8edc9cfc37ea8e1121
6
+ metadata.gz: 8c3e94547db32735d4f60200ad2bfa8de32427812dfa88a8db56487b7d28a7d0f5d4c5e1204f9a9016edc55957833994e6065ee3866a9c974acb8663f82dbd43
7
+ data.tar.gz: a8cb171f27a823a38260675a2721db15137fbb136be816ee0825cb3673f2b8fb4eb044452957b150d35164462e6842b87d672b8f97e816bc2183d52adfde99a1
@@ -1,10 +1,10 @@
1
1
  language: ruby
2
2
  cache: bundler
3
3
  rvm:
4
- - 1.9.3
5
- - 2.0.0
6
- - 2.1.0
7
- - 2.2.2
4
+ - 2.2
5
+ - 2.3
6
+ - 2.4
7
+ - 2.5
8
8
  - ruby-head
9
9
  before_install:
10
10
  - "gem update --system"
data/bin/rescue CHANGED
@@ -39,7 +39,11 @@ else
39
39
  when 'rails'
40
40
  ENV['PRY_RESCUE_RAILS'] = 'true'
41
41
  exec(*ARGV)
42
- when /^re?spec|rake$/
42
+ when 'rake'
43
+ require File.expand_path('../../lib/pry-rescue.rb', __FILE__)
44
+ PryRescue.load_rake ARGV[1]
45
+ exit
46
+ when /^re?spec$/
43
47
  ENV['SPEC_OPTS'] = "#{ENV['SPEC_OPTS']} -r pry-rescue/rspec"
44
48
  exec(*ARGV)
45
49
  end
@@ -12,7 +12,7 @@ if ENV['PRY_RESCUE_RAILS']
12
12
  end
13
13
  case ENV['PRY_PEEK']
14
14
  when nil
15
- PryRescue.peek_on_signal('QUIT') unless Pry::Helpers::BaseHelpers.windows?
15
+ PryRescue.peek_on_signal('QUIT') unless Pry::Helpers::Platform.windows?
16
16
  when ''
17
17
  # explicitly disable QUIT.
18
18
  else
@@ -79,6 +79,14 @@ class PryRescue
79
79
  end
80
80
  end
81
81
 
82
+ def load_rake(task)
83
+ require 'rake'
84
+ Pry::rescue do
85
+ load "#{Dir.pwd}/Rakefile"
86
+ Rake::Task[task].invoke
87
+ end
88
+ end
89
+
82
90
  # Is the user currently inside pry rescue?
83
91
  # @return [Boolean]
84
92
  def in_exception_context?
@@ -47,6 +47,8 @@ Pry::Commands.create_command "cd-cause", "Move to the exception that caused this
47
47
  ex = ex.instance_variable_get(:@rescue_cause) if rescued == ex
48
48
  raise Pry::CommandError, "No previous exception to cd-cause into" if ex.nil? || ex == rescued
49
49
 
50
+ ex = ex.cause if ex.respond_to?(:cause) && !ex.cause.nil?
51
+
50
52
  Pry.rescued ex
51
53
  end
52
54
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'pry-rescue'
3
- s.version = '1.4.5'
3
+ s.version = '1.5.0'
4
4
  s.summary = 'Open a pry session on any unhandled exceptions'
5
5
  s.description = 'Allows you to wrap code in Pry::rescue{ } to open a pry session at any unhandled exceptions'
6
6
  s.homepage = 'https://github.com/ConradIrwin/pry-rescue'
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
11
11
  s.require_paths = ['lib']
12
12
  s.executables = s.files.grep(%r{^bin/}).map{|f| File.basename f}
13
13
 
14
- s.add_dependency 'pry'
14
+ s.add_dependency 'pry', '>= 0.12.0'
15
15
  s.add_dependency 'interception', '>= 0.5'
16
16
 
17
17
  s.add_development_dependency 'pry-stack_explorer' # upgrade to regular dep?
@@ -1,4 +1,5 @@
1
1
  require './spec/spec_helper'
2
+ require './spec/fixtures/template_error'
2
3
 
3
4
  describe "pry-rescue commands" do
4
5
  describe "try-again" do
@@ -56,6 +57,30 @@ describe "pry-rescue commands" do
56
57
  end
57
58
 
58
59
  describe "cd-cause" do
60
+ context 're-raising with custom Exception' do
61
+ it "should not loop through same context" do
62
+ _ex_ = nil
63
+ e1 = nil
64
+ Pry::rescue do
65
+ begin
66
+ begin
67
+ _b1 = binding
68
+ raise "original"
69
+ rescue => e1
70
+ _b2 = binding
71
+ raise TemplateError.new(e1)
72
+ end
73
+ rescue => e2
74
+ _ex_ = e2
75
+ end
76
+ end
77
+
78
+ expect(PryRescue).to receive(:enter_exception_context).once.with(e1)
79
+
80
+ Pry.new.tap{ |p| p.push_binding(binding) }.process_command 'cd-cause'
81
+ end
82
+ end
83
+
59
84
  it "should enter the next exception's context" do
60
85
  _ex_ = nil
61
86
  e1 = nil
@@ -2,25 +2,25 @@ require File.expand_path('../../lib/pry-rescue.rb', __FILE__)
2
2
 
3
3
  describe 'Pry.rescue' do
4
4
  it 'should call PryRescue.enter_exception_context' do
5
- lambda{
6
- PryRescue.should_receive(:enter_exception_context).once
5
+ expect(lambda {
6
+ expect(PryRescue).to receive(:enter_exception_context).once
7
7
  Pry::rescue{ raise "foobar" }
8
- }.should raise_error(/foobar/)
8
+ }).to raise_error(/foobar/)
9
9
  end
10
10
 
11
11
  it "should retry on try-again" do
12
12
  @called = 0
13
- PryRescue.should_receive(:enter_exception_context).once{ throw :try_again }
13
+ expect(PryRescue).to receive(:enter_exception_context).once{ throw :try_again }
14
14
  Pry::rescue do
15
15
  @called += 1
16
16
  raise "foobar" if @called == 1
17
17
  end
18
- @called.should == 2
18
+ expect(@called).to be(2)
19
19
  end
20
20
 
21
21
  it "should try-again from innermost block" do
22
22
  @outer = @inner = 0
23
- PryRescue.should_receive(:enter_exception_context).once{ throw :try_again }
23
+ expect(PryRescue).to receive(:enter_exception_context).once{ throw :try_again }
24
24
  Pry::rescue do
25
25
  @outer += 1
26
26
  Pry::rescue do
@@ -29,13 +29,13 @@ describe 'Pry.rescue' do
29
29
  end
30
30
  end
31
31
 
32
- @outer.should == 1
33
- @inner.should == 2
32
+ expect(@outer).to be(1)
33
+ expect(@inner).to be(2)
34
34
  end
35
35
 
36
36
  it "should enter the first occurence of an exception that is re-raised" do
37
- PryRescue.should_receive(:enter_exception_context).once{ |raised| raised.size.should == 1 }
38
- lambda do
37
+ expect(PryRescue).to receive(:enter_exception_context).once{ |raised| raised.size.should == 1 }
38
+ expect(lambda do
39
39
  Pry::rescue do
40
40
  begin
41
41
  raise "first_occurance"
@@ -43,26 +43,26 @@ describe 'Pry.rescue' do
43
43
  raise
44
44
  end
45
45
  end
46
- end.should raise_error(/first_occurance/)
46
+ end).to raise_error(/first_occurance/)
47
47
  end
48
48
 
49
49
  it "should not catch SystemExit" do
50
- PryRescue.should_not_receive(:enter_exception_context)
50
+ expect(PryRescue).to_not receive(:enter_exception_context)
51
51
 
52
- lambda do
52
+ expect(lambda do
53
53
  Pry::rescue do
54
54
  exit
55
55
  end
56
- end.should raise_error SystemExit
56
+ end).to raise_error SystemExit
57
57
  end
58
58
 
59
59
  it 'should not catch Ctrl+C' do
60
- PryRescue.should_not_receive(:enter_exception_context)
61
- lambda do
60
+ expect(PryRescue).to_not receive(:enter_exception_context)
61
+ expect(lambda do
62
62
  Pry::rescue do
63
63
  raise Interrupt, "ctrl+c (fake)"
64
64
  end
65
- end.should raise_error Interrupt
65
+ end).to raise_error Interrupt
66
66
  end
67
67
  end
68
68
 
@@ -72,15 +72,15 @@ describe "Pry.rescued" do
72
72
  begin
73
73
  raise "foo"
74
74
  rescue => e
75
- Pry.should_receive(:warn)
75
+ expect(Pry).to receive(:warn)
76
76
  Pry.rescued(e)
77
77
  end
78
78
  end
79
79
 
80
80
  it "should raise an error if used on an exception not raised" do
81
81
  Pry::rescue do
82
- Pry.should_receive(:warn) do |message|
83
- message.should =~ /^WARNING: Tried to inspect exception outside of Pry::rescue/
82
+ expect(Pry).to receive(:warn) do |message|
83
+ expect(message).to match(/^WARNING: Tried to inspect exception outside of Pry::rescue/)
84
84
  end
85
85
  Pry.rescued(RuntimeError.new("foo").exception)
86
86
  end
@@ -91,7 +91,7 @@ describe "Pry.rescued" do
91
91
  begin
92
92
  raise "foo"
93
93
  rescue => e
94
- PryRescue.should_receive(:enter_exception_context).once
94
+ expect(PryRescue).to receive(:enter_exception_context).once
95
95
  Pry::rescued(e)
96
96
  end
97
97
  end
@@ -0,0 +1,13 @@
1
+ # This Exception Class behaves same as ActionView::Template::Error
2
+ # https://github.com/rails/rails/blob/master/actionview/lib/action_view/template/error.rb#L68
3
+ #
4
+ # It encapsulates an Exception and stores the latest Exception raised in its
5
+ # `cause` attribute
6
+ class TemplateError < StandardError
7
+ attr_reader :cause
8
+
9
+ def initialize(cause)
10
+ @cause = $!
11
+ end
12
+ end
13
+
@@ -6,9 +6,9 @@ describe "PryRescue.peek!" do
6
6
  Pry.config.output = StringIO.new
7
7
  foo = 5
8
8
 
9
- lambda do
9
+ expect(lambda do
10
10
  PryRescue.peek!
11
- end.should change{ foo }.from(5).to(6)
11
+ end).to change{ foo }.from(5).to(6)
12
12
  end
13
13
 
14
14
  # this will fail, or not?
@@ -22,8 +22,8 @@ describe "PryRescue.peek!" do
22
22
 
23
23
  foo = 5
24
24
 
25
- lambda do
25
+ expect(lambda do
26
26
  PryRescue.peek!
27
- end.should change{ foo }.from(5).to(6)
27
+ end).to change{ foo }.from(5).to(6)
28
28
  end
29
29
  end
@@ -4,52 +4,52 @@ require 'uri'
4
4
  describe "PryRescue.load" do
5
5
  if defined?(PryStackExplorer)
6
6
  it "should open at the correct point" do
7
- PryRescue.should_receive(:pry).once{ |opts|
8
- opts[:call_stack].first.eval("__FILE__").should end_with('spec/fixtures/simple.rb')
7
+ expect(PryRescue).to receive(:pry).once { |opts|
8
+ expect(opts[:call_stack].first.eval("__FILE__")).to end_with('spec/fixtures/simple.rb')
9
9
  }
10
- lambda{
10
+ expect(lambda {
11
11
  PryRescue.load("spec/fixtures/simple.rb")
12
- }.should raise_error(/simple-exception/)
12
+ }).to raise_error(/simple-exception/)
13
13
  end
14
14
 
15
15
  it "should open above the standard library" do
16
- PryRescue.should_receive(:pry).once do |opts|
17
- opts[:call_stack][opts[:initial_frame]].eval("__FILE__").should end_with('spec/fixtures/uri.rb')
16
+ expect(PryRescue).to receive(:pry).once do |opts|
17
+ expect(opts[:call_stack][opts[:initial_frame]].eval("__FILE__")).to end_with('spec/fixtures/uri.rb')
18
18
  end
19
- lambda{
19
+ expect(lambda{
20
20
  PryRescue.load("spec/fixtures/uri.rb")
21
- }.should raise_error(URI::InvalidURIError)
21
+ }).to raise_error(URI::InvalidURIError)
22
22
  end
23
23
 
24
24
  it "should keep the standard library on the binding stack" do
25
- PryRescue.should_receive(:pry).once do |opts|
26
- opts[:call_stack].first.eval("__FILE__").should start_with(RbConfig::CONFIG['libdir'])
25
+ expect(PryRescue).to receive(:pry).once do |opts|
26
+ expect(opts[:call_stack].first.eval("__FILE__")).to start_with(RbConfig::CONFIG['libdir'])
27
27
  end
28
- lambda{
28
+ expect(lambda{
29
29
  PryRescue.load("spec/fixtures/uri.rb")
30
- }.should raise_error(URI::InvalidURIError)
30
+ }).to raise_error(URI::InvalidURIError)
31
31
  end
32
32
 
33
33
  it "should open above gems" do
34
- PryRescue.should_receive(:pry).once do |opts|
35
- opts[:call_stack][opts[:initial_frame]].eval("__FILE__").should end_with('spec/fixtures/coderay.rb')
34
+ expect(PryRescue).to receive(:pry).once do |opts|
35
+ expect(opts[:call_stack][opts[:initial_frame]].eval("__FILE__")).to end_with('spec/fixtures/coderay.rb')
36
36
  end
37
- lambda{
37
+ expect(lambda{
38
38
  PryRescue.load("spec/fixtures/coderay.rb")
39
- }.should raise_error(ArgumentError)
39
+ }).to raise_error(ArgumentError)
40
40
  end
41
41
 
42
42
  it "should open above gems" do
43
- PryRescue.should_receive(:pry).once do |opts|
43
+ expect(PryRescue).to receive(:pry).once do |opts|
44
44
  coderay_path = Gem::Specification.respond_to?(:detect) ?
45
45
  Gem::Specification.detect{|x| x.name == 'coderay' }.full_gem_path :
46
46
  Gem.all_load_paths.grep(/coderay/).last
47
47
 
48
- opts[:call_stack].first.eval("__FILE__").should start_with(coderay_path)
48
+ expect(opts[:call_stack].first.eval("__FILE__")).to start_with(coderay_path)
49
49
  end
50
- lambda{
50
+ expect(lambda{
51
51
  PryRescue.load("spec/fixtures/coderay.rb")
52
- }.should raise_error(ArgumentError)
52
+ }).to raise_error(ArgumentError)
53
53
  end
54
54
 
55
55
  it "should skip pwd, even if it is a gem (but not vendor stuff)" do
@@ -66,56 +66,56 @@ describe "PryRescue.load" do
66
66
  end
67
67
 
68
68
  it "should filter out duplicate stack frames" do
69
- PryRescue.should_receive(:pry).once do |opts|
70
- opts[:call_stack][0].eval("__LINE__").should == 4
71
- opts[:call_stack][1].eval("__LINE__").should == 12
69
+ expect(PryRescue).to receive(:pry).once do |opts|
70
+ expect(opts[:call_stack][0].eval("__LINE__")).to be(4)
71
+ expect(opts[:call_stack][1].eval("__LINE__")).to be(12)
72
72
  end
73
- lambda{
73
+ expect(lambda{
74
74
  PryRescue.load("spec/fixtures/super.rb")
75
- }.should raise_error(/super-exception/)
75
+ }).to raise_error(/super-exception/)
76
76
  end
77
77
 
78
78
  it "should calculate correct initial frame even when duplicates are present" do
79
- PryRescue.should_receive(:pry).once do |opts|
80
- opts[:call_stack][0].eval("__FILE__").should end_with('fake.rb')
81
- opts[:call_stack][opts[:initial_frame]].eval("__FILE__").should end_with('spec/fixtures/initial.rb')
79
+ expect(PryRescue).to receive(:pry).once do |opts|
80
+ expect(opts[:call_stack][0].eval("__FILE__")).to end_with('fake.rb')
81
+ expect(opts[:call_stack][opts[:initial_frame]].eval("__FILE__")).to end_with('spec/fixtures/initial.rb')
82
82
  end
83
- lambda{
83
+ expect(lambda{
84
84
  PryRescue.load("spec/fixtures/initial.rb")
85
- }.should raise_error(/no :baz please/)
85
+ }).to raise_error(/no :baz please/)
86
86
  end
87
87
 
88
88
  it "should skip over reraises from within gems" do
89
- PryRescue.should_receive(:pry).once do |opts|
90
- opts[:call_stack][0].eval("__FILE__").should end_with('spec/fixtures/reraise.rb')
89
+ expect(PryRescue).to receive(:pry).once do |opts|
90
+ expect(opts[:call_stack][0].eval("__FILE__")).to end_with('spec/fixtures/reraise.rb')
91
91
  end
92
- lambda{
92
+ expect(lambda{
93
93
  PryRescue.load("spec/fixtures/reraise.rb")
94
- }.should raise_error(/reraise-exception/)
94
+ }).to raise_error(/reraise-exception/)
95
95
  end
96
96
 
97
97
  it "should not skip over independent raises within gems" do
98
- PryRescue.should_receive(:pry).once do |opts|
99
- opts[:call_stack][0].eval("__FILE__").should end_with('fake.rb')
98
+ expect(PryRescue).to receive(:pry).once do |opts|
99
+ expect(opts[:call_stack][0].eval("__FILE__")).to end_with('fake.rb')
100
100
  end
101
- lambda{
101
+ expect(lambda{
102
102
  PryRescue.load("spec/fixtures/raiseother.rb")
103
- }.should raise_error(/raiseother_exception/)
103
+ }).to raise_error(/raiseother_exception/)
104
104
  end
105
105
 
106
106
  it "should output a warning if the exception was not raised" do
107
- PryRescue.should_not_receive(:enter_exception_context)
108
- Pry.should_receive(:warn).once
107
+ expect(PryRescue).to_not receive(:enter_exception_context)
108
+ expect(Pry).to receive(:warn).once
109
109
  Pry.rescued(RuntimeError.new("foo"))
110
110
  end
111
111
  else
112
112
  it "should open at the correct point" do
113
- Pry.should_receive(:start).once{ |binding, h|
114
- binding.eval("__FILE__").should end_with('spec/fixtures/simple.rb')
113
+ expect(Pry).to receive(:start).once { |binding, h|
114
+ expect(binding.eval("__FILE__")).to end_with('spec/fixtures/simple.rb')
115
115
  }
116
- lambda{
116
+ expect(lambda{
117
117
  PryRescue.load("spec/fixtures/simple.rb")
118
- }.should raise_error(/simple-exception/)
118
+ }).to raise_error(/simple-exception/)
119
119
  end
120
120
  end
121
121
  end
@@ -1,5 +1,3 @@
1
1
  require 'rspec'
2
2
 
3
- require 'pry/test/helper'
4
-
5
3
  require './lib/pry-rescue'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pry-rescue
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.5
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Conrad Irwin
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-02-16 00:00:00.000000000 Z
13
+ date: 2018-11-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: pry
@@ -18,14 +18,14 @@ dependencies:
18
18
  requirements:
19
19
  - - ">="
20
20
  - !ruby/object:Gem::Version
21
- version: '0'
21
+ version: 0.12.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - ">="
27
27
  - !ruby/object:Gem::Version
28
- version: '0'
28
+ version: 0.12.0
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: interception
31
31
  requirement: !ruby/object:Gem::Requirement
@@ -178,6 +178,7 @@ files:
178
178
  - spec/fixtures/reraise.rb
179
179
  - spec/fixtures/simple.rb
180
180
  - spec/fixtures/super.rb
181
+ - spec/fixtures/template_error.rb
181
182
  - spec/fixtures/uri.rb
182
183
  - spec/peek_spec.rb
183
184
  - spec/pry_rescue_spec.rb
@@ -202,7 +203,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
202
203
  version: '0'
203
204
  requirements: []
204
205
  rubyforge_project:
205
- rubygems_version: 2.6.8
206
+ rubygems_version: 2.6.11
206
207
  signing_key:
207
208
  specification_version: 4
208
209
  summary: Open a pry session on any unhandled exceptions