SusSourceSusOutputMessages

module Messages

Provides message formatting methods for output handlers.

Definitions

PASSED_PREFIX = [:passed, "✓ "].freeze

The prefix for passed assertions.

FAILED_PREFIX = [:failed, "✗ "].freeze

The prefix for failed assertions.

def pass_prefix(orientation)

Get the prefix for a passed assertion based on orientation.

Signature

parameter orientation Boolean

The orientation of the assertions.

returns Array

The prefix array.

Implementation

def pass_prefix(orientation)
	if orientation
		PASSED_PREFIX
	else
		FAILED_PREFIX
	end
end

def fail_prefix(orientation)

Get the prefix for a failed assertion based on orientation.

Signature

parameter orientation Boolean

The orientation of the assertions.

returns Array

The prefix array.

Implementation

def fail_prefix(orientation)
	if orientation
		FAILED_PREFIX
	else
		PASSED_PREFIX
	end
end

def assert(condition, orientation, message, backtrace)

Print an assertion result. If the orientation is true, and the test passed, then it is a successful outcome. If the orientation is false, and the test failed, then it is a successful outcome. Otherwise, it is a failed outcome.

Signature

parameter condition Boolean

The result of the test.

parameter orientation Boolean

The orientation of the assertions.

parameter message String

The message to display.

parameter backtrace Backtrace

The backtrace to display.

Implementation

def assert(condition, orientation, message, backtrace)
	if condition
		self.puts(:indent, *pass_prefix(orientation), message, backtrace)
	else
		self.puts(:indent, *fail_prefix(orientation), message, backtrace)
	end
end

def skip_prefix

Signature

returns String

The prefix for skipped tests.

Implementation

def skip_prefix
	"⏸ "
end

def skip(reason, identity)

Print a skip message.

Signature

parameter reason String

The reason for skipping.

parameter identity Identity, nil

The identity where the skip occurred.

Implementation

def skip(reason, identity)
	self.puts(:indent, :skipped, skip_prefix, reason)
end

def error_prefix

Signature

returns Array

The prefix for error messages.

Implementation

def error_prefix
	[:errored, "⚠ "]
end

def error(error, identity, prefix = error_prefix)

Print an error message.

Signature

parameter error Exception

The error to display.

parameter identity Identity, nil

The identity where the error occurred.

parameter prefix Array

Optional prefix to use.

Implementation

def error(error, identity, prefix = error_prefix)
	lines = error.message.split(/\r?\n/)
	
	self.puts(:indent, *prefix, error.class, ": ", lines.shift)
	
	lines.each do |line|
		self.puts(:indent, line)
	end
	
	self.write(Output::Backtrace.for(error, identity))
	
	if cause = error.cause
		self.error(cause, identity, ["Caused by ", :errored])
	end
end

def inform_prefix

Signature

returns String

The prefix for informational messages.

Implementation

def inform_prefix
	"ℹ "
end

def inform(message, identity)

Print an informational message.

Signature

parameter message String

The message to display.

parameter identity Identity, nil

The identity where the message was generated.

Implementation

def inform(message, identity)
	self.puts(:indent, :inform, inform_prefix, message)
end