mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Add unit tests for DEFAULT_CONTROL_D_HANDLER
DEFAULT_CONTROL_D_HANDLER handles a user's Control-D (^D) presses. Add unit tests for ^D presses. Note that this commit doesn't include unit tests for the situation when ^D is being pressed in an expression[1]. [1]: Example of the untested situation: % pry [1] pry(main)> class Foo [1] pry(main)* ^D [2] pry(main)> Signed-off-by: Kyrylo Silin <kyrylosilin@gmail.com>
This commit is contained in:
parent
6ae24abd5b
commit
80112d24bb
2 changed files with 46 additions and 1 deletions
|
@ -106,7 +106,7 @@ class Pry
|
||||||
# clear input buffer
|
# clear input buffer
|
||||||
eval_string.replace("")
|
eval_string.replace("")
|
||||||
elsif _pry_.binding_stack.one?
|
elsif _pry_.binding_stack.one?
|
||||||
# ^D at top-level breaks out of loop
|
# ^D at top-level breaks out of a REPL loop
|
||||||
_pry_.binding_stack.clear
|
_pry_.binding_stack.clear
|
||||||
throw(:breakout)
|
throw(:breakout)
|
||||||
else
|
else
|
||||||
|
|
45
test/test_control_d_handler.rb
Normal file
45
test/test_control_d_handler.rb
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
require 'helper'
|
||||||
|
|
||||||
|
describe Pry::DEFAULT_CONTROL_D_HANDLER do
|
||||||
|
describe 'control-d press' do
|
||||||
|
before do
|
||||||
|
@control_d = "Pry::DEFAULT_CONTROL_D_HANDLER.call('', _pry_)"
|
||||||
|
@binding_stack = "self.binding_stack = _pry_.binding_stack.dup"
|
||||||
|
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 = nil
|
||||||
|
redirect_pry_io(InputTester.new(@control_d)) do
|
||||||
|
instance = Pry.new
|
||||||
|
instance.repl
|
||||||
|
end
|
||||||
|
|
||||||
|
instance.binding_stack.should.be.empty
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'in a nested session' do
|
||||||
|
it 'should pop last binding from the binding stack' do
|
||||||
|
base = OpenStruct.new
|
||||||
|
base.obj = OpenStruct.new
|
||||||
|
|
||||||
|
redirect_pry_io(InputTester.new("cd obj", "self.stack_size = _pry_.binding_stack.size",
|
||||||
|
@control_d, "self.stack_size = _pry_.binding_stack.size", "exit-all")) do
|
||||||
|
Pry.start(base)
|
||||||
|
end
|
||||||
|
|
||||||
|
base.obj.stack_size.should == 2
|
||||||
|
base.stack_size.should == 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue