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

48 lines
797 B
Ruby
Raw Normal View History

2012-12-23 03:03:29 -05:00
# 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
2012-12-23 03:08:40 -05:00
@repl = Pry::REPL.new(@pry)
2012-12-23 03:03:29 -05:00
@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