pry-rescue 1.4.5 → 1.6.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
- SHA1:
3
- metadata.gz: f8498adfc62776fab874402fd91ff59f7a0b3811
4
- data.tar.gz: 2efe1214b7acb9361f5c84754bad36aebfc769bd
2
+ SHA256:
3
+ metadata.gz: 9858e248a006df546dbc0e2e4a5b0055e9f0e2276bce651729af051d88741ec7
4
+ data.tar.gz: dbc440ce345d54877bd894a8dfe89c9d497e4f144ffcc5dadf702bb89887c7cc
5
5
  SHA512:
6
- metadata.gz: a60814bf969deba350559387f5a11c79fa6b03e86bb90656cee06f1ec26dd52e3db99ea815dbe033cb10fd65dcce59a932959c838a2b1b70a40d238057f2be54
7
- data.tar.gz: 94c9e761195dcd0c7eb01c17af7670b0eea83fa9d59e36d4b24a1612f4b49807f6f12f0463072c4f5a7838d5ff256f54fb2d4629fb896d8edc9cfc37ea8e1121
6
+ metadata.gz: cccaff14cd38dfe24cfa8a85d7121b90f526e214cb6accf474e1237429a372d871eb5189e696ea18b4eb34371f236ebfeee0559202d1301be11b0bf8d06ebdd9
7
+ data.tar.gz: 5236813e00b7a5198159d181c1b660c4aad9b4f8c1b7c50a9c69d39753d5641d8f8efe24176a51f709b91d1f28301baae577d930c5cfe393d93ebbc8f958db89
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.travis.yml CHANGED
@@ -1,10 +1,9 @@
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.5
5
+ - 2.6
6
+ - 2.7
8
7
  - ruby-head
9
8
  before_install:
10
9
  - "gem update --system"
data/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ ## v1.6.0 (9 January 2024)
2
+ * Fix ruby 3.2 compatibility
3
+
4
+ ## v1.5.2 (24 June 2020)
5
+ * RSpec: Fix Rescue opening after transactional tests are rolled back.
6
+ (issue #99 - PR #118) (@joallard)
7
+
8
+ * bin/rescue: Use realpaths (issue #109 - PR #110)
9
+
10
+ *(Damien Robert)*
11
+
12
+ ## v1.5.1 (22 May 2020)
13
+ * Make Binding#source_location polyfill. (Removes deprecation warnings
14
+ for Ruby 2.6+)
data/README.md CHANGED
@@ -109,6 +109,12 @@ Unfortunately using `edit -c` to edit `_spec.rb` files does not yet reload the
109
109
  code in a way that the `try-again` command can understand. You can still use
110
110
  `try-again` if you edit code that is not in spec files.
111
111
 
112
+ If you want pry-rescue to *always* be enabled when you run tests, simply add this line to your `test_helper.rb`:
113
+
114
+ ```ruby
115
+ require 'pry-rescue/rspec'
116
+ ```
117
+
112
118
  ### Minitest
113
119
 
114
120
  Add the following to your `test_helper.rb` or to the top of your test file.
data/Rakefile CHANGED
@@ -1,3 +1,4 @@
1
+ require "bundler/gem_tasks"
1
2
  require 'rspec/core/rake_task'
2
3
 
3
4
  task :default => :test
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.realpath(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
@@ -47,8 +51,9 @@ end
47
51
 
48
52
  if script = ARGV.shift
49
53
  $0 = File.expand_path(script)
50
- if File.exists? script
51
- require File.expand_path('../../lib/pry-rescue.rb', __FILE__)
54
+
55
+ if File.exist? script
56
+ require File.realpath(File.expand_path('../../lib/pry-rescue.rb', __FILE__))
52
57
  PryRescue.load $0, ensure_repl
53
58
  else
54
59
  $stderr.puts "Error: #{script.inspect} not found."
@@ -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,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
@@ -7,29 +8,23 @@ class PryRescue
7
8
  # Run an Rspec example within Pry::rescue{ }.
8
9
  #
9
10
  # Takes care to ensure that `try-again` will work.
11
+ #
12
+ # `example` is a RSpec::Core::Example::Procsy
10
13
  def self.run(example)
11
14
  Pry::rescue do
12
15
  begin
13
16
  before
14
17
 
15
- example.binding.eval('@exception = nil; @example && @example.instance_variable_set(:@exception, nil)')
16
- example.binding.eval('example.instance_variable_set(:@exception, nil) if defined?(example)')
17
- if example.example_group_instance.respond_to?(:__init_memoized, true)
18
- example.binding.eval('@example && @example.example_group_instance.instance_variable_set(:@__init_memoized, true)')
19
- example.binding.eval('example.example_group_instance.instance_variable_set(:@__init_memoized, true) if defined?(example)')
20
- else
21
- example.binding.eval('@example && @example.example_group_instance.instance_variable_set(:@__memoized, {})')
22
- example.binding.eval('example.example_group_instance.instance_variable_set(:@__memoized, {}) if defined?(example)')
23
- end
18
+ example.example.instance_variable_set(:@exception, nil)
19
+ example.example_group_instance.instance_variable_set(:@__init_memoized, true)
20
+
24
21
  example.run
25
- e = example.binding.eval('@exception || @example && @example.instance_variable_get(:@exception)')
26
- e ||= example.binding.eval('example.instance_variable_get(:@exception) if defined?(example)')
27
- if e
28
- Pry::rescued(e)
29
- end
22
+
23
+ # Rescued will be called in :after hook, which is ran before the second
24
+ # :around leg
30
25
 
31
26
  ensure
32
- after
27
+ after_outside
33
28
  end
34
29
  end
35
30
  end
@@ -38,7 +33,12 @@ class PryRescue
38
33
  monkeypatch_capybara if defined?(Capybara)
39
34
  end
40
35
 
41
- def self.after
36
+ def self.after(example)
37
+ e = example.exception
38
+ Pry::rescued(e) if e
39
+ end
40
+
41
+ def self.after_outside
42
42
  after_filters.each(&:call)
43
43
  end
44
44
 
@@ -50,7 +50,13 @@ class PryRescue
50
50
  unless Capybara.respond_to?(:reset_sessions_after_rescue!)
51
51
  class << Capybara
52
52
  alias_method :reset_sessions_after_rescue!, :reset_sessions!
53
- def reset_sessions!; end
53
+ def reset_sessions!
54
+ return if Capybara.raise_server_errors
55
+
56
+ session_pool.reverse_each do |_mode, session|
57
+ session.server.reset_error!
58
+ end
59
+ end
54
60
  end
55
61
 
56
62
  after_filters << Capybara.method(:reset_sessions_after_rescue!)
@@ -67,4 +73,8 @@ RSpec.configure do |c|
67
73
  c.around(:each) do |example|
68
74
  PryRescue::RSpec.run example
69
75
  end
76
+
77
+ c.after(:each) do |example|
78
+ PryRescue::RSpec.after(example)
79
+ end
70
80
  end
@@ -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/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::BaseHelpers.windows?
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.eval("__FILE__") == __FILE__
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?(binding.eval("__FILE__"))
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
- 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__)
166
175
  end.drop_while do |b|
167
176
  Interception == b.eval("self")
168
177
  end
data/pry-rescue.gemspec CHANGED
@@ -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.6.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?
@@ -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
@@ -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
+
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.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
@@ -2,54 +2,62 @@ 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.should_receive(:pry).once{ |opts|
8
- opts[:call_stack].first.eval("__FILE__").should end_with('spec/fixtures/simple.rb')
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
- }.should raise_error(/simple-exception/)
20
+ }).to raise_error(/simple-exception/)
13
21
  end
14
22
 
15
23
  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')
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
- }.should raise_error(URI::InvalidURIError)
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.should_receive(:pry).once do |opts|
26
- opts[:call_stack].first.eval("__FILE__").should start_with(RbConfig::CONFIG['libdir'])
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
- }.should raise_error(URI::InvalidURIError)
38
+ }).to raise_error(URI::InvalidURIError)
31
39
  end
32
40
 
33
41
  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')
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
- }.should raise_error(ArgumentError)
47
+ }).to raise_error(ArgumentError)
40
48
  end
41
49
 
42
50
  it "should open above gems" do
43
- PryRescue.should_receive(:pry).once do |opts|
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.eval("__FILE__").should start_with(coderay_path)
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
- }.should raise_error(ArgumentError)
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
@@ -66,56 +74,56 @@ describe "PryRescue.load" do
66
74
  end
67
75
 
68
76
  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
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)
72
80
  end
73
- lambda{
81
+ expect(lambda{
74
82
  PryRescue.load("spec/fixtures/super.rb")
75
- }.should raise_error(/super-exception/)
83
+ }).to raise_error(/super-exception/)
76
84
  end
77
85
 
78
86
  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')
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')
82
90
  end
83
- lambda{
91
+ expect(lambda{
84
92
  PryRescue.load("spec/fixtures/initial.rb")
85
- }.should raise_error(/no :baz please/)
93
+ }).to raise_error(/no :baz please/)
86
94
  end
87
95
 
88
96
  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')
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')
91
99
  end
92
- lambda{
100
+ expect(lambda{
93
101
  PryRescue.load("spec/fixtures/reraise.rb")
94
- }.should raise_error(/reraise-exception/)
102
+ }).to raise_error(/reraise-exception/)
95
103
  end
96
104
 
97
105
  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')
106
+ expect(PryRescue).to receive(:pry).once do |opts|
107
+ expect(opts[:call_stack][0].source_location[0]).to end_with('fake.rb')
100
108
  end
101
- lambda{
109
+ expect(lambda{
102
110
  PryRescue.load("spec/fixtures/raiseother.rb")
103
- }.should raise_error(/raiseother_exception/)
111
+ }).to raise_error(/raiseother_exception/)
104
112
  end
105
113
 
106
114
  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
115
+ expect(PryRescue).to_not receive(:enter_exception_context)
116
+ expect(Pry).to receive(:warn).once
109
117
  Pry.rescued(RuntimeError.new("foo"))
110
118
  end
111
119
  else
112
120
  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')
121
+ expect(Pry).to receive(:start).once { |binding, h|
122
+ expect(binding.source_location[0]).to end_with('spec/fixtures/simple.rb')
115
123
  }
116
- lambda{
124
+ expect(lambda{
117
125
  PryRescue.load("spec/fixtures/simple.rb")
118
- }.should raise_error(/simple-exception/)
126
+ }).to raise_error(/simple-exception/)
119
127
  end
120
128
  end
121
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
@@ -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.6.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: 2024-01-10 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
@@ -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
@@ -178,9 +167,11 @@ 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
177
  licenses:
@@ -201,8 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
201
192
  - !ruby/object:Gem::Version
202
193
  version: '0'
203
194
  requirements: []
204
- rubyforge_project:
205
- rubygems_version: 2.6.8
195
+ rubygems_version: 3.0.3.1
206
196
  signing_key:
207
197
  specification_version: 4
208
198
  summary: Open a pry session on any unhandled exceptions