mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Refactor Pry.toplevel_binding to allow reset during tests
This commit is contained in:
parent
ba0d052584
commit
ced328d38a
2 changed files with 30 additions and 10 deletions
|
@ -390,16 +390,23 @@ class Pry
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
# Grab a copy of the TOPLEVEL_BINDING without any local variables.
|
def self.toplevel_binding
|
||||||
# This binding has a default definee of Object, and new methods are
|
unless @toplevel_binding
|
||||||
# private (just as in TOPLEVEL_BINDING).
|
# Grab a copy of the TOPLEVEL_BINDING without any local variables.
|
||||||
def self.__pry__
|
# This binding has a default definee of Object, and new methods are
|
||||||
|
# private (just as in TOPLEVEL_BINDING).
|
||||||
|
TOPLEVEL_BINDING.eval <<-RUBY
|
||||||
|
def self.__pry__
|
||||||
binding
|
binding
|
||||||
|
end
|
||||||
|
Pry.toplevel_binding = __pry__
|
||||||
|
class << self; undef __pry__; end
|
||||||
|
RUBY
|
||||||
|
end
|
||||||
|
@toplevel_binding.eval('private')
|
||||||
|
@toplevel_binding
|
||||||
|
end
|
||||||
end
|
end
|
||||||
Pry.toplevel_binding = __pry__
|
|
||||||
Pry.toplevel_binding.eval("private")
|
|
||||||
class << self; undef __pry__; end
|
|
||||||
|
|
||||||
Pry.init
|
Pry.init
|
||||||
|
|
|
@ -49,6 +49,17 @@ module Bacon
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Reset toplevel binding at the beginning of each test case.
|
||||||
|
module Bacon
|
||||||
|
class Context
|
||||||
|
alias _real_it it
|
||||||
|
def it(description, &block)
|
||||||
|
Pry.toplevel_binding = nil
|
||||||
|
_real_it(description, &block)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# A global space for storing temporary state during tests.
|
# A global space for storing temporary state during tests.
|
||||||
Pad = OpenStruct.new
|
Pad = OpenStruct.new
|
||||||
def Pad.clear
|
def Pad.clear
|
||||||
|
@ -269,7 +280,9 @@ class PryTester
|
||||||
@pry = Pry.new(options)
|
@pry = Pry.new(options)
|
||||||
|
|
||||||
if context
|
if context
|
||||||
@pry.binding_stack << Pry.binding_for(context)
|
target = Pry.binding_for(context)
|
||||||
|
@pry.binding_stack << target
|
||||||
|
@pry.inject_sticky_locals(target)
|
||||||
end
|
end
|
||||||
|
|
||||||
@pry.input_array << nil # TODO: shouldn't need this
|
@pry.input_array << nil # TODO: shouldn't need this
|
||||||
|
|
Loading…
Reference in a new issue