module Output
Represents output handlers for test results and messages.
Nested
Definitions
def self.github_actions?(env)
Detect if we're running in GitHub Actions, where human-readable output is preferred. GitHub Actions sets the GITHUB_ACTIONS environment variable to "true".
Signature
-
parameter
envHash The environment variables to check.
Implementation
def self.github_actions?(env)
env["GITHUB_ACTIONS"] == "true"
end
def self.for(io, env = ENV)
Create an appropriate output handler for the given IO.
Signature
-
parameter
ioIO The IO object to write to.
-
parameter
envHash The environment variables to consider (defaults to ENV).
-
returns
XTerm, Text An XTerm handler if the IO is a TTY or running in GitHub Actions, otherwise a Text handler.
Implementation
def self.for(io, env = ENV)
if io.isatty or self.github_actions?(env)
XTerm.new(io)
else
Text.new(io)
end
end
def self.default(io = $stderr, env = ENV)
Create a default output handler with styling configured.
Signature
-
parameter
ioIO The IO object to write to (defaults to $stderr).
-
parameter
envHash The environment variables to consider (defaults to ENV).
-
returns
XTerm, Text A configured output handler.
Implementation
def self.default(io = $stderr, env = ENV)
output = self.for(io, env)
Output::Bar.register(output)
output[:context] = output.style(nil, nil, :bold)
output[:describe] = output.style(:cyan)
output[:it] = output.style(:cyan)
output[:with] = output.style(:cyan)
output[:variable] = output.style(:blue, nil, :bold)
# The ellipsis marks where an inspected value was truncated; it is shown
# faintly so it reads as "trailing off" without competing with the value.
output[:ellipsis] = output.style(nil, nil, :faint)
output[:path] = output.style(:yellow)
output[:line] = output.style(:yellow)
output[:identity] = output.style(:yellow)
output[:passed] = output.style(:green)
output[:failed] = output.style(:red)
output[:deferred] = output.style(:yellow)
output[:skipped] = output.style(:blue)
output[:errored] = output.style(:red)
# output[:inform] = output.style(nil, nil, :bold)
return output
end
def self.buffered
Create a buffered output handler.
Signature
-
returns
Buffered A new buffered output handler.
Implementation
def self.buffered
Buffered.new
end