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
# inspect.
eig = class << obj; self; end
klass = Pry::Method.safe_send(eig, :ancestors).first
singleton = class << obj; self; end
ancestors = Pry::Method.safe_send(singleton, :ancestors)
klass = ancestors.reject { |k| k == singleton }.first
obj_id = obj.__id__.to_s(16) rescue 0
str = "#<#{klass}:0x#{obj_id}>"

View file

@ -6,8 +6,6 @@ class Pry
group 'Context'
description 'Recursively search for a method within a Class/Module or the current namespace.'
command_options :shellwords => false
command_options :requires_gem => 'ruby18_source_location' if mri_18?
banner <<-'BANNER'
Usage: find-method [-n|-c] METHOD [NAMESPACE]
@ -26,10 +24,6 @@ class Pry
find-method -c 'output.puts' Pry
BANNER
def setup
require 'ruby18_source_location' if mri_18?
end
def options(opti)
opti.on :n, :name, "Search for a method by name"
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
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)
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
if defined?(BasicObject)
class BasicObject
# Return a binding object for the receiver.
#
@ -124,12 +123,9 @@ if defined?(BasicObject)
#
# @return [Binding]
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
end
EOF
self.__pry__
end
end
end

View file

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

View file

@ -146,9 +146,6 @@ class Pry
def exec_hook(event_name, *args, &block)
@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|
begin
callable.call(*args, &block)
@ -158,7 +155,6 @@ class Pry
end
end.last
end
end
# Return the number of hook functions registered for the `event_name` event.
# @param [Symbol] event_name The name of the event.

View file

@ -405,8 +405,6 @@ class Pry
end
# @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
owner = @method.owner
# Avoid using `to_sym` on {Method#name}, which returns a `String`, because

View file

@ -44,7 +44,8 @@ class Pry::Terminal
require 'io/console'
$stdout.winsize if $stdout.tty? and $stdout.respond_to?(:winsize)
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
def screen_size_according_to_env

View file

@ -47,10 +47,6 @@ module PryTestHelpers
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
# @return [String] The path of the temp file
def temp_file(ext='.rb')

View file

@ -66,28 +66,12 @@ class Pry
end
# 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
# avoids the problem of accidentally calling the singleton method
# `Module.constants`.
# module. This avoids the problem of accidentally calling the singleton
# method `Module.constants`.
# @param [Boolean] inherit Include the names of constants from included
# modules?
def constants(inherit = true)
method = Module.instance_method(:constants).bind(@wrapped)
# 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
Module.instance_method(:constants).bind(@wrapped).call(inherit)
end
# 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
# other rubies returns Enumerator
def candidates
enum = generator.new do |y|
enum = Enumerator.new do |y|
(0...number_of_candidates).each do |num|
y.yield candidate(num)
end
@ -292,18 +276,6 @@ class Pry
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
# highest rank, that is the 'monkey patch' of this module with the
# 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/
end
if !mri18_and_no_real_source_location?
it "shows the source of the process method" do
pry_eval('show-source my-test').should =~ /output.puts command_name/
end
end
describe "command options hash" do
it "is always present" do

View file

@ -1,11 +1,5 @@
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
def hello
"timothy"
@ -67,4 +61,3 @@ unless Pry::Helpers::BaseHelpers.mri_18?
end
Object.remove_const(:MyKlass)
end

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -144,7 +144,8 @@ describe Pry::Method do
m.name.should == "gag"
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
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
Pry::Method.resolution_order(LS::Top).should ==
[singleton_class(LS::Top), singleton_class(Object), (defined? BasicObject) && singleton_class(BasicObject)].compact +
Pry::Method.instance_resolution_order(Class)
[singleton_class(LS::Top), singleton_class(Object), singleton_class(BasicObject),
*Pry::Method.instance_resolution_order(Class)]
end
end
end
@ -496,8 +497,6 @@ describe Pry::Method do
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
meth = Pry::Method(Hash.new.method(:key?))
aliases = Set.new(meth.aliases)
@ -505,6 +504,4 @@ describe Pry::Method do
aliases.should == Set.new(["include?", "member?", "has_key?"])
end
end
end
end

View file

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

View file

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