Class: Clack::Testing::KeyQueue

Inherits:
Object
  • Object
show all
Defined in:
lib/clack/testing.rb

Overview

A StringIO-like object that feeds keys from a queue. Passed as the input: parameter to prompts for testing.

Instance Method Summary collapse

Constructor Details

#initialize(keys) ⇒ KeyQueue

Returns a new instance of KeyQueue.



111
112
113
114
# File 'lib/clack/testing.rb', line 111

def initialize(keys)
  @keys = keys
  @read_count = 0
end

Instance Method Details

#getcObject



116
117
118
119
120
121
# File 'lib/clack/testing.rb', line 116

def getc
  @read_count += 1
  raise "Too many reads (#{@read_count}) - possible infinite loop in test" if @read_count > 100

  @keys.shift || KEYS[:enter]
end

#tty?Boolean

Not a real TTY

Returns:

  • (Boolean)


124
# File 'lib/clack/testing.rb', line 124

def tty? = false