1
0
Fork 0
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:
Ryan Fitzgerald 2012-10-13 21:00:36 +00:00
parent ba0d052584
commit ced328d38a
2 changed files with 30 additions and 10 deletions

View file

@ -390,16 +390,23 @@ class Pry
end
end
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.__pry__
def self.toplevel_binding
unless @toplevel_binding
# 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).
TOPLEVEL_BINDING.eval <<-RUBY
def self.__pry__
binding
end
Pry.toplevel_binding = __pry__
class << self; undef __pry__; end
RUBY
end
@toplevel_binding.eval('private')
@toplevel_binding
end
end
Pry.toplevel_binding = __pry__
Pry.toplevel_binding.eval("private")
class << self; undef __pry__; end
Pry.init

View file

@ -49,6 +49,17 @@ module Bacon
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.
Pad = OpenStruct.new
def Pad.clear
@ -269,7 +280,9 @@ class PryTester
@pry = Pry.new(options)
if context
@pry.binding_stack << Pry.binding_for(context)
target = Pry.binding_for(context)
@pry.binding_stack << target
@pry.inject_sticky_locals(target)
end
@pry.input_array << nil # TODO: shouldn't need this