2012-06-16 14:12:10 -04:00
|
|
|
require 'helper'
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
2012-12-14 20:23:24 -05:00
|
|
|
describe "at top-level session" do
|
|
|
|
it "breaks out of a REPL" do
|
|
|
|
pry_tester(0).simulate_repl do |t|
|
|
|
|
t.eval @control_d
|
|
|
|
end.should == nil
|
2012-06-16 14:12:10 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-14 20:23:24 -05:00
|
|
|
describe "in a nested session" do
|
|
|
|
it "pops last binding from the binding stack" do
|
|
|
|
pry_tester(0).simulate_repl { |t|
|
|
|
|
t.eval 'cd :foo'
|
|
|
|
t.eval('_pry_.binding_stack.size').should == 2
|
|
|
|
t.eval(@control_d)
|
|
|
|
t.eval('_pry_.binding_stack.size').should == 1
|
|
|
|
t.eval 'exit-all'
|
|
|
|
}
|
|
|
|
end
|
2012-06-16 14:12:10 -04:00
|
|
|
|
2012-12-14 20:23:24 -05:00
|
|
|
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 @control_d
|
|
|
|
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'
|
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
|