class TL1::TestIO

A simple IO-like object that accepts a hash of string inputs and corresponding outputs, useful for testing.

Public Class Methods

new(commands, first_output: '') click to toggle source
# File lib/tl1/test_io.rb, line 6
def initialize(commands, first_output: '')
  commands.each_pair do |input, output|
    next if output =~ COMPLD
    raise ArgumentError, "incomplete output for #{input}"
  end

  @commands = commands
  @next_output = first_output
end

Public Instance Methods

expect(pattern, _timeout = nil) click to toggle source
# File lib/tl1/test_io.rb, line 16
def expect(pattern, _timeout = nil)
  unless pattern =~ @next_output
    raise TimeoutError, 'pattern does not match the next output'
  end

  @next_output
end
write(message) click to toggle source
# File lib/tl1/test_io.rb, line 24
def write(message)
  @next_output = @commands.fetch(message)
  true
end