mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
ReplTester API changes; add failing spec
This commit is contained in:
parent
f82cd1535e
commit
4edafaee0f
2 changed files with 54 additions and 18 deletions
|
@ -9,13 +9,11 @@ class ReplTester
|
|||
end
|
||||
end
|
||||
|
||||
def self.start
|
||||
def self.start(&block)
|
||||
redirect_pry_io Input.new, StringIO.new do
|
||||
instance = new
|
||||
|
||||
yield instance
|
||||
instance.in "exit-all"
|
||||
raise "REPL didn't die" if instance.fiber.alive?
|
||||
instance.instance_eval(&block)
|
||||
instance.ensure_exit
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -32,7 +30,7 @@ class ReplTester
|
|||
@fiber.resume
|
||||
end
|
||||
|
||||
def in(input)
|
||||
def input(input)
|
||||
Pry.output.send(:initialize) # reset StringIO
|
||||
@fiber.resume(input)
|
||||
end
|
||||
|
@ -41,7 +39,20 @@ class ReplTester
|
|||
match.should === @pry.select_prompt
|
||||
end
|
||||
|
||||
def out(match)
|
||||
def output(match)
|
||||
match.should === Pry.output.string.chomp
|
||||
end
|
||||
|
||||
def ensure_exit
|
||||
if @should_exit_naturally
|
||||
fiber.should.not.be.alive
|
||||
else
|
||||
input "exit-all"
|
||||
raise "REPL didn't die" if fiber.alive?
|
||||
end
|
||||
end
|
||||
|
||||
def assert_exited
|
||||
@should_exit_naturally = true
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,20 +13,45 @@ describe "The REPL" do
|
|||
mock_pry("def a", "!", "5").should =~ /Input buffer cleared/
|
||||
end
|
||||
|
||||
it "shouldn't break if we start a nested session" do
|
||||
ReplTester.start do |t|
|
||||
t.in 'Pry::REPL.new(_pry_, :target => 10).start'
|
||||
t.out ''
|
||||
t.prompt /10.*> $/
|
||||
describe "eval_string and binding_stack" do
|
||||
it "shouldn't break if we start a nested session" do
|
||||
ReplTester.start do
|
||||
input 'Pry::REPL.new(_pry_, :target => 10).start'
|
||||
output ''
|
||||
prompt /10.*> $/
|
||||
|
||||
t.in 'self'
|
||||
t.out '=> 10'
|
||||
input 'self'
|
||||
output '=> 10'
|
||||
|
||||
t.in nil
|
||||
t.out ''
|
||||
input nil # Ctrl-D
|
||||
output ''
|
||||
|
||||
t.in 'self'
|
||||
t.out '=> main'
|
||||
input 'self'
|
||||
output '=> main'
|
||||
end
|
||||
end
|
||||
|
||||
it "shouldn't break if we pop bindings in Ruby" do
|
||||
ReplTester.start do
|
||||
input 'cd 10'
|
||||
output ''
|
||||
prompt /10.*> $/
|
||||
|
||||
input '_pry_.binding_stack.pop'
|
||||
output /^=> #<Binding/
|
||||
prompt /main.*> $/
|
||||
|
||||
input '_pry_.binding_stack.pop'
|
||||
output /^=> #<Binding/
|
||||
assert_exited
|
||||
end
|
||||
end
|
||||
|
||||
it "should immediately evaluate if eval_string is complete" do
|
||||
ReplTester.start do
|
||||
input '_pry_.eval_string = "10"'
|
||||
output '=> 10'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue