module Cucumber::Runtime::UserInterface
def ask(question, timeout_seconds)
that makes a sound before invoking #ask.
If that doesn't issue a beep, you can shell out to something else
ask("#{7.chr}How many cukes are in the external system?")
just prepend ASCII character 7 to the question:
If you want a beep to happen (to grab the manual tester's attention),
the result is added to the output using #puts.
An operator (manual tester) can then enter a line of text and hit
Suspends execution and prompts +question+ to the console (STDOUT).
def ask(question, timeout_seconds) STDOUT.puts(question) STDOUT.flush puts(question) if(Cucumber::JRUBY) answer = jruby_gets(timeout_seconds) else answer = mri_gets(timeout_seconds) end if(answer) puts(answer) answer else raise("Waited for input for #{timeout_seconds} seconds, then timed out.") end end
def embed(src, mime_type, label)
The embedded data may or may not be ignored, depending on what kind of formatter(s) are active.
be a path to a file, or if it's an image it may also be a Base64 encoded image.
Embed +src+ of MIME type +mime_type+ into the output. The +src+ argument may
def embed(src, mime_type, label) @visitor.embed(src, mime_type, label) end
def jruby_gets(timeout_seconds)
def jruby_gets(timeout_seconds) answer = nil t = java.lang.Thread.new do answer = STDIN.gets end t.start t.join(timeout_seconds * 1000) answer end
def mri_gets(timeout_seconds)
def mri_gets(timeout_seconds) begin Timeout.timeout(timeout_seconds) do STDIN.gets end rescue Timeout::Error => e nil end end
def puts(*messages)
nicer, and in all outputs (in case you use several formatters)
This is an alternative to using Kernel#puts - it will display
Output +messages+ alongside the formatted output.
def puts(*messages) @visitor.puts(*messages) end