1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

Add integration tester, failing spec

This commit is contained in:
Ryan Fitzgerald 2012-12-23 00:03:29 -08:00
parent 00939762c4
commit 6ee0f4a32b
3 changed files with 65 additions and 0 deletions

View file

@ -8,6 +8,7 @@ require 'mocha/api'
require 'pry/test/helper' require 'pry/test/helper'
require 'helpers/bacon' require 'helpers/bacon'
require 'helpers/mock_pry' require 'helpers/mock_pry'
require 'helpers/repl_tester'
class Module class Module
public :remove_const public :remove_const

View file

@ -0,0 +1,47 @@
# This is for super-high-level integration testing.
require 'fiber'
class ReplTester
class Input
def readline(prompt)
Fiber.yield(prompt)
end
end
def self.start
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?
end
end
attr_accessor :pry, :repl, :fiber
def initialize
@pry = Pry.new
@repl = Pry::REPL.new(:pry => @pry)
@fiber = Fiber.new do
@repl.start
end
@fiber.resume
end
def in(input)
Pry.output.send(:initialize) # reset StringIO
@fiber.resume(input)
end
def prompt(match)
match.should === @pry.select_prompt
end
def out(match)
match.should === Pry.output.string.chomp
end
end

View file

@ -12,4 +12,21 @@ describe "The REPL" do
it "should let you run commands in the middle of multiline expressions" do it "should let you run commands in the middle of multiline expressions" do
mock_pry("def a", "!", "5").should =~ /Input buffer cleared/ mock_pry("def a", "!", "5").should =~ /Input buffer cleared/
end end
it "shouldn't break if we start a nested session" do
ReplTester.start do |t|
t.in 'Pry::REPL.start(:pry => _pry_, :target => 10)'
t.out ''
t.prompt /10.*> $/
t.in 'self'
t.out '=> 10'
t.in nil
t.out ''
t.in 'self'
t.out '=> main'
end
end
end end