Method: Cucumber::Runtime::UserInterface#ask

Defined in:
lib/cucumber/runtime/user_interface.rb

#ask(question, timeout_seconds) ⇒ Object

Suspends execution and prompts question to the console (STDOUT). An operator (manual tester) can then enter a line of text and hit <ENTER>. The entered text is returned, and both question and the result is added to the output using #puts.

If you want a beep to happen (to grab the manual tester’s attention), just prepend ASCII character 7 to the question:

ask("#{7.chr}How many cukes are in the external system?")

If that doesn’t issue a beep, you can shell out to something else that makes a sound before invoking #ask.

[View source] [View on GitHub]

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/cucumber/runtime/user_interface.rb', line 23

def ask(question, timeout_seconds)
  $stdout.puts(question)
  $stdout.flush
  puts(question)

  answer = if Cucumber::JRUBY
             jruby_gets(timeout_seconds)
           else
             mri_gets(timeout_seconds)
           end

  raise("Waited for input for #{timeout_seconds} seconds, then timed out.") unless answer

  puts(answer)
  answer
end