pry-rescue 1.5.0 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 936ad34711f6f4e6084c959c7e6e1431873cc549
4
- data.tar.gz: 44befec5ee09418f9c459c8b548a5840da6c8cc0
2
+ SHA256:
3
+ metadata.gz: c70d483edf7b738214f0f22aa4d9fb81909de0de007cb6e581124331d1d8eeb8
4
+ data.tar.gz: d9cfd93f342bfe7373ab80b83e2f7f0304ea3472037e10877b640324bf0b5fc3
5
5
  SHA512:
6
- metadata.gz: 8c3e94547db32735d4f60200ad2bfa8de32427812dfa88a8db56487b7d28a7d0f5d4c5e1204f9a9016edc55957833994e6065ee3866a9c974acb8663f82dbd43
7
- data.tar.gz: a8cb171f27a823a38260675a2721db15137fbb136be816ee0825cb3673f2b8fb4eb044452957b150d35164462e6842b87d672b8f97e816bc2183d52adfde99a1
6
+ metadata.gz: ff2b45da86ffec10f67fae0c3aa4d24270d5c907d8b3380cecb580f50ff37a0c733c2d8dd956c925081bc20d84e1b9bc9a15e10030ba49ed8bce1a83824b5732
7
+ data.tar.gz: 22e51ce3bcc20834edb13e115c9030d2c6945466886d85d0a9a239a69ebfdc38dde922e2968a07c0408134e00a8adc7954e071c21e1cf9b4604b2ea7073b9b8c
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
@@ -1,10 +1,9 @@
1
1
  language: ruby
2
2
  cache: bundler
3
3
  rvm:
4
- - 2.2
5
- - 2.3
6
- - 2.4
7
4
  - 2.5
5
+ - 2.6
6
+ - 2.7
8
7
  - ruby-head
9
8
  before_install:
10
9
  - "gem update --system"
@@ -0,0 +1,3 @@
1
+ ## v1.5.1 (22 May 2020)
2
+ * Make Binding#source_location polyfill. (Removes deprecation warnings
3
+ for Ruby 2.6+)
data/README.md CHANGED
@@ -84,6 +84,7 @@ browser on unhandled exceptions, and [pry-rails](https://github.com/rweng/pry-ra
84
84
  adds some Rails specific helpers to Pry, and replaces `rails console` by Pry.
85
85
 
86
86
  ### RSpec
87
+ **ActiveRecord users: see below caveat**
87
88
 
88
89
  If you're using [RSpec](https://rspec.org) or
89
90
  [respec](https://github.com/oggy/respec), you can open a Pry session on
@@ -105,10 +106,32 @@ RSpec::Expectations::ExpectationNotMetError: expected: 0.3
105
106
  [1] pry(main)>
106
107
  ```
107
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`
108
124
  Unfortunately using `edit -c` to edit `_spec.rb` files does not yet reload the
109
125
  code in a way that the `try-again` command can understand. You can still use
110
126
  `try-again` if you edit code that is not in spec files.
111
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
+
112
135
  ### Minitest
113
136
 
114
137
  Add the following to your `test_helper.rb` or to the top of your test file.
@@ -6,6 +6,7 @@ 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__)
@@ -103,7 +104,7 @@ class PryRescue
103
104
  # @param [Exception] e The raised exception
104
105
  def phantom_load_raise?(e)
105
106
  bindings = e.instance_variable_get(:@rescue_bindings)
106
- bindings.any? && bindings.first.eval("__FILE__") == __FILE__
107
+ bindings.any? && SourceLocation.call(bindings.first)[0] == __FILE__
107
108
  end
108
109
 
109
110
  # When using pry-stack-explorer we want to start the rescue session outside of gems
@@ -113,7 +114,7 @@ class PryRescue
113
114
  # @return [Fixnum] The offset of the first binding of user code
114
115
  def initial_frame(bindings)
115
116
  bindings.each_with_index do |binding, i|
116
- return i if user_path?(binding.eval("__FILE__"))
117
+ return i if user_path?(SourceLocation.call(binding)[0])
117
118
  end
118
119
 
119
120
  0
@@ -170,7 +171,7 @@ class PryRescue
170
171
  def without_bindings_below_raise(bindings)
171
172
  return bindings if bindings.size <= 1
172
173
  bindings.drop_while do |b|
173
- b.eval("__FILE__") == File.expand_path("../pry-rescue/core_ext.rb", __FILE__)
174
+ SourceLocation.call(b)[0] == File.expand_path("../pry-rescue/core_ext.rb", __FILE__)
174
175
  end.drop_while do |b|
175
176
  Interception == b.eval("self")
176
177
  end
@@ -1,4 +1,5 @@
1
1
  require 'pry-rescue'
2
+ require 'pry-stack_explorer'
2
3
  require 'rspec' unless defined?(RSpec)
3
4
 
4
5
  class PryRescue
@@ -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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'pry-rescue'
3
- s.version = '1.5.0'
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'
@@ -20,23 +20,4 @@ Gem::Specification.new do |s|
20
20
  s.add_development_dependency 'rspec'
21
21
  s.add_development_dependency 'redcarpet'
22
22
  s.add_development_dependency 'capybara'
23
-
24
- # SPECIAL DEVELOPMENT GEM FOR OLD RUBY
25
- # DONT USE THIS TRICK FOR RUNTIME GEM
26
- if Gem::Version.create(RUBY_VERSION) < Gem::Version.create("2.2.2")
27
- s.add_development_dependency 'yard', '< 0.9.6'
28
- s.add_development_dependency 'rack', ['~> 1.6', '< 1.7']
29
- else
30
- s.add_development_dependency 'yard'
31
- end
32
- if Gem::Version.create(RUBY_VERSION) < Gem::Version.create("2.1")
33
- # capybara > nokogiri
34
- s.add_development_dependency 'nokogiri', ['~> 1.6', '< 1.7.0']
35
- end
36
- if Gem::Version.create(RUBY_VERSION) < Gem::Version.create("2.0")
37
- # capybara > addressable > public_suffix
38
- s.add_development_dependency 'public_suffix', ['~> 1.4', '< 1.5']
39
- # capybara > mime-types
40
- s.add_development_dependency 'mime-types', ['~> 2.6', '< 2.99']
41
- end
42
23
  end
@@ -2,10 +2,18 @@ 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
15
  expect(PryRescue).to receive(:pry).once { |opts|
8
- expect(opts[:call_stack].first.eval("__FILE__")).to end_with('spec/fixtures/simple.rb')
16
+ expect(opts[:call_stack].first.source_location[0]).to end_with('spec/fixtures/simple.rb')
9
17
  }
10
18
  expect(lambda {
11
19
  PryRescue.load("spec/fixtures/simple.rb")
@@ -14,7 +22,7 @@ describe "PryRescue.load" do
14
22
 
15
23
  it "should open above the standard library" do
16
24
  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')
25
+ expect(opts[:call_stack][opts[:initial_frame]].source_location[0]).to end_with('spec/fixtures/uri.rb')
18
26
  end
19
27
  expect(lambda{
20
28
  PryRescue.load("spec/fixtures/uri.rb")
@@ -23,7 +31,7 @@ describe "PryRescue.load" do
23
31
 
24
32
  it "should keep the standard library on the binding stack" do
25
33
  expect(PryRescue).to receive(:pry).once do |opts|
26
- expect(opts[:call_stack].first.eval("__FILE__")).to start_with(RbConfig::CONFIG['libdir'])
34
+ expect(opts[:call_stack].first.source_location[0]).to start_with(RbConfig::CONFIG['libdir'])
27
35
  end
28
36
  expect(lambda{
29
37
  PryRescue.load("spec/fixtures/uri.rb")
@@ -32,7 +40,7 @@ describe "PryRescue.load" do
32
40
 
33
41
  it "should open above gems" do
34
42
  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')
43
+ expect(opts[:call_stack][opts[:initial_frame]].source_location[0]).to end_with('spec/fixtures/coderay.rb')
36
44
  end
37
45
  expect(lambda{
38
46
  PryRescue.load("spec/fixtures/coderay.rb")
@@ -45,7 +53,7 @@ describe "PryRescue.load" do
45
53
  Gem::Specification.detect{|x| x.name == 'coderay' }.full_gem_path :
46
54
  Gem.all_load_paths.grep(/coderay/).last
47
55
 
48
- expect(opts[:call_stack].first.eval("__FILE__")).to start_with(coderay_path)
56
+ expect(opts[:call_stack].first.source_location[0]).to start_with(coderay_path)
49
57
  end
50
58
  expect(lambda{
51
59
  PryRescue.load("spec/fixtures/coderay.rb")
@@ -67,8 +75,8 @@ describe "PryRescue.load" do
67
75
 
68
76
  it "should filter out duplicate stack frames" do
69
77
  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)
78
+ expect(opts[:call_stack][0].source_location[1]).to be(4)
79
+ expect(opts[:call_stack][1].source_location[1]).to be(12)
72
80
  end
73
81
  expect(lambda{
74
82
  PryRescue.load("spec/fixtures/super.rb")
@@ -77,8 +85,8 @@ describe "PryRescue.load" do
77
85
 
78
86
  it "should calculate correct initial frame even when duplicates are present" do
79
87
  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')
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')
82
90
  end
83
91
  expect(lambda{
84
92
  PryRescue.load("spec/fixtures/initial.rb")
@@ -87,7 +95,7 @@ describe "PryRescue.load" do
87
95
 
88
96
  it "should skip over reraises from within gems" do
89
97
  expect(PryRescue).to receive(:pry).once do |opts|
90
- expect(opts[:call_stack][0].eval("__FILE__")).to end_with('spec/fixtures/reraise.rb')
98
+ expect(opts[:call_stack][0].source_location[0]).to end_with('spec/fixtures/reraise.rb')
91
99
  end
92
100
  expect(lambda{
93
101
  PryRescue.load("spec/fixtures/reraise.rb")
@@ -96,7 +104,7 @@ describe "PryRescue.load" do
96
104
 
97
105
  it "should not skip over independent raises within gems" do
98
106
  expect(PryRescue).to receive(:pry).once do |opts|
99
- expect(opts[:call_stack][0].eval("__FILE__")).to end_with('fake.rb')
107
+ expect(opts[:call_stack][0].source_location[0]).to end_with('fake.rb')
100
108
  end
101
109
  expect(lambda{
102
110
  PryRescue.load("spec/fixtures/raiseother.rb")
@@ -111,7 +119,7 @@ describe "PryRescue.load" do
111
119
  else
112
120
  it "should open at the correct point" do
113
121
  expect(Pry).to receive(:start).once { |binding, h|
114
- expect(binding.eval("__FILE__")).to end_with('spec/fixtures/simple.rb')
122
+ expect(binding.source_location[0]).to end_with('spec/fixtures/simple.rb')
115
123
  }
116
124
  expect(lambda{
117
125
  PryRescue.load("spec/fixtures/simple.rb")
@@ -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
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.5.0
4
+ version: 1.5.1
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: 2018-11-13 00:00:00.000000000 Z
13
+ date: 2020-05-29 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: pry
@@ -110,20 +110,6 @@ dependencies:
110
110
  - - ">="
111
111
  - !ruby/object:Gem::Version
112
112
  version: '0'
113
- - !ruby/object:Gem::Dependency
114
- name: yard
115
- requirement: !ruby/object:Gem::Requirement
116
- requirements:
117
- - - ">="
118
- - !ruby/object:Gem::Version
119
- version: '0'
120
- type: :development
121
- prerelease: false
122
- version_requirements: !ruby/object:Gem::Requirement
123
- requirements:
124
- - - ">="
125
- - !ruby/object:Gem::Version
126
- version: '0'
127
113
  description: Allows you to wrap code in Pry::rescue{ } to open a pry session at any
128
114
  unhandled exceptions
129
115
  email:
@@ -137,7 +123,9 @@ extensions: []
137
123
  extra_rdoc_files: []
138
124
  files:
139
125
  - ".gitignore"
126
+ - ".rspec"
140
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
@@ -182,6 +171,7 @@ files:
182
171
  - spec/fixtures/uri.rb
183
172
  - spec/peek_spec.rb
184
173
  - spec/pry_rescue_spec.rb
174
+ - spec/source_location_spec.rb
185
175
  - spec/spec_helper.rb
186
176
  homepage: https://github.com/ConradIrwin/pry-rescue
187
177
  licenses:
@@ -202,8 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
202
192
  - !ruby/object:Gem::Version
203
193
  version: '0'
204
194
  requirements: []
205
- rubyforge_project:
206
- rubygems_version: 2.6.11
195
+ rubygems_version: 3.0.3
207
196
  signing_key:
208
197
  specification_version: 4
209
198
  summary: Open a pry session on any unhandled exceptions