2014-03-14 00:31:24 -04:00
|
|
|
require_relative 'helper'
|
2012-06-16 14:12:10 -04:00
|
|
|
|
|
|
|
describe Pry::DEFAULT_CONTROL_D_HANDLER do
|
2012-12-14 20:23:24 -05:00
|
|
|
|
|
|
|
describe "control-d press" do
|
|
|
|
|
2012-06-16 14:12:10 -04:00
|
|
|
before do
|
2012-12-14 20:23:24 -05:00
|
|
|
# Simulates a ^D press.
|
2012-06-16 14:12:10 -04:00
|
|
|
@control_d = "Pry::DEFAULT_CONTROL_D_HANDLER.call('', _pry_)"
|
|
|
|
end
|
|
|
|
|
2012-12-14 20:23:24 -05:00
|
|
|
describe "in an expression" do
|
|
|
|
it "should clear out passed string" do
|
|
|
|
str = 'hello world'
|
2012-06-16 14:12:10 -04:00
|
|
|
Pry::DEFAULT_CONTROL_D_HANDLER.call(str, nil)
|
2012-12-14 20:23:24 -05:00
|
|
|
str.should == ''
|
2012-06-16 14:12:10 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'at top-level session' do
|
|
|
|
it 'should break out of a REPL loop' do
|
2012-12-20 04:28:04 -05:00
|
|
|
instance = Pry.new
|
|
|
|
instance.binding_stack.should.not.be.empty
|
2012-12-28 01:06:50 -05:00
|
|
|
instance.eval(nil).should.be.false
|
2012-06-16 14:12:10 -04:00
|
|
|
instance.binding_stack.should.be.empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'in a nested session' do
|
|
|
|
it 'should pop last binding from the binding stack' do
|
2012-12-20 04:28:04 -05:00
|
|
|
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
|
2012-12-20 04:28:04 -05:00
|
|
|
t.eval("_pry_.binding_stack.size").should == 1
|
2012-06-16 14:12:10 -04:00
|
|
|
end
|
|
|
|
|
2012-12-14 20:23:24 -05:00
|
|
|
it "breaks out of the parent session" do
|
2012-12-28 13:00:33 -05:00
|
|
|
ReplTester.start do
|
|
|
|
input 'Pry::REPL.new(_pry_, :target => 10).start'
|
|
|
|
output ''
|
|
|
|
prompt(/10.*> $/)
|
|
|
|
|
|
|
|
input 'self'
|
|
|
|
output '=> 10'
|
|
|
|
|
|
|
|
input nil # Ctrl-D
|
|
|
|
output ''
|
|
|
|
|
|
|
|
input 'self'
|
|
|
|
output '=> main'
|
|
|
|
|
|
|
|
input nil # Ctrl-D
|
|
|
|
output '=> nil' # Exit value of nested REPL.
|
|
|
|
assert_exited
|
2012-06-16 14:12:10 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-12-14 20:23:24 -05:00
|
|
|
|
2012-06-16 14:12:10 -04:00
|
|
|
end
|
2012-12-14 20:23:24 -05:00
|
|
|
|
2012-06-16 14:12:10 -04:00
|
|
|
end
|