1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00
pry--pry/test/test_input_stack.rb
Kyrylo Silin 8f3e4555ba Tidy up tests and remove some repeating code
Clean up repeating code on the subject of str_output variable. Fix
indentation in some files and restructure some tests, in order to
ease parsing of files by an eye.

Signed-off-by: Kyrylo Silin <kyrylosilin@gmail.com>
Signed-off-by: Yorick Peterse <yorickpeterse@gmail.com>
2012-06-11 19:33:04 +02:00

86 lines
2.9 KiB
Ruby

# coding: utf-8
require 'helper'
describe "Pry#input_stack" do
before do
@str_output = StringIO.new
end
it 'should accept :input_stack as a config option' do
stack = [StringIO.new("test")]
Pry.new(:input_stack => stack).input_stack.should == stack
end
it 'should use defaults from Pry.config' do
Pry.config.input_stack = [StringIO.new("exit")]
Pry.new.input_stack.should == Pry.config.input_stack
Pry.config.input_stack = []
end
it 'should read from all input objects on stack and exit session (usingn repl)' do
stack = [b = StringIO.new(":cloister\nexit\n"), c = StringIO.new(":baron\n")]
instance = Pry.new(:input => StringIO.new(":alex\n"),
:output => @str_output,
:input_stack => stack)
instance.repl
@str_output.string.should =~ /:alex/
@str_output.string.should =~ /:baron/
@str_output.string.should =~ /:cloister/
end
it 'input objects should be popped off stack as they are used up' do
stack = [StringIO.new(":cloister\n"), StringIO.new(":baron\n")]
instance = Pry.new(:input => StringIO.new(":alex\n"),
:output => @str_output,
:input_stack => stack)
stack.size.should == 2
instance.rep
@str_output.string.should =~ /:alex/
instance.rep
@str_output.string.should =~ /:baron/
stack.size.should == 1
instance.rep
@str_output.string.should =~ /:cloister/
stack.size.should == 0
end
it 'should revert to Pry.config.input when it runs out of input objects in input_stack' do
redirect_pry_io(StringIO.new(":rimbaud\nexit\n"), StringIO.new) do
stack = [StringIO.new(":cloister\n"), StringIO.new(":baron\n")]
instance = Pry.new(:input => StringIO.new(":alex\n"),
:output => @str_output,
:input_stack => stack)
instance.repl
@str_output.string.should =~ /:alex/
@str_output.string.should =~ /:baron/
@str_output.string.should =~ /:cloister/
@str_output.string.should =~ /:rimbaud/
end
end
it 'should display error and throw(:breakout) if at end of input after using up input_stack objects' do
catch(:breakout) do
redirect_pry_io(StringIO.new(":rimbaud\n"), @str_output) do
Pry.new(:input_stack => [StringIO.new(":a\n"), StringIO.new(":b\n")]).repl
end
end
@str_output.string.should =~ /Error: Pry ran out of things to read/
end
if "".respond_to?(:encoding)
it "should pass strings to Pry in the right encoding" do
input1 = "'f。。'.encoding.name" # utf-8, see coding declaration
input2 = input1.encode('Shift_JIS')
mock_pry(input1, input2).should == %{=> "UTF-8"\n=> "Shift_JIS"\n\n}
end
it "should be able to use unicode regexes on a UTF-8 terminal" do
mock_pry('":-Þ" =~ /þ/i').should == %{=> 2\n\n}
end
end
end