Module: Cucumber::Runtime::UserInterface
- Included in:
- Cucumber::Runtime
- Defined in:
- lib/cucumber/runtime/user_interface.rb
Instance Attribute Summary collapse
-
#visitor ⇒ Object
writeonly
Sets the attribute visitor.
Instance Method Summary collapse
-
#announce(msg) ⇒ Object
Output
announcement
alongside the formatted output. -
#ask(question, timeout_seconds) ⇒ Object
Suspends execution and prompts
question
to the console (STDOUT). -
#embed(file, mime_type) ⇒ Object
Embed
file
of MIME typemime_type
into the output.
Instance Attribute Details
#visitor=(value) ⇒ Object (writeonly)
Sets the attribute visitor
7 8 9 |
# File 'lib/cucumber/runtime/user_interface.rb', line 7 def visitor=(value) @visitor = value end |
Instance Method Details
#announce(msg) ⇒ Object
Output announcement
alongside the formatted output. This is an alternative to using Kernel#puts - it will display nicer, and in all outputs (in case you use several formatters)
13 14 15 |
# File 'lib/cucumber/runtime/user_interface.rb', line 13 def announce(msg) msg.respond_to?(:join) ? @visitor.announce(msg.join("\n")) : @visitor.announce(msg.to_s) end |
#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 #announce.
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.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/cucumber/runtime/user_interface.rb', line 30 def ask(question, timeout_seconds) STDOUT.puts(question) STDOUT.flush announce(question) if(Cucumber::JRUBY) answer = jruby_gets(timeout_seconds) else answer = mri_gets(timeout_seconds) end if(answer) announce(answer) answer else raise("Waited for input for #{timeout_seconds} seconds, then timed out.") end end |
#embed(file, mime_type) ⇒ Object
Embed file
of MIME type mime_type
into the output. This may or may not be ignored, depending on what kind of formatter(s) are active.
52 53 54 |
# File 'lib/cucumber/runtime/user_interface.rb', line 52 def (file, mime_type) @visitor.(file, mime_type) end |