class HighLine::Simulate

Simulates Highline input for use in tests.

def self.with(*strings)

def self.with(*strings)
  @input = HighLine.default_instance.instance_variable_get :@input
  HighLine.default_instance.instance_variable_set :@input, new(strings)
  yield
ensure
  HighLine.default_instance.instance_variable_set :@input, @input
end

def eof?

The simulator handles its own EOF
def eof?
  false
end

def getbyte

the next line of the script
Simulate StringIO#getbyte by shifting a single character off of
def getbyte
  line = gets
  return if line.empty?
  char = line.slice! 0
  @strings.unshift line
  char
end

def gets

Simulate StringIO#gets by shifting a string off of the script
def gets
  @strings.shift
end

def initialize(strings)

Parameters:
  • strings (Array) -- preloaded string to be used
def initialize(strings)
  @strings = strings
end