Module: Test::Unit::Util::Output
| Relationships & Source Files | |
| Extension / Inclusion / Inheritance Descendants | |
|
Included In:
| |
| Defined in: | lib/test/unit/util/output.rb |
Constant Summary
-
CAPTURE_MONITOR =
Internal use only
# File 'lib/test/unit/util/output.rb', line 55Monitor.new
Instance Method Summary
-
#capture_io
Alias for #capture_output.
-
#capture_output
(also: #capture_io)
Returns output for standard output and standard error as string.
-
#capture_output_monitor
private
See additional method definition at line 49.
Instance Method Details
#capture_io
Alias for #capture_output.
# File 'lib/test/unit/util/output.rb', line 42
alias_method :capture_io, :capture_output
#capture_output Also known as: #capture_io
Returns output for standard output and standard error as string.
Calls from multiple threads are serialized. Note that
output written by other threads while the block is
running is also captured. Don't call #capture_output in
another thread or fiber while the block is running. It
blocks or raises ThreadError.
Example:
capture_output do
puts("stdout")
warn("stderr")
end # -> ["stdout\n", "stderr\n"]
# File 'lib/test/unit/util/output.rb', line 23
def capture_output require "stringio" capture_output_monitor.synchronize do output = StringIO.new error = StringIO.new stdout_save, stderr_save = $stdout, $stderr $stdout, $stderr = output, error begin yield [output.string, error.string] ensure $stdout, $stderr = stdout_save, stderr_save end end end
#capture_output_monitor (private)
See additional method definition at line 49.
# File 'lib/test/unit/util/output.rb', line 56
def capture_output_monitor Ractor.store_if_absent(:test_unit_capture_output_monitor) do Monitor.new end end