Module: InputsTTYMethods

Defined in:
lib/clir/TTY-Prompt.cls.rb

Overview

Tests methods for TTY::Prompt

Each method of TTY::Prompt owns its own method in this module so it can respond to Q.<method> and return the ‘inputs’ defined in CLITests for user interaction.

Defined Under Namespace

Classes: CLiTestNoMoreValuesError, Responder

Instance Method Summary collapse

Instance Method Details

#ask(*args, &block) ⇒ Object



185
186
187
# File 'lib/clir/TTY-Prompt.cls.rb', line 185

def ask(*args, &block)
  response_of('ask', *args, &block)
end

#inputsObject

In test mode, return fake-user inputs (keyboard inputs)



157
158
159
160
161
162
163
164
165
166
167
# File 'lib/clir/TTY-Prompt.cls.rb', line 157

def inputs
  @inputs ||= begin
    if ENV['CLI_TEST_INPUTS']
      JSON.parse ENV['CLI_TEST_INPUTS']
    elsif CLI::Replayer.inputs
      CLI::Replayer.inputs
    else
      []
    end
  end
end

#multi_select(*args, &block) ⇒ Object



200
201
202
# File 'lib/clir/TTY-Prompt.cls.rb', line 200

def multi_select(*args, &block)
  response_of('multi_select', *args, &block)
end

#multiline(*args, &block) ⇒ Object



194
195
196
# File 'lib/clir/TTY-Prompt.cls.rb', line 194

def multiline(*args, &block)
  response_of('multiline', *args, &block)
end

#next_inputObject

value to return.

Returns:

  • next fake-user input or raise a error if no more



173
174
175
176
177
178
179
# File 'lib/clir/TTY-Prompt.cls.rb', line 173

def next_input
  if inputs.any?
    inputs.shift
  else
    raise CLiTestNoMoreValuesError
  end
end

#no?(*args, &block) ⇒ Boolean

Returns:

  • (Boolean)


191
192
193
# File 'lib/clir/TTY-Prompt.cls.rb', line 191

def no?(*args, &block)
  response_of('no', *args, &block)
end

#response_of(type, *args, &block) ⇒ Object



181
182
183
# File 'lib/clir/TTY-Prompt.cls.rb', line 181

def response_of(type, *args, &block)
  Responder.new(self, type, *args, &block).response
end

#select(*args, &block) ⇒ Object



197
198
199
# File 'lib/clir/TTY-Prompt.cls.rb', line 197

def select(*args, &block)
  response_of('select', *args, &block)
end

#slider(*args, &block) ⇒ Object



203
204
205
# File 'lib/clir/TTY-Prompt.cls.rb', line 203

def slider(*args, &block)
  response_of('slider', *args, &block)
end

#yes?(*args, &block) ⇒ Boolean

Returns:

  • (Boolean)


188
189
190
# File 'lib/clir/TTY-Prompt.cls.rb', line 188

def yes?(*args, &block)
  response_of('yes', *args, &block)
end