pry-rescue 1.4.1 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rspec +1 -0
- data/.travis.yml +7 -4
- data/CHANGELOG.md +3 -0
- data/README.md +33 -1
- data/bin/rescue +13 -6
- data/lib/pry-rescue.rb +13 -4
- data/lib/pry-rescue/commands.rb +2 -0
- data/lib/pry-rescue/kernel_exit_hooks.rb +4 -1
- data/lib/pry-rescue/minitest.rb +4 -2
- data/lib/pry-rescue/rails.rb +5 -3
- data/lib/pry-rescue/rspec.rb +14 -1
- data/lib/pry-rescue/source_location.rb +13 -0
- data/pry-rescue.gemspec +3 -3
- data/spec/commands_spec.rb +53 -27
- data/spec/core_ext_spec.rb +21 -21
- data/spec/fixtures/template_error.rb +13 -0
- data/spec/peek_spec.rb +4 -4
- data/spec/pry_rescue_spec.rb +62 -47
- data/spec/source_location_spec.rb +19 -0
- data/spec/spec_helper.rb +0 -3
- metadata +30 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c70d483edf7b738214f0f22aa4d9fb81909de0de007cb6e581124331d1d8eeb8
|
4
|
+
data.tar.gz: d9cfd93f342bfe7373ab80b83e2f7f0304ea3472037e10877b640324bf0b5fc3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff2b45da86ffec10f67fae0c3aa4d24270d5c907d8b3380cecb580f50ff37a0c733c2d8dd956c925081bc20d84e1b9bc9a15e10030ba49ed8bce1a83824b5732
|
7
|
+
data.tar.gz: 22e51ce3bcc20834edb13e115c9030d2c6945466886d85d0a9a239a69ebfdc38dde922e2968a07c0408134e00a8adc7954e071c21e1cf9b4604b2ea7073b9b8c
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Super-fast debugging for Ruby. (See [Pry to the rescue!](http://cirw.in/blog/pry-to-the-rescue))
|
4
4
|
<a href="https://travis-ci.org/ConradIrwin/pry-rescue">
|
5
|
-
<img src="https://secure.travis-ci.org/ConradIrwin/pry-rescue.
|
5
|
+
<img src="https://secure.travis-ci.org/ConradIrwin/pry-rescue.svg?branch=master" alt="Build status">
|
6
6
|
</a>
|
7
7
|
|
8
8
|
## Introduction
|
@@ -69,12 +69,22 @@ Then whenever an unhandled exception happens inside Rails, a Pry console will op
|
|
69
69
|
stdout. This is the same terminal that you see the Rails logs on, so if you're
|
70
70
|
using something like [pow](https://pow.cx) then you will run into difficulties.
|
71
71
|
|
72
|
+
If you are using non-default http servers like Unicorn or Thin, you can also trigger
|
73
|
+
this behavior via (after including pry-rescue in your Gemfile):
|
74
|
+
|
75
|
+
```
|
76
|
+
PRY_RESCUE_RAILS=1 bundle exec unicorn
|
77
|
+
```
|
78
|
+
|
79
|
+
|
80
|
+
|
72
81
|
You might also be interested in
|
73
82
|
[better_errors](https://github.com/charliesome/better_errors) which opens consoles in your
|
74
83
|
browser on unhandled exceptions, and [pry-rails](https://github.com/rweng/pry-rails) which
|
75
84
|
adds some Rails specific helpers to Pry, and replaces `rails console` by Pry.
|
76
85
|
|
77
86
|
### RSpec
|
87
|
+
**ActiveRecord users: see below caveat**
|
78
88
|
|
79
89
|
If you're using [RSpec](https://rspec.org) or
|
80
90
|
[respec](https://github.com/oggy/respec), you can open a Pry session on
|
@@ -96,10 +106,32 @@ RSpec::Expectations::ExpectationNotMetError: expected: 0.3
|
|
96
106
|
[1] pry(main)>
|
97
107
|
```
|
98
108
|
|
109
|
+
### Important caveat when using with Rails/ActiveRecord and transactional fixtures
|
110
|
+
> Records are missing but should be there! Am I losing track of reality?
|
111
|
+
|
112
|
+
You are not. (Probably.)
|
113
|
+
|
114
|
+
By default, RSpec runs test examples in a transaction, and rolls it back when done.
|
115
|
+
By the time Pry-Rescue fires, the transaction has already been rolled back and records are gone!
|
116
|
+
|
117
|
+
A good sanity check is to call `Model.all`. It will usually be empty. However, at the time of the test, they were truly there.
|
118
|
+
|
119
|
+
This bug is currently tracked at [#99](https://github.com/ConradIrwin/pry-rescue/issues/99).
|
120
|
+
|
121
|
+
Current workaround: Pry-Rescue can't be used, but you can use `binding.pry` inside the test. You'll have access to all records you need there.
|
122
|
+
|
123
|
+
### Using pry `edit`
|
99
124
|
Unfortunately using `edit -c` to edit `_spec.rb` files does not yet reload the
|
100
125
|
code in a way that the `try-again` command can understand. You can still use
|
101
126
|
`try-again` if you edit code that is not in spec files.
|
102
127
|
|
128
|
+
### Always enabled
|
129
|
+
If you want pry-rescue to *always* be enabled when you run tests, simply add this line to your `test_helper.rb`:
|
130
|
+
|
131
|
+
```ruby
|
132
|
+
require 'pry-rescue/rspec'
|
133
|
+
```
|
134
|
+
|
103
135
|
### Minitest
|
104
136
|
|
105
137
|
Add the following to your `test_helper.rb` or to the top of your test file.
|
data/bin/rescue
CHANGED
@@ -34,12 +34,19 @@ when '-i'
|
|
34
34
|
when /\A-/
|
35
35
|
puts USAGE
|
36
36
|
exit
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
37
|
+
else
|
38
|
+
case File.basename(ARGV[0] || "")
|
39
|
+
when 'rails'
|
40
|
+
ENV['PRY_RESCUE_RAILS'] = 'true'
|
41
|
+
exec(*ARGV)
|
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$/
|
47
|
+
ENV['SPEC_OPTS'] = "#{ENV['SPEC_OPTS']} -r pry-rescue/rspec"
|
48
|
+
exec(*ARGV)
|
49
|
+
end
|
43
50
|
end
|
44
51
|
|
45
52
|
if script = ARGV.shift
|
data/lib/pry-rescue.rb
CHANGED
@@ -6,13 +6,14 @@ require File.expand_path('../pry-rescue/core_ext', __FILE__)
|
|
6
6
|
require File.expand_path('../pry-rescue/commands', __FILE__)
|
7
7
|
require File.expand_path('../pry-rescue/rack', __FILE__)
|
8
8
|
require File.expand_path('../pry-rescue/peek.rb', __FILE__)
|
9
|
+
require File.expand_path('../pry-rescue/source_location.rb', __FILE__)
|
9
10
|
|
10
11
|
if ENV['PRY_RESCUE_RAILS']
|
11
12
|
require File.expand_path('../pry-rescue/rails', __FILE__)
|
12
13
|
end
|
13
14
|
case ENV['PRY_PEEK']
|
14
15
|
when nil
|
15
|
-
PryRescue.peek_on_signal('QUIT') unless Pry::Helpers::
|
16
|
+
PryRescue.peek_on_signal('QUIT') unless Pry::Helpers::Platform.windows?
|
16
17
|
when ''
|
17
18
|
# explicitly disable QUIT.
|
18
19
|
else
|
@@ -79,6 +80,14 @@ class PryRescue
|
|
79
80
|
end
|
80
81
|
end
|
81
82
|
|
83
|
+
def load_rake(task)
|
84
|
+
require 'rake'
|
85
|
+
Pry::rescue do
|
86
|
+
load "#{Dir.pwd}/Rakefile"
|
87
|
+
Rake::Task[task].invoke
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
82
91
|
# Is the user currently inside pry rescue?
|
83
92
|
# @return [Boolean]
|
84
93
|
def in_exception_context?
|
@@ -95,7 +104,7 @@ class PryRescue
|
|
95
104
|
# @param [Exception] e The raised exception
|
96
105
|
def phantom_load_raise?(e)
|
97
106
|
bindings = e.instance_variable_get(:@rescue_bindings)
|
98
|
-
bindings.any? && bindings.first
|
107
|
+
bindings.any? && SourceLocation.call(bindings.first)[0] == __FILE__
|
99
108
|
end
|
100
109
|
|
101
110
|
# When using pry-stack-explorer we want to start the rescue session outside of gems
|
@@ -105,7 +114,7 @@ class PryRescue
|
|
105
114
|
# @return [Fixnum] The offset of the first binding of user code
|
106
115
|
def initial_frame(bindings)
|
107
116
|
bindings.each_with_index do |binding, i|
|
108
|
-
return i if user_path?(
|
117
|
+
return i if user_path?(SourceLocation.call(binding)[0])
|
109
118
|
end
|
110
119
|
|
111
120
|
0
|
@@ -162,7 +171,7 @@ class PryRescue
|
|
162
171
|
def without_bindings_below_raise(bindings)
|
163
172
|
return bindings if bindings.size <= 1
|
164
173
|
bindings.drop_while do |b|
|
165
|
-
|
174
|
+
SourceLocation.call(b)[0] == File.expand_path("../pry-rescue/core_ext.rb", __FILE__)
|
166
175
|
end.drop_while do |b|
|
167
176
|
Interception == b.eval("self")
|
168
177
|
end
|
data/lib/pry-rescue/commands.rb
CHANGED
@@ -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
|
data/lib/pry-rescue/minitest.rb
CHANGED
@@ -2,7 +2,9 @@ require 'pry-rescue'
|
|
2
2
|
|
3
3
|
# Minitest 5 handles all unknown exceptions, so to get them out of
|
4
4
|
# minitest, we need to add Exception to its passthrough types
|
5
|
-
|
5
|
+
# Note: We need to check the explicit minitest version because the minitest ecosystem
|
6
|
+
# may redefine Minitest::Test for Minitest versions < 5.
|
7
|
+
if defined?(Minitest::Test) && Minitest::Unit::VERSION.split('.').first.to_i >= 5
|
6
8
|
|
7
9
|
class Minitest::Test
|
8
10
|
alias_method :run_without_rescue, :run
|
@@ -22,7 +24,7 @@ else
|
|
22
24
|
# Unfortunately the version of minitest bundled with ruby seems to
|
23
25
|
# take precedence over the new gem, so we can't do this and still
|
24
26
|
# support ruby-1.9.3
|
25
|
-
|
27
|
+
|
26
28
|
class MiniTest::Unit::TestCase
|
27
29
|
alias_method :run_without_rescue, :run
|
28
30
|
|
data/lib/pry-rescue/rails.rb
CHANGED
@@ -6,9 +6,11 @@ class PryRescue
|
|
6
6
|
# Just adding 'use PryRescue::Rack' inside your rails app will add
|
7
7
|
# the middleware above the rails exception handling middleware,
|
8
8
|
# and so it will not work.
|
9
|
-
|
10
|
-
|
11
|
-
app
|
9
|
+
if defined?(::Rails)
|
10
|
+
class Railtie < ::Rails::Railtie
|
11
|
+
initializer "pry_rescue" do |app|
|
12
|
+
app.config.middleware.use PryRescue::Rack
|
13
|
+
end
|
12
14
|
end
|
13
15
|
end
|
14
16
|
end
|
data/lib/pry-rescue/rspec.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
require 'pry-rescue'
|
2
|
+
require 'pry-stack_explorer'
|
3
|
+
require 'rspec' unless defined?(RSpec)
|
4
|
+
|
2
5
|
class PryRescue
|
3
6
|
class RSpec
|
4
7
|
|
@@ -11,8 +14,18 @@ class PryRescue
|
|
11
14
|
before
|
12
15
|
|
13
16
|
example.binding.eval('@exception = nil; @example && @example.instance_variable_set(:@exception, nil)')
|
17
|
+
example.binding.eval('example.instance_variable_set(:@exception, nil) if defined?(example)')
|
18
|
+
if example.example_group_instance.respond_to?(:__init_memoized, true)
|
19
|
+
example.binding.eval('@example && @example.example_group_instance.instance_variable_set(:@__init_memoized, true)')
|
20
|
+
example.binding.eval('example.example_group_instance.instance_variable_set(:@__init_memoized, true) if defined?(example)')
|
21
|
+
else
|
22
|
+
example.binding.eval('@example && @example.example_group_instance.instance_variable_set(:@__memoized, {})')
|
23
|
+
example.binding.eval('example.example_group_instance.instance_variable_set(:@__memoized, {}) if defined?(example)')
|
24
|
+
end
|
14
25
|
example.run
|
15
|
-
|
26
|
+
e = example.binding.eval('@exception || @example && @example.instance_variable_get(:@exception)')
|
27
|
+
e ||= example.binding.eval('example.instance_variable_get(:@exception) if defined?(example)')
|
28
|
+
if e
|
16
29
|
Pry::rescued(e)
|
17
30
|
end
|
18
31
|
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class PryRescue
|
2
|
+
module SourceLocation
|
3
|
+
DEPRECATION_TIME = Time.new(2021,4,1)
|
4
|
+
|
5
|
+
WithRuby2_5 = ->(b){ [b.eval("__FILE__"), b.eval("__LINE__")] }
|
6
|
+
WithRuby2_6 = ->(b){ b.source_location }
|
7
|
+
|
8
|
+
define_singleton_method(
|
9
|
+
:call,
|
10
|
+
(RUBY_VERSION < "2.6.0") ? WithRuby2_5 : WithRuby2_6
|
11
|
+
)
|
12
|
+
end
|
13
|
+
end
|
data/pry-rescue.gemspec
CHANGED
@@ -1,23 +1,23 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'pry-rescue'
|
3
|
-
s.version = '1.
|
3
|
+
s.version = '1.5.1'
|
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'
|
7
7
|
s.email = ['conrad.irwin@gmail.com', 'jrmair@gmail.com', 'chris@ill-logic.com']
|
8
8
|
s.authors = ['Conrad Irwin', 'banisterfiend', 'epitron']
|
9
9
|
s.files = `git ls-files`.split("\n")
|
10
|
+
s.license = 'MIT'
|
10
11
|
s.require_paths = ['lib']
|
11
12
|
s.executables = s.files.grep(%r{^bin/}).map{|f| File.basename f}
|
12
13
|
|
13
|
-
s.add_dependency 'pry'
|
14
|
+
s.add_dependency 'pry', '>= 0.12.0'
|
14
15
|
s.add_dependency 'interception', '>= 0.5'
|
15
16
|
|
16
17
|
s.add_development_dependency 'pry-stack_explorer' # upgrade to regular dep?
|
17
18
|
|
18
19
|
s.add_development_dependency 'rake'
|
19
20
|
s.add_development_dependency 'rspec'
|
20
|
-
s.add_development_dependency 'yard'
|
21
21
|
s.add_development_dependency 'redcarpet'
|
22
22
|
s.add_development_dependency 'capybara'
|
23
23
|
end
|
data/spec/commands_spec.rb
CHANGED
@@ -1,21 +1,22 @@
|
|
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
|
5
6
|
it "should throw try_again" do
|
6
|
-
PryRescue.
|
7
|
+
expect(PryRescue).to receive(:in_exception_context?).and_return(true)
|
7
8
|
|
8
|
-
|
9
|
-
Pry.new.process_command
|
10
|
-
}.
|
9
|
+
expect {
|
10
|
+
Pry.new.process_command("try-again")
|
11
|
+
}.to throw_symbol(:try_again)
|
11
12
|
end
|
12
13
|
|
13
14
|
it "should raise a CommandError if not in Pry::rescue" do
|
14
|
-
PryRescue.
|
15
|
+
expect(PryRescue).to receive(:in_exception_context?).and_return(false)
|
15
16
|
|
16
|
-
|
17
|
-
Pry.new.process_command "try-again"
|
18
|
-
}.
|
17
|
+
expect {
|
18
|
+
Pry.new.process_command "try-again"
|
19
|
+
}.to raise_error Pry::CommandError
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
@@ -28,11 +29,11 @@ describe "pry-rescue commands" do
|
|
28
29
|
b2 = binding
|
29
30
|
end
|
30
31
|
|
31
|
-
Pry.
|
32
|
-
raised.
|
33
|
-
|
32
|
+
allow(Pry).to receive(:rescued).once do |raised|
|
33
|
+
expect(raised).to eq e1
|
34
|
+
end
|
34
35
|
|
35
|
-
Pry.new.process_command 'cd-cause e1'
|
36
|
+
Pry.new.tap{ |p| p.push_binding(binding) }.process_command 'cd-cause e1'
|
36
37
|
end
|
37
38
|
|
38
39
|
it "should enter the context of _ex_ if no exception is given" do
|
@@ -47,15 +48,39 @@ describe "pry-rescue commands" do
|
|
47
48
|
end
|
48
49
|
end
|
49
50
|
|
50
|
-
Pry.
|
51
|
-
raised.
|
52
|
-
|
51
|
+
allow(Pry).to receive(:rescued).once do |raised|
|
52
|
+
expect(raised).to eq _ex_
|
53
|
+
end
|
53
54
|
|
54
|
-
Pry.new.process_command 'cd-cause'
|
55
|
+
Pry.new.tap{ |p| p.push_binding(b2) }.process_command 'cd-cause'
|
55
56
|
end
|
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
|
@@ -73,9 +98,10 @@ describe "pry-rescue commands" do
|
|
73
98
|
end
|
74
99
|
end
|
75
100
|
|
76
|
-
PryRescue.
|
101
|
+
expect(PryRescue).to receive(:enter_exception_context).once.with(e1)
|
77
102
|
|
78
|
-
Pry.new.process_command 'cd-cause'
|
103
|
+
Pry.new.tap{ |p| p.push_binding(binding) }.process_command 'cd-cause'
|
104
|
+
# PryTester.new(binding).process_command 'cd-cause'
|
79
105
|
end
|
80
106
|
|
81
107
|
it "should raise a CommandError if no previous commands" do
|
@@ -88,9 +114,9 @@ describe "pry-rescue commands" do
|
|
88
114
|
_ex_ = e1
|
89
115
|
end
|
90
116
|
|
91
|
-
|
92
|
-
Pry.new.process_command 'cd-cause'
|
93
|
-
}.
|
117
|
+
expect {
|
118
|
+
Pry.new.tap{ |p| p.push_binding(binding) }.process_command 'cd-cause'
|
119
|
+
}.to raise_error Pry::CommandError, /No previous exception/
|
94
120
|
end
|
95
121
|
|
96
122
|
it "should raise a CommandError on a re-raise" do
|
@@ -107,15 +133,15 @@ describe "pry-rescue commands" do
|
|
107
133
|
end
|
108
134
|
_rescued_ = _ex_
|
109
135
|
|
110
|
-
|
111
|
-
Pry.new.process_command 'cd-cause'
|
112
|
-
}.
|
136
|
+
expect {
|
137
|
+
Pry.new.tap{ |p| p.push_binding(binding) }.process_command 'cd-cause'
|
138
|
+
}.to raise_error Pry::CommandError, /No previous exception/
|
113
139
|
end
|
114
140
|
|
115
141
|
it "should raise a CommandError if not in Pry::rescue" do
|
116
|
-
|
117
|
-
Pry.new.process_command 'cd-cause'
|
118
|
-
}.
|
142
|
+
expect {
|
143
|
+
Pry.new.tap{ |p| p.push_binding(binding) }.process_command 'cd-cause'
|
144
|
+
}.to raise_error Pry::CommandError, /No previous exception/
|
119
145
|
end
|
120
146
|
end
|
121
147
|
end
|
data/spec/core_ext_spec.rb
CHANGED
@@ -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.
|
5
|
+
expect(lambda {
|
6
|
+
expect(PryRescue).to receive(:enter_exception_context).once
|
7
7
|
Pry::rescue{ raise "foobar" }
|
8
|
-
}.
|
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.
|
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.
|
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.
|
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.
|
33
|
-
@inner.
|
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.
|
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.
|
46
|
+
end).to raise_error(/first_occurance/)
|
47
47
|
end
|
48
48
|
|
49
49
|
it "should not catch SystemExit" do
|
50
|
-
PryRescue.
|
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.
|
56
|
+
end).to raise_error SystemExit
|
57
57
|
end
|
58
58
|
|
59
59
|
it 'should not catch Ctrl+C' do
|
60
|
-
PryRescue.
|
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.
|
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.
|
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.
|
83
|
-
message.
|
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.
|
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
|
+
|
data/spec/peek_spec.rb
CHANGED
@@ -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.
|
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.
|
27
|
+
end).to change{ foo }.from(5).to(6)
|
28
28
|
end
|
29
29
|
end
|
data/spec/pry_rescue_spec.rb
CHANGED
@@ -2,113 +2,128 @@ require File.expand_path('../../lib/pry-rescue.rb', __FILE__)
|
|
2
2
|
require 'uri'
|
3
3
|
|
4
4
|
describe "PryRescue.load" do
|
5
|
+
before :all do
|
6
|
+
if !binding.respond_to?(:source_location)
|
7
|
+
Binding.define_method :source_location do
|
8
|
+
PryRescue::SourceLocation.call(self)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
5
13
|
if defined?(PryStackExplorer)
|
6
14
|
it "should open at the correct point" do
|
7
|
-
PryRescue.
|
8
|
-
opts[:call_stack].first.
|
15
|
+
expect(PryRescue).to receive(:pry).once { |opts|
|
16
|
+
expect(opts[:call_stack].first.source_location[0]).to end_with('spec/fixtures/simple.rb')
|
9
17
|
}
|
10
|
-
lambda{
|
18
|
+
expect(lambda {
|
11
19
|
PryRescue.load("spec/fixtures/simple.rb")
|
12
|
-
}.
|
20
|
+
}).to raise_error(/simple-exception/)
|
13
21
|
end
|
14
22
|
|
15
23
|
it "should open above the standard library" do
|
16
|
-
PryRescue.
|
17
|
-
opts[:call_stack][opts[:initial_frame]].
|
24
|
+
expect(PryRescue).to receive(:pry).once do |opts|
|
25
|
+
expect(opts[:call_stack][opts[:initial_frame]].source_location[0]).to end_with('spec/fixtures/uri.rb')
|
18
26
|
end
|
19
|
-
lambda{
|
27
|
+
expect(lambda{
|
20
28
|
PryRescue.load("spec/fixtures/uri.rb")
|
21
|
-
}.
|
29
|
+
}).to raise_error(URI::InvalidURIError)
|
22
30
|
end
|
23
31
|
|
24
32
|
it "should keep the standard library on the binding stack" do
|
25
|
-
PryRescue.
|
26
|
-
opts[:call_stack].first.
|
33
|
+
expect(PryRescue).to receive(:pry).once do |opts|
|
34
|
+
expect(opts[:call_stack].first.source_location[0]).to start_with(RbConfig::CONFIG['libdir'])
|
27
35
|
end
|
28
|
-
lambda{
|
36
|
+
expect(lambda{
|
29
37
|
PryRescue.load("spec/fixtures/uri.rb")
|
30
|
-
}.
|
38
|
+
}).to raise_error(URI::InvalidURIError)
|
31
39
|
end
|
32
40
|
|
33
41
|
it "should open above gems" do
|
34
|
-
PryRescue.
|
35
|
-
opts[:call_stack][opts[:initial_frame]].
|
42
|
+
expect(PryRescue).to receive(:pry).once do |opts|
|
43
|
+
expect(opts[:call_stack][opts[:initial_frame]].source_location[0]).to end_with('spec/fixtures/coderay.rb')
|
36
44
|
end
|
37
|
-
lambda{
|
45
|
+
expect(lambda{
|
38
46
|
PryRescue.load("spec/fixtures/coderay.rb")
|
39
|
-
}.
|
47
|
+
}).to raise_error(ArgumentError)
|
40
48
|
end
|
41
49
|
|
42
50
|
it "should open above gems" do
|
43
|
-
PryRescue.
|
51
|
+
expect(PryRescue).to receive(:pry).once do |opts|
|
44
52
|
coderay_path = Gem::Specification.respond_to?(:detect) ?
|
45
53
|
Gem::Specification.detect{|x| x.name == 'coderay' }.full_gem_path :
|
46
54
|
Gem.all_load_paths.grep(/coderay/).last
|
47
55
|
|
48
|
-
opts[:call_stack].first.
|
56
|
+
expect(opts[:call_stack].first.source_location[0]).to start_with(coderay_path)
|
49
57
|
end
|
50
|
-
lambda{
|
58
|
+
expect(lambda{
|
51
59
|
PryRescue.load("spec/fixtures/coderay.rb")
|
52
|
-
}.
|
60
|
+
}).to raise_error(ArgumentError)
|
53
61
|
end
|
54
62
|
|
55
63
|
it "should skip pwd, even if it is a gem (but not vendor stuff)" do
|
56
|
-
Gem::Specification.stub :any? do true end
|
57
|
-
|
58
|
-
|
64
|
+
# Gem::Specification.stub :any? do true end
|
65
|
+
allow(Gem::Specification).to receive(:any?).and_return(true)
|
66
|
+
|
67
|
+
expect(
|
68
|
+
PryRescue.send(:user_path?, Dir.pwd + '/asdf.rb')
|
69
|
+
).to be true
|
70
|
+
|
71
|
+
expect(
|
72
|
+
PryRescue.send(:user_path?, Dir.pwd + '/vendor/asdf.rb')
|
73
|
+
).to be false
|
59
74
|
end
|
60
75
|
|
61
76
|
it "should filter out duplicate stack frames" do
|
62
|
-
PryRescue.
|
63
|
-
opts[:call_stack][0].
|
64
|
-
opts[:call_stack][1].
|
77
|
+
expect(PryRescue).to receive(:pry).once do |opts|
|
78
|
+
expect(opts[:call_stack][0].source_location[1]).to be(4)
|
79
|
+
expect(opts[:call_stack][1].source_location[1]).to be(12)
|
65
80
|
end
|
66
|
-
lambda{
|
81
|
+
expect(lambda{
|
67
82
|
PryRescue.load("spec/fixtures/super.rb")
|
68
|
-
}.
|
83
|
+
}).to raise_error(/super-exception/)
|
69
84
|
end
|
70
85
|
|
71
86
|
it "should calculate correct initial frame even when duplicates are present" do
|
72
|
-
PryRescue.
|
73
|
-
opts[:call_stack][0].
|
74
|
-
opts[:call_stack][opts[:initial_frame]].
|
87
|
+
expect(PryRescue).to receive(:pry).once do |opts|
|
88
|
+
expect(opts[:call_stack][0].source_location[0]).to end_with('fake.rb')
|
89
|
+
expect(opts[:call_stack][opts[:initial_frame]].source_location[0]).to end_with('spec/fixtures/initial.rb')
|
75
90
|
end
|
76
|
-
lambda{
|
91
|
+
expect(lambda{
|
77
92
|
PryRescue.load("spec/fixtures/initial.rb")
|
78
|
-
}.
|
93
|
+
}).to raise_error(/no :baz please/)
|
79
94
|
end
|
80
95
|
|
81
96
|
it "should skip over reraises from within gems" do
|
82
|
-
PryRescue.
|
83
|
-
opts[:call_stack][0].
|
97
|
+
expect(PryRescue).to receive(:pry).once do |opts|
|
98
|
+
expect(opts[:call_stack][0].source_location[0]).to end_with('spec/fixtures/reraise.rb')
|
84
99
|
end
|
85
|
-
lambda{
|
100
|
+
expect(lambda{
|
86
101
|
PryRescue.load("spec/fixtures/reraise.rb")
|
87
|
-
}.
|
102
|
+
}).to raise_error(/reraise-exception/)
|
88
103
|
end
|
89
104
|
|
90
105
|
it "should not skip over independent raises within gems" do
|
91
|
-
PryRescue.
|
92
|
-
opts[:call_stack][0].
|
106
|
+
expect(PryRescue).to receive(:pry).once do |opts|
|
107
|
+
expect(opts[:call_stack][0].source_location[0]).to end_with('fake.rb')
|
93
108
|
end
|
94
|
-
lambda{
|
109
|
+
expect(lambda{
|
95
110
|
PryRescue.load("spec/fixtures/raiseother.rb")
|
96
|
-
}.
|
111
|
+
}).to raise_error(/raiseother_exception/)
|
97
112
|
end
|
98
113
|
|
99
114
|
it "should output a warning if the exception was not raised" do
|
100
|
-
PryRescue.
|
101
|
-
Pry.
|
115
|
+
expect(PryRescue).to_not receive(:enter_exception_context)
|
116
|
+
expect(Pry).to receive(:warn).once
|
102
117
|
Pry.rescued(RuntimeError.new("foo"))
|
103
118
|
end
|
104
119
|
else
|
105
120
|
it "should open at the correct point" do
|
106
|
-
Pry.
|
107
|
-
binding.
|
121
|
+
expect(Pry).to receive(:start).once { |binding, h|
|
122
|
+
expect(binding.source_location[0]).to end_with('spec/fixtures/simple.rb')
|
108
123
|
}
|
109
|
-
lambda{
|
124
|
+
expect(lambda{
|
110
125
|
PryRescue.load("spec/fixtures/simple.rb")
|
111
|
-
}.
|
126
|
+
}).to raise_error(/simple-exception/)
|
112
127
|
end
|
113
128
|
end
|
114
129
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
describe PryRescue::SourceLocation do
|
2
|
+
describe ".call" do
|
3
|
+
subject{ described_class.call(binding) }
|
4
|
+
|
5
|
+
it "matches [file, line]" do
|
6
|
+
is_expected.to match([__FILE__, be_between(2,30)])
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
it "will be removed when Ruby 2.5 is EOL" do
|
11
|
+
time = Time.now
|
12
|
+
|
13
|
+
if time >= described_class::DEPRECATION_TIME
|
14
|
+
expect(
|
15
|
+
defined?(PryRescue::SourceLocation)
|
16
|
+
).to be false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/spec/spec_helper.rb
CHANGED
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
|
+
version: 1.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Conrad Irwin
|
@@ -10,118 +10,104 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2020-05-29 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: pry
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - ">="
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
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:
|
28
|
+
version: 0.12.0
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: interception
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
32
32
|
requirements:
|
33
|
-
- -
|
33
|
+
- - ">="
|
34
34
|
- !ruby/object:Gem::Version
|
35
35
|
version: '0.5'
|
36
36
|
type: :runtime
|
37
37
|
prerelease: false
|
38
38
|
version_requirements: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
|
-
- -
|
40
|
+
- - ">="
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: '0.5'
|
43
43
|
- !ruby/object:Gem::Dependency
|
44
44
|
name: pry-stack_explorer
|
45
45
|
requirement: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
|
-
- -
|
47
|
+
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
49
|
version: '0'
|
50
50
|
type: :development
|
51
51
|
prerelease: false
|
52
52
|
version_requirements: !ruby/object:Gem::Requirement
|
53
53
|
requirements:
|
54
|
-
- -
|
54
|
+
- - ">="
|
55
55
|
- !ruby/object:Gem::Version
|
56
56
|
version: '0'
|
57
57
|
- !ruby/object:Gem::Dependency
|
58
58
|
name: rake
|
59
59
|
requirement: !ruby/object:Gem::Requirement
|
60
60
|
requirements:
|
61
|
-
- -
|
61
|
+
- - ">="
|
62
62
|
- !ruby/object:Gem::Version
|
63
63
|
version: '0'
|
64
64
|
type: :development
|
65
65
|
prerelease: false
|
66
66
|
version_requirements: !ruby/object:Gem::Requirement
|
67
67
|
requirements:
|
68
|
-
- -
|
68
|
+
- - ">="
|
69
69
|
- !ruby/object:Gem::Version
|
70
70
|
version: '0'
|
71
71
|
- !ruby/object:Gem::Dependency
|
72
72
|
name: rspec
|
73
73
|
requirement: !ruby/object:Gem::Requirement
|
74
74
|
requirements:
|
75
|
-
- -
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
version: '0'
|
78
|
-
type: :development
|
79
|
-
prerelease: false
|
80
|
-
version_requirements: !ruby/object:Gem::Requirement
|
81
|
-
requirements:
|
82
|
-
- - '>='
|
83
|
-
- !ruby/object:Gem::Version
|
84
|
-
version: '0'
|
85
|
-
- !ruby/object:Gem::Dependency
|
86
|
-
name: yard
|
87
|
-
requirement: !ruby/object:Gem::Requirement
|
88
|
-
requirements:
|
89
|
-
- - '>='
|
75
|
+
- - ">="
|
90
76
|
- !ruby/object:Gem::Version
|
91
77
|
version: '0'
|
92
78
|
type: :development
|
93
79
|
prerelease: false
|
94
80
|
version_requirements: !ruby/object:Gem::Requirement
|
95
81
|
requirements:
|
96
|
-
- -
|
82
|
+
- - ">="
|
97
83
|
- !ruby/object:Gem::Version
|
98
84
|
version: '0'
|
99
85
|
- !ruby/object:Gem::Dependency
|
100
86
|
name: redcarpet
|
101
87
|
requirement: !ruby/object:Gem::Requirement
|
102
88
|
requirements:
|
103
|
-
- -
|
89
|
+
- - ">="
|
104
90
|
- !ruby/object:Gem::Version
|
105
91
|
version: '0'
|
106
92
|
type: :development
|
107
93
|
prerelease: false
|
108
94
|
version_requirements: !ruby/object:Gem::Requirement
|
109
95
|
requirements:
|
110
|
-
- -
|
96
|
+
- - ">="
|
111
97
|
- !ruby/object:Gem::Version
|
112
98
|
version: '0'
|
113
99
|
- !ruby/object:Gem::Dependency
|
114
100
|
name: capybara
|
115
101
|
requirement: !ruby/object:Gem::Requirement
|
116
102
|
requirements:
|
117
|
-
- -
|
103
|
+
- - ">="
|
118
104
|
- !ruby/object:Gem::Version
|
119
105
|
version: '0'
|
120
106
|
type: :development
|
121
107
|
prerelease: false
|
122
108
|
version_requirements: !ruby/object:Gem::Requirement
|
123
109
|
requirements:
|
124
|
-
- -
|
110
|
+
- - ">="
|
125
111
|
- !ruby/object:Gem::Version
|
126
112
|
version: '0'
|
127
113
|
description: Allows you to wrap code in Pry::rescue{ } to open a pry session at any
|
@@ -136,8 +122,10 @@ executables:
|
|
136
122
|
extensions: []
|
137
123
|
extra_rdoc_files: []
|
138
124
|
files:
|
139
|
-
- .gitignore
|
140
|
-
- .
|
125
|
+
- ".gitignore"
|
126
|
+
- ".rspec"
|
127
|
+
- ".travis.yml"
|
128
|
+
- CHANGELOG.md
|
141
129
|
- Gemfile
|
142
130
|
- LICENSE.MIT
|
143
131
|
- README.md
|
@@ -168,6 +156,7 @@ files:
|
|
168
156
|
- lib/pry-rescue/rack.rb
|
169
157
|
- lib/pry-rescue/rails.rb
|
170
158
|
- lib/pry-rescue/rspec.rb
|
159
|
+
- lib/pry-rescue/source_location.rb
|
171
160
|
- lib/pry/rescue.rb
|
172
161
|
- pry-rescue.gemspec
|
173
162
|
- spec/commands_spec.rb
|
@@ -178,12 +167,15 @@ files:
|
|
178
167
|
- spec/fixtures/reraise.rb
|
179
168
|
- spec/fixtures/simple.rb
|
180
169
|
- spec/fixtures/super.rb
|
170
|
+
- spec/fixtures/template_error.rb
|
181
171
|
- spec/fixtures/uri.rb
|
182
172
|
- spec/peek_spec.rb
|
183
173
|
- spec/pry_rescue_spec.rb
|
174
|
+
- spec/source_location_spec.rb
|
184
175
|
- spec/spec_helper.rb
|
185
176
|
homepage: https://github.com/ConradIrwin/pry-rescue
|
186
|
-
licenses:
|
177
|
+
licenses:
|
178
|
+
- MIT
|
187
179
|
metadata: {}
|
188
180
|
post_install_message:
|
189
181
|
rdoc_options: []
|
@@ -191,19 +183,17 @@ require_paths:
|
|
191
183
|
- lib
|
192
184
|
required_ruby_version: !ruby/object:Gem::Requirement
|
193
185
|
requirements:
|
194
|
-
- -
|
186
|
+
- - ">="
|
195
187
|
- !ruby/object:Gem::Version
|
196
188
|
version: '0'
|
197
189
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
198
190
|
requirements:
|
199
|
-
- -
|
191
|
+
- - ">="
|
200
192
|
- !ruby/object:Gem::Version
|
201
193
|
version: '0'
|
202
194
|
requirements: []
|
203
|
-
|
204
|
-
rubygems_version: 2.0.3
|
195
|
+
rubygems_version: 3.0.3
|
205
196
|
signing_key:
|
206
197
|
specification_version: 4
|
207
198
|
summary: Open a pry session on any unhandled exceptions
|
208
199
|
test_files: []
|
209
|
-
has_rdoc:
|