mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Use a clean toplevel_binding by default.
This commit is contained in:
parent
ac68f843a3
commit
4af01cb3a5
3 changed files with 40 additions and 2 deletions
|
@ -131,7 +131,7 @@ Copyright (c) 2011 John Mair (banisterfiend)
|
|||
on(:c, :context,
|
||||
"Start the session in the specified context. Equivalent to `context.pry` in a session.",
|
||||
:argument => true,
|
||||
:default => "TOPLEVEL_BINDING"
|
||||
:default => "Pry.toplevel_binding"
|
||||
)
|
||||
end.process_options do |opts|
|
||||
# invoked via cli
|
||||
|
|
|
@ -46,6 +46,9 @@ class Pry
|
|||
# @return [Boolean] Whether Pry sessions are quiet by default.
|
||||
attr_accessor :quiet
|
||||
|
||||
# @return [Binding] A top level binding with no local variables
|
||||
attr_accessor :toplevel_binding
|
||||
|
||||
# plugin forwardables
|
||||
def_delegators :@plugin_manager, :plugins, :load_plugins, :locate_plugins
|
||||
|
||||
|
@ -105,7 +108,7 @@ class Pry
|
|||
# @option options (see Pry#initialize)
|
||||
# @example
|
||||
# Pry.start(Object.new, :input => MyInput.new)
|
||||
def self.start(target=TOPLEVEL_BINDING, options={})
|
||||
def self.start(target=toplevel_binding, options={})
|
||||
target = Pry.binding_for(target)
|
||||
initial_session_setup
|
||||
|
||||
|
@ -359,4 +362,14 @@ class Pry
|
|||
end
|
||||
end
|
||||
|
||||
# Grab a copy of the TOPLEVEL_BINDING without any local variables.
|
||||
# This binding has a default definee of Object, and new methods are
|
||||
# private (just as in TOPLEVEL_BINDING).
|
||||
def self.__binding_impl__
|
||||
binding
|
||||
end
|
||||
Pry.toplevel_binding = __binding_impl__
|
||||
Pry.toplevel_binding.eval("private")
|
||||
class << self; undef __binding_impl__; end
|
||||
|
||||
Pry.init
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
require 'helper'
|
||||
version = 1
|
||||
describe "test Pry defaults" do
|
||||
|
||||
after do
|
||||
|
@ -398,4 +399,28 @@ describe "test Pry defaults" do
|
|||
output.string.should == ""
|
||||
end
|
||||
end
|
||||
|
||||
describe 'toplevel_binding' do
|
||||
it 'should be devoid of local variables' do
|
||||
mock_pry(Pry.toplevel_binding, "ls -l").should.not =~ /version/
|
||||
|
||||
# https://github.com/rubinius/rubinius/issues/357
|
||||
unless Pry::Helpers::BaseHelpers.rbx?
|
||||
mock_pry(TOPLEVEL_BINDING, "ls -l").should =~ /version/
|
||||
end
|
||||
end
|
||||
|
||||
it 'should have self the same as TOPLEVEL_BINDING' do
|
||||
mock_pry(Pry.toplevel_binding, "self.equal? TOPLEVEL_BINDING.eval('self')").should =~ /=> true/
|
||||
end
|
||||
|
||||
# https://github.com/rubinius/rubinius/issues/1779
|
||||
unless Pry::Helpers::BaseHelpers.rbx?
|
||||
it 'should define private methods on Object' do
|
||||
mock_pry(TOPLEVEL_BINDING, "def gooey_fooey; end")
|
||||
method(:gooey_fooey).owner.should == Object
|
||||
Pry::Method(method(:gooey_fooey)).visibility.should == :private
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue