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

Pry#binding_stack respected by :when_started hook

* If _pry_.binding_stack is set then binding_stack parameter (from :when_started) is ignored, even if it's modified.
* binding_stack parameter should eventually be removed altogther before 0.9.8 release, and people can use _pry_.binding_stack instead
This commit is contained in:
John Mair 2012-01-18 17:20:13 +13:00
parent 4dcb856aa2
commit 2827ded4a0
2 changed files with 56 additions and 2 deletions

View file

@ -123,8 +123,12 @@ class Pry
pry_instance
)
head, *tail = binding_stack
pry_instance.binding_stack.push(*tail)
if pry_instance.binding_stack.empty?
head, *tail = binding_stack
pry_instance.binding_stack.push(*tail)
else
head = pry_instance.binding_stack.pop
end
# Enter the matrix
pry_instance.repl(head)

View file

@ -320,6 +320,56 @@ describe Pry::Hooks do
Pry.config.hooks.delete_hook(:when_started, :test_hook)
end
it 'should allow overriding of target (and binding_stack)' do
options = nil
o = Object.new
class << o; attr_accessor :value; end
Pry.config.hooks.add_hook(:when_started, :test_hook) { |binding_stack, opt, _pry_| binding_stack.replace [Pry.binding_for(o)] }
redirect_pry_io(InputTester.new("@value = true","exit-all")) do
Pry.start binding, :hello => :baby
end
o.value.should == true
Pry.config.hooks.delete_hook(:when_started, :test_hook)
end
it 'should allow overriding of target (and binding_stack) via _pry_.binding_stack' do
options = nil
o = Object.new
class << o; attr_accessor :value; end
Pry.config.hooks.add_hook(:when_started, :test_hook) { |binding_stack, opt, _pry_| _pry_.binding_stack = [Pry.binding_for(o)] }
redirect_pry_io(InputTester.new("@value = true","exit-all")) do
Pry.start binding, :hello => :baby
end
o.value.should == true
Pry.config.hooks.delete_hook(:when_started, :test_hook)
end
it 'should give precedence to _pry_.binding_stack over binding_stack' do
options = nil
o = Object.new
class << o; attr_accessor :value; end
Pry.config.hooks.add_hook(:when_started, :test_hook) do |binding_stack, opt, _pry_|
_pry_.binding_stack = [Pry.binding_for(o)]
binding_stack.replace [Pry.binding_for(5)]
end
redirect_pry_io(InputTester.new("@value = true","exit-all")) do
Pry.start binding, :hello => :baby
end
o.value.should == true
Pry.config.hooks.delete_hook(:when_started, :test_hook)
end
end
describe "after_session hook" do