class HighLine::Simulate
Simulates Highline input for use in tests.
Public Class Methods
Source
# File lib/highline/simulate.rb, line 19 def initialize(strings) @strings = strings end
Creates a simulator with an array of Strings as a script @param strings [Array<String>] preloaded string to be used
as input buffer when simulating.
Source
# File lib/highline/simulate.rb, line 51 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
A wrapper method that temporarily replaces the Highline instance in HighLine.default_instance
with an instance of this object for the duration of the block
@param strings [String] preloaded string buffer that
will feed the input operations when simulating.
Public Instance Methods
Source
# File lib/highline/simulate.rb, line 40 def eof? false end
The simulator handles its own EOF
Source
# File lib/highline/simulate.rb, line 30 def getbyte line = gets return if line.empty? char = line.slice! 0 @strings.unshift line char end
Simulate
StringIO#getbyte by shifting a single character off of the next line of the script