1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

Merge branch 'master' into wip-config

Conflicts:
	lib/pry.rb
This commit is contained in:
Robert Gleeson 2014-01-20 08:43:36 +01:00
commit 5177913c91
20 changed files with 1291 additions and 1386 deletions

View file

@ -37,8 +37,9 @@ class Pry
# Read the class name off of the singleton class to provide a default # Read the class name off of the singleton class to provide a default
# inspect. # inspect.
eig = class << obj; self; end singleton = class << obj; self; end
klass = Pry::Method.safe_send(eig, :ancestors).first ancestors = Pry::Method.safe_send(singleton, :ancestors)
klass = ancestors.reject { |k| k == singleton }.first
obj_id = obj.__id__.to_s(16) rescue 0 obj_id = obj.__id__.to_s(16) rescue 0
str = "#<#{klass}:0x#{obj_id}>" str = "#<#{klass}:0x#{obj_id}>"

View file

@ -6,8 +6,6 @@ class Pry
group 'Context' group 'Context'
description 'Recursively search for a method within a Class/Module or the current namespace.' description 'Recursively search for a method within a Class/Module or the current namespace.'
command_options :shellwords => false command_options :shellwords => false
command_options :requires_gem => 'ruby18_source_location' if mri_18?
banner <<-'BANNER' banner <<-'BANNER'
Usage: find-method [-n|-c] METHOD [NAMESPACE] Usage: find-method [-n|-c] METHOD [NAMESPACE]
@ -26,10 +24,6 @@ class Pry
find-method -c 'output.puts' Pry find-method -c 'output.puts' Pry
BANNER BANNER
def setup
require 'ruby18_source_location' if mri_18?
end
def options(opti) def options(opti)
opti.on :n, :name, "Search for a method by name" opti.on :n, :name, "Search for a method by name"
opti.on :c, :content, "Search for a method based on content in Regex form" opti.on :c, :content, "Search for a method based on content in Regex form"

View file

@ -3,11 +3,6 @@ class Pry
extend Pry::Helpers::BaseHelpers extend Pry::Helpers::BaseHelpers
command_options :shellwords => false, :interpolate => false command_options :shellwords => false, :interpolate => false
command_options :requires_gem => "ruby18_source_location" if mri_18?
def setup
require 'ruby18_source_location' if mri_18?
end
def options(opt) def options(opt)
opt.on :s, :super, "Select the 'super' method. Can be repeated to traverse the ancestors", :as => :count opt.on :s, :super, "Select the 'super' method. Can be repeated to traverse the ancestors", :as => :count

View file

@ -99,7 +99,6 @@ class Object
end end
end end
if defined?(BasicObject)
class BasicObject class BasicObject
# Return a binding object for the receiver. # Return a binding object for the receiver.
# #
@ -124,12 +123,9 @@ if defined?(BasicObject)
# #
# @return [Binding] # @return [Binding]
def __pry__ def __pry__
# In ruby-1.8.7 ::Kernel.binding sets self to Kernel in the returned binding.
# Luckily ruby-1.8.7 doesn't have BasicObject, so this is safe.
::Kernel.binding ::Kernel.binding
end end
EOF EOF
self.__pry__ self.__pry__
end end
end end
end

View file

@ -90,10 +90,6 @@ class Pry
RbConfig::CONFIG['ruby_install_name'] == 'ruby' RbConfig::CONFIG['ruby_install_name'] == 'ruby'
end end
def mri_18?
mri? && RUBY_VERSION =~ /1.8/
end
def mri_19? def mri_19?
mri? && RUBY_VERSION =~ /1.9/ mri? && RUBY_VERSION =~ /1.9/
end end

View file

@ -146,9 +146,6 @@ class Pry
def exec_hook(event_name, *args, &block) def exec_hook(event_name, *args, &block)
@hooks[event_name] ||= [] @hooks[event_name] ||= []
# silence warnings to get rid of 1.8's "warning: multiple values
# for a block parameter" warnings
Pry::Helpers::BaseHelpers.silence_warnings do
@hooks[event_name].map do |hook_name, callable| @hooks[event_name].map do |hook_name, callable|
begin begin
callable.call(*args, &block) callable.call(*args, &block)
@ -158,7 +155,6 @@ class Pry
end end
end.last end.last
end end
end
# Return the number of hook functions registered for the `event_name` event. # Return the number of hook functions registered for the `event_name` event.
# @param [Symbol] event_name The name of the event. # @param [Symbol] event_name The name of the event.

View file

@ -405,8 +405,6 @@ class Pry
end end
# @return [Array<String>] All known aliases for the method. # @return [Array<String>] All known aliases for the method.
# @note On Ruby 1.8 this method always returns an empty Array for methods
# implemented in C.
def aliases def aliases
owner = @method.owner owner = @method.owner
# Avoid using `to_sym` on {Method#name}, which returns a `String`, because # Avoid using `to_sym` on {Method#name}, which returns a `String`, because

View file

@ -44,7 +44,8 @@ class Pry::Terminal
require 'io/console' require 'io/console'
$stdout.winsize if $stdout.tty? and $stdout.respond_to?(:winsize) $stdout.winsize if $stdout.tty? and $stdout.respond_to?(:winsize)
rescue LoadError rescue LoadError
# They're probably on 1.8 without the io-console gem. We'll keep trying. # They probably don't have the io/console stdlib or the io-console gem.
# We'll keep trying.
end end
def screen_size_according_to_env def screen_size_according_to_env

View file

@ -47,10 +47,6 @@ module PryTestHelpers
end end
end end
def mri18_and_no_real_source_location?
Pry::Helpers::BaseHelpers.mri_18? && !(Method.instance_method(:source_location).owner == Method)
end
# Open a temp file and yield it to the block, closing it after # Open a temp file and yield it to the block, closing it after
# @return [String] The path of the temp file # @return [String] The path of the temp file
def temp_file(ext='.rb') def temp_file(ext='.rb')

View file

@ -66,28 +66,12 @@ class Pry
end end
# Returns an array of the names of the constants accessible in the wrapped # Returns an array of the names of the constants accessible in the wrapped
# module. This provides a consistent interface between 1.8 and 1.9 and also # module. This avoids the problem of accidentally calling the singleton
# avoids the problem of accidentally calling the singleton method # method `Module.constants`.
# `Module.constants`.
# @param [Boolean] inherit Include the names of constants from included # @param [Boolean] inherit Include the names of constants from included
# modules? # modules?
def constants(inherit = true) def constants(inherit = true)
method = Module.instance_method(:constants).bind(@wrapped) Module.instance_method(:constants).bind(@wrapped).call(inherit)
# If we're on 1.8, we have to manually remove ancestors' constants. If
# we're on 1.9, though, it's better to use the built-in `inherit` param,
# since it doesn't do things like incorrectly remove Pry::Config.
if method.arity == 0
consts = method.call
if !inherit
ancestors_ = Pry::Method.safe_send(@wrapped, :ancestors)
consts -= (ancestors_ - [@wrapped]).map(&:constants).flatten
end
else
consts = method.call(inherit)
end
consts
end end
# The prefix that would appear before methods defined on this class. # The prefix that would appear before methods defined on this class.
@ -259,7 +243,7 @@ class Pry
# @return [Enumerator, Array] on JRuby 1.9 and higher returns Array, on # @return [Enumerator, Array] on JRuby 1.9 and higher returns Array, on
# other rubies returns Enumerator # other rubies returns Enumerator
def candidates def candidates
enum = generator.new do |y| enum = Enumerator.new do |y|
(0...number_of_candidates).each do |num| (0...number_of_candidates).each do |num|
y.yield candidate(num) y.yield candidate(num)
end end
@ -292,18 +276,6 @@ class Pry
private private
# Ruby 1.8 doesn't support `Enumerator` (it's called Generator instead)
#
# @return [Object] Return the appropriate generator class.
def generator
@generator ||= if defined?(Enumerator)
Enumerator
else
require 'generator'
Generator
end
end
# @return [Pry::WrappedModule::Candidate] The candidate with the # @return [Pry::WrappedModule::Candidate] The candidate with the
# highest rank, that is the 'monkey patch' of this module with the # highest rank, that is the 'monkey patch' of this module with the
# highest number of methods, which contains a source code line that # highest number of methods, which contains a source code line that

View file

@ -664,11 +664,9 @@ describe "Pry::Command" do
pry_eval('my---test').should =~ /my-testmy-test/ pry_eval('my---test').should =~ /my-testmy-test/
end end
if !mri18_and_no_real_source_location?
it "shows the source of the process method" do it "shows the source of the process method" do
pry_eval('show-source my-test').should =~ /output.puts command_name/ pry_eval('show-source my-test').should =~ /output.puts command_name/
end end
end
describe "command options hash" do describe "command options hash" do
it "is always present" do it "is always present" do

View file

@ -1,11 +1,5 @@
require 'helper' require 'helper'
# we turn off the test for MRI 1.8 because our source_location hack
# for C methods actually runs the methods - and since it runs ALL
# methods (in an attempt to find a match) it runs 'exit' and aborts
# the test, causing a failure. We should fix this in the future by
# blacklisting certain methods for 1.8 MRI (such as exit, fork, and so on)
unless Pry::Helpers::BaseHelpers.mri_18?
MyKlass = Class.new do MyKlass = Class.new do
def hello def hello
"timothy" "timothy"
@ -67,4 +61,3 @@ unless Pry::Helpers::BaseHelpers.mri_18?
end end
Object.remove_const(:MyKlass) Object.remove_const(:MyKlass)
end

View file

@ -1,7 +1,6 @@
require 'helper' require 'helper'
describe "gem-list" do describe "gem-list" do
# fixing bug for 1.8 compat
it 'should not raise when invoked' do it 'should not raise when invoked' do
proc { proc {
pry_eval(self, 'gem-list') pry_eval(self, 'gem-list')

View file

@ -34,7 +34,6 @@ describe "ls" do
end end
end end
if defined?(BasicObject)
describe "BasicObject" do describe "BasicObject" do
it "should work on BasicObject" do it "should work on BasicObject" do
pry_eval("ls BasicObject.new").should =~ /BasicObject#methods:.*__send__/m pry_eval("ls BasicObject.new").should =~ /BasicObject#methods:.*__send__/m
@ -47,7 +46,6 @@ describe "ls" do
).should =~ /LessBasic#methods:.*jaroussky/m ).should =~ /LessBasic#methods:.*jaroussky/m
end end
end end
end
describe "methods" do describe "methods" do
it "should show public methods by default" do it "should show public methods by default" do

View file

@ -1,7 +1,6 @@
require 'helper' require 'helper'
require "fixtures/show_source_doc_examples" require "fixtures/show_source_doc_examples"
if !PryTestHelpers.mri18_and_no_real_source_location?
describe "show-doc" do describe "show-doc" do
before do before do
@o = Object.new @o = Object.new
@ -243,7 +242,6 @@ if !PryTestHelpers.mri18_and_no_real_source_location?
end end
end end
if !Pry::Helpers::BaseHelpers.mri_18?
describe "in REPL" do describe "in REPL" do
it 'should find class defined in repl' do it 'should find class defined in repl' do
t = pry_tester t = pry_tester
@ -258,7 +256,6 @@ if !PryTestHelpers.mri18_and_no_real_source_location?
Object.remove_const :TobinaMyDog Object.remove_const :TobinaMyDog
end end
end end
end
it 'should lookup module name with respect to current context' do it 'should lookup module name with respect to current context' do
constant_scope(:AlphaClass, :BetaClass) do constant_scope(:AlphaClass, :BetaClass) do
@ -574,4 +571,3 @@ if !PryTestHelpers.mri18_and_no_real_source_location?
end end
end end
end end
end

View file

@ -1,7 +1,6 @@
require 'helper' require 'helper'
require "fixtures/show_source_doc_examples" require "fixtures/show_source_doc_examples"
if !PryTestHelpers.mri18_and_no_real_source_location?
describe "show-source" do describe "show-source" do
before do before do
@o = Object.new @o = Object.new
@ -131,9 +130,6 @@ if !PryTestHelpers.mri18_and_no_real_source_location?
}.should.raise(Pry::CommandError).message.should =~ /No superclass found/ }.should.raise(Pry::CommandError).message.should =~ /No superclass found/
end end
# dynamically defined method source retrieval is only supported in
# 1.9 - where Method#source_location is native
if RUBY_VERSION =~ /1.9/
it "should output the source of a method defined inside Pry" do it "should output the source of a method defined inside Pry" do
out = pry_eval("def dyn_method\n:test\nend", 'show-source dyn_method') out = pry_eval("def dyn_method\n:test\nend", 'show-source dyn_method')
out.should =~ /def dyn_method/ out.should =~ /def dyn_method/
@ -164,7 +160,6 @@ if !PryTestHelpers.mri18_and_no_real_source_location?
out.should =~ /what she said/ out.should =~ /what she said/
Pry.commands.delete "hubba-hubba" Pry.commands.delete "hubba-hubba"
end end
end
describe "finding super methods with help of `--super` switch" do describe "finding super methods with help of `--super` switch" do
before do before do
@ -218,14 +213,12 @@ if !PryTestHelpers.mri18_and_no_real_source_location?
end end
describe "on sourcable objects" do describe "on sourcable objects" do
if RUBY_VERSION =~ /1.9/
it "should output source defined inside pry" do it "should output source defined inside pry" do
pry_tester.tap do |t| pry_tester.tap do |t|
t.eval "hello = proc { puts 'hello world!' }" t.eval "hello = proc { puts 'hello world!' }"
t.eval("show-source hello").should =~ /proc \{ puts/ t.eval("show-source hello").should =~ /proc \{ puts/
end end
end end
end
it "should output source for procs/lambdas stored in variables" do it "should output source for procs/lambdas stored in variables" do
hello = proc { puts 'hello world!' } hello = proc { puts 'hello world!' }
@ -381,7 +374,6 @@ if !PryTestHelpers.mri18_and_no_real_source_location?
end end
end end
if !Pry::Helpers::BaseHelpers.mri_18?
before do before do
pry_eval unindent(<<-EOS) pry_eval unindent(<<-EOS)
class Dog class Dog
@ -410,7 +402,6 @@ if !PryTestHelpers.mri18_and_no_real_source_location?
pry_eval('show-source -s TobinaMyDog').should =~ /class Dog/ pry_eval('show-source -s TobinaMyDog').should =~ /class Dog/
end end
end end
end
it 'should lookup module name with respect to current context' do it 'should lookup module name with respect to current context' do
@ -815,4 +806,3 @@ if !PryTestHelpers.mri18_and_no_real_source_location?
end end
end end
end end
end

View file

@ -41,7 +41,6 @@ describe "whereami" do
Object.remove_const(:Cor) Object.remove_const(:Cor)
end end
if defined?(BasicObject)
it 'should work in BasicObjects' do it 'should work in BasicObjects' do
cor = Class.new(BasicObject) do cor = Class.new(BasicObject) do
def blimey! def blimey!
@ -51,7 +50,6 @@ describe "whereami" do
pry_eval(cor, 'whereami').should =~ /::Kernel.binding [#] omnom/ pry_eval(cor, 'whereami').should =~ /::Kernel.binding [#] omnom/
end end
end
it 'should show description and correct code when __LINE__ and __FILE__ are outside @method.source_location' do it 'should show description and correct code when __LINE__ and __FILE__ are outside @method.source_location' do
class Cor class Cor

View file

@ -144,7 +144,8 @@ describe Pry::Method do
m.name.should == "gag" m.name.should == "gag"
end end
if defined?(BasicObject) && !Pry::Helpers::BaseHelpers.rbx? # rubinius issue 1921 # Temporarily disabled to work around rubinius/rubinius#2871.
unless Pry::Helpers::BaseHelpers.rbx?
it "should find the right method from a BasicObject" do it "should find the right method from a BasicObject" do
a = Class.new(BasicObject) { def gag; ::Kernel.binding; end; def self.line; __LINE__; end } a = Class.new(BasicObject) { def gag; ::Kernel.binding; end; def self.line; __LINE__; end }
@ -433,8 +434,8 @@ describe Pry::Method do
it "should include the Pry::Method.instance_resolution_order of Class after the singleton classes" do it "should include the Pry::Method.instance_resolution_order of Class after the singleton classes" do
Pry::Method.resolution_order(LS::Top).should == Pry::Method.resolution_order(LS::Top).should ==
[singleton_class(LS::Top), singleton_class(Object), (defined? BasicObject) && singleton_class(BasicObject)].compact + [singleton_class(LS::Top), singleton_class(Object), singleton_class(BasicObject),
Pry::Method.instance_resolution_order(Class) *Pry::Method.instance_resolution_order(Class)]
end end
end end
end end
@ -496,8 +497,6 @@ describe Pry::Method do
end end
end end
unless Pry::Helpers::BaseHelpers.mri_18?
# Ruby 1.8 doesn't support this feature.
it 'should be able to find aliases for methods implemented in C' do it 'should be able to find aliases for methods implemented in C' do
meth = Pry::Method(Hash.new.method(:key?)) meth = Pry::Method(Hash.new.method(:key?))
aliases = Set.new(meth.aliases) aliases = Set.new(meth.aliases)
@ -505,6 +504,4 @@ describe Pry::Method do
aliases.should == Set.new(["include?", "member?", "has_key?"]) aliases.should == Set.new(["include?", "member?", "has_key?"])
end end
end end
end
end end

View file

@ -5,16 +5,12 @@ describe Pry do
@str_output = StringIO.new @str_output = StringIO.new
end end
if RUBY_VERSION =~ /1.9/
describe "Exotic object support" do describe "Exotic object support" do
# regression test for exotic object support # regression test for exotic object support
it "Should not error when return value is a BasicObject instance" do it "Should not error when return value is a BasicObject instance" do
ReplTester.start do ReplTester.start do
input('BasicObject.new').should =~ /^=> #<BasicObject:/ input('BasicObject.new').should =~ /^=> #<BasicObject:/
end end
end
end end
end end
@ -89,12 +85,10 @@ describe Pry do
}.should.raise(NameError) }.should.raise(NameError)
end end
if defined?(BasicObject)
it 'should be able to operate inside the BasicObject class' do it 'should be able to operate inside the BasicObject class' do
pry_eval(BasicObject, ":foo", "Pad.obj = _") pry_eval(BasicObject, ":foo", "Pad.obj = _")
Pad.obj.should == :foo Pad.obj.should == :foo
end end
end
it 'should set an ivar on an object' do it 'should set an ivar on an object' do
o = Object.new o = Object.new
@ -325,9 +319,8 @@ describe Pry do
end end
it 'should define a method on the class of an object when performing "def meth;end" inside an immediate value or Numeric' do it 'should define a method on the class of an object when performing "def meth;end" inside an immediate value or Numeric' do
# should include float in here, but test fails for some reason [:test, 0, true, false, nil,
# on 1.8.7, no idea why! (0.0 unless Pry::Helpers::BaseHelpers.jruby?)].each do |val|
[:test, 0, true, false, nil].each do |val|
pry_eval(val, "def hello; end"); pry_eval(val, "def hello; end");
val.class.instance_methods(false).map(&:to_sym).include?(:hello).should == true val.class.instance_methods(false).map(&:to_sym).include?(:hello).should == true
end end

View file

@ -15,11 +15,9 @@ describe "Pry.run_command" do
out.string.should =~ /hokey_pokey/ out.string.should =~ /hokey_pokey/
end end
if !PryTestHelpers.mri18_and_no_real_source_location?
# This is a regression test as 0.9.11 broke this behaviour # This is a regression test as 0.9.11 broke this behaviour
it 'can perform a show-source' do it 'can perform a show-source' do
Pry.run_command "show-source drum", :context => @context, :output => out = StringIO.new Pry.run_command "show-source drum", :context => @context, :output => out = StringIO.new
out.string.should =~ /roken is dodelijk/ out.string.should =~ /roken is dodelijk/
end end
end end
end