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:
parent
00939762c4
commit
6ee0f4a32b
3 changed files with 65 additions and 0 deletions
|
@ -8,6 +8,7 @@ require 'mocha/api'
|
|||
require 'pry/test/helper'
|
||||
require 'helpers/bacon'
|
||||
require 'helpers/mock_pry'
|
||||
require 'helpers/repl_tester'
|
||||
|
||||
class Module
|
||||
public :remove_const
|
||||
|
|
47
spec/helpers/repl_tester.rb
Normal file
47
spec/helpers/repl_tester.rb
Normal 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
|
|
@ -12,4 +12,21 @@ describe "The REPL" do
|
|||
it "should let you run commands in the middle of multiline expressions" 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.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
|
||||
|
|
Loading…
Reference in a new issue