Module: Sus::Output

Defined in:
lib/sus/output.rb,
lib/sus/output/bar.rb,
lib/sus/output/null.rb,
lib/sus/output/text.rb,
lib/sus/output/lines.rb,
lib/sus/output/xterm.rb,
lib/sus/output/status.rb,
lib/sus/output/buffered.rb,
lib/sus/output/messages.rb,
lib/sus/output/progress.rb,
lib/sus/output/variable.rb,
lib/sus/output/backtrace.rb,
lib/sus/output/structured.rb

Overview

Represents output handlers for test results and messages.

Defined Under Namespace

Modules: Messages, Variable Classes: Backtrace, Bar, Buffered, Lines, Null, Progress, Status, Structured, Text, XTerm

Class Method Summary collapse

Class Method Details

.bufferedObject

Create a buffered output handler.



72
73
74
# File 'lib/sus/output.rb', line 72

def self.buffered
	Buffered.new
end

.default(io = $stderr, env = ENV) ⇒ Object

Create a default output handler with styling configured.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/sus/output.rb', line 39

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

.for(io, env = ENV) ⇒ Object

Create an appropriate output handler for the given IO.



27
28
29
30
31
32
33
# File 'lib/sus/output.rb', line 27

def self.for(io, env = ENV)
	if io.isatty or self.github_actions?(env)
		XTerm.new(io)
	else
		Text.new(io)
	end
end

.github_actions?(env) ⇒ Boolean

Detect if we’re running in GitHub Actions, where human-readable output is preferred. GitHub Actions sets the GITHUB_ACTIONS environment variable to “true”.

Returns:

  • (Boolean)


19
20
21
# File 'lib/sus/output.rb', line 19

def self.github_actions?(env)
	env["GITHUB_ACTIONS"] == "true"
end