mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
* Abort early when searching for a superclass if the target method has been called through 'super' keyword from a prepended module. * mv spec/regression spec/integration * add hanami integration spec
This commit is contained in:
parent
62c6183b9c
commit
6a89f574da
4 changed files with 72 additions and 12 deletions
19
CHANGELOG.md
19
CHANGELOG.md
|
@ -3,19 +3,30 @@
|
|||
#### Features
|
||||
|
||||
* Add Pry::Testable, an improved modular replacement for PryTestHelpers.
|
||||
**breaking change**. [#1679](https://github.com/pry/pry/pull/1679).
|
||||
**breaking change**.
|
||||
|
||||
See pull request [#1679](https://github.com/pry/pry/pull/1679).
|
||||
|
||||
* Add a new category module: "Pry::Platform". Loosely related to #1668 below.
|
||||
[#1670](https://github.com/pry/pry/pull/1670)
|
||||
|
||||
See pull request [#1670](https://github.com/pry/pry/pull/1670)
|
||||
|
||||
* Add `mac_osx?` and `linux?` utility functions to Pry::Helpers::BaseHelpers.
|
||||
[#1668](https://github.com/pry/pry/pull/1668).
|
||||
|
||||
See pull request [#1668](https://github.com/pry/pry/pull/1668).
|
||||
|
||||
* Add utility functions for drawing colorised text on a colorised background.
|
||||
[#1673](https://github.com/pry/pry/pull/1673).
|
||||
|
||||
See pull request [#1673](https://github.com/pry/pry/pull/1673).
|
||||
|
||||
#### Bug fixes
|
||||
|
||||
* Fix a case of infinite recursion in `Pry::Method::WeirdMethodLocator#find_method_in_superclass`
|
||||
that users of the [Hanami](http://hanamirb.org/) web framework experienced and
|
||||
reported since 2015.
|
||||
|
||||
See pull request [#1639](https://github.com/pry/pry/pull/1689).
|
||||
|
||||
* Fix a bug where Method objects were not returned for setters inherited
|
||||
from a default (Pry::Config::Default). Eg, this is no longer an error:
|
||||
|
||||
|
|
|
@ -26,13 +26,17 @@ class Pry
|
|||
# @param [Binding] b
|
||||
# @return [Boolean]
|
||||
def normal_method?(method, b)
|
||||
method && (method.source_file && method.source_range rescue false) &&
|
||||
File.expand_path(method.source_file) == File.expand_path(b.eval('__FILE__')) &&
|
||||
method.source_range.include?(b.eval('__LINE__'))
|
||||
if method and method.source_file and method.source_range
|
||||
binding_file, binding_line = b.eval('__FILE__'), b.eval('__LINE__')
|
||||
File.expand_path(method.source_file) == File.expand_path(binding_file) and
|
||||
method.source_range.include?(binding_line)
|
||||
end
|
||||
rescue
|
||||
false
|
||||
end
|
||||
|
||||
def weird_method?(method, b)
|
||||
!normal_method?(method, b)
|
||||
not normal_method?(method, b)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -61,6 +65,11 @@ class Pry
|
|||
|
||||
private
|
||||
|
||||
def skip_superclass_search?
|
||||
target_mod = @target.eval('self').class
|
||||
target_mod.ancestors.take_while {|mod| mod != target_mod }.any?
|
||||
end
|
||||
|
||||
def normal_method?(method)
|
||||
self.class.normal_method?(method, target)
|
||||
end
|
||||
|
@ -98,7 +107,9 @@ class Pry
|
|||
# superclass method.
|
||||
def find_method_in_superclass
|
||||
guess = method
|
||||
|
||||
if skip_superclass_search?
|
||||
return guess
|
||||
end
|
||||
while guess
|
||||
# needs rescue if this is a Disowned method or a C method or something...
|
||||
# TODO: Fix up the exception handling so we don't need a bare rescue
|
||||
|
|
38
spec/integration/hanami_spec.rb
Normal file
38
spec/integration/hanami_spec.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
require "helper"
|
||||
require "shellwords"
|
||||
|
||||
RSpec.describe "Hanami integration" do
|
||||
before :all do
|
||||
@ruby = RbConfig.ruby.shellescape
|
||||
@pry_dir = File.expand_path(File.join(__FILE__, '../../../lib')).shellescape
|
||||
end
|
||||
|
||||
it "does not enter an infinite loop (#1471, #1621)" do
|
||||
skip "prepend is not supported on this version of Ruby" if RUBY_VERSION.start_with? "1.9"
|
||||
code = <<-RUBY
|
||||
require "pry"
|
||||
require "timeout"
|
||||
module Prepend1
|
||||
def call(arg)
|
||||
super
|
||||
end
|
||||
end
|
||||
module Prepend2
|
||||
def call(arg)
|
||||
super
|
||||
end
|
||||
end
|
||||
class Action
|
||||
prepend Prepend1
|
||||
prepend Prepend2
|
||||
def call(arg)
|
||||
binding.pry input: StringIO.new("exit"), output: StringIO.new
|
||||
end
|
||||
end
|
||||
Timeout.timeout(1) { Action.new.call("define prison, in the abstract sense") }
|
||||
exit 42
|
||||
RUBY
|
||||
`#@ruby -I#@pry_dir -e'#{code}'`
|
||||
expect($?.exitstatus).to eq(42)
|
||||
end
|
||||
end
|
|
@ -4,9 +4,9 @@
|
|||
require "helper"
|
||||
require "shellwords"
|
||||
|
||||
describe "Readline" do
|
||||
before do
|
||||
@ruby = RbConfig.ruby.shellescape
|
||||
RSpec.describe "Readline" do
|
||||
before :all do
|
||||
@ruby = RbConfig.ruby.shellescape
|
||||
@pry_dir = File.expand_path(File.join(__FILE__, '../../../lib')).shellescape
|
||||
end
|
||||
|
Loading…
Reference in a new issue