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

57 lines
1.6 KiB
Ruby
Raw Normal View History

require 'helper'
describe Pry::DEFAULT_CONTROL_D_HANDLER do
describe "control-d press" do
before do
# Simulates a ^D press.
@control_d = "Pry::DEFAULT_CONTROL_D_HANDLER.call('', _pry_)"
end
describe "in an expression" do
it "should clear out passed string" do
str = 'hello world'
Pry::DEFAULT_CONTROL_D_HANDLER.call(str, nil)
str.should == ''
end
end
describe 'at top-level session' do
it 'should break out of a REPL loop' do
instance = Pry.new
instance.binding_stack.should.not.be.empty
2012-12-28 01:06:50 -05:00
instance.eval(nil).should.be.false
instance.binding_stack.should.be.empty
end
end
describe 'in a nested session' do
it 'should pop last binding from the binding stack' do
t = pry_tester
t.eval "cd Object.new"
t.eval("_pry_.binding_stack.size").should == 2
2012-12-28 01:06:50 -05:00
t.eval("_pry_.eval(nil)").should.be.true
t.eval("_pry_.binding_stack.size").should == 1
end
it "breaks out of the parent session" do
pry_tester(:outer).simulate_repl do |o|
o.context = :inner
o.simulate_repl { |i|
i.eval('_pry_.current_context.eval("self")').should == :inner
i.eval('_pry_.binding_stack.size').should == 2
i.eval('_pry_.eval(nil)')
i.eval('_pry_.binding_stack.size').should == 1
i.eval('_pry_.current_context.eval("self")').should == :outer
i.eval 'throw :breakout'
}
o.eval 'exit-all'
end
end
end
end
end