Module: Sus::Output::Messages

Included in:
Null, Text
Defined in:
lib/sus/output/messages.rb

Overview

Provides message formatting methods for output handlers.

Constant Summary collapse

PASSED_PREFIX =

The prefix for passed assertions.

[:passed, ""].freeze
FAILED_PREFIX =

The prefix for failed assertions.

[:failed, ""].freeze

Instance Method Summary collapse

Instance Method Details

#assert(condition, orientation, message, backtrace) ⇒ Object

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.



47
48
49
50
51
52
53
# File 'lib/sus/output/messages.rb', line 47

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

#error(error, identity, prefix = error_prefix) ⇒ Object

Print an error message.



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/sus/output/messages.rb', line 76

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

#error_prefixObject



68
69
70
# File 'lib/sus/output/messages.rb', line 68

def error_prefix
	[:errored, ""]
end

#fail_prefix(orientation) ⇒ Object

Get the prefix for a failed assertion based on orientation.



30
31
32
33
34
35
36
# File 'lib/sus/output/messages.rb', line 30

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

#inform(message, identity) ⇒ Object

Print an informational message.



100
101
102
# File 'lib/sus/output/messages.rb', line 100

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

#inform_prefixObject



93
94
95
# File 'lib/sus/output/messages.rb', line 93

def inform_prefix
	""
end

#pass_prefix(orientation) ⇒ Object

Get the prefix for a passed assertion based on orientation.



19
20
21
22
23
24
25
# File 'lib/sus/output/messages.rb', line 19

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

#skip(reason, identity) ⇒ Object

Print a skip message.



63
64
65
# File 'lib/sus/output/messages.rb', line 63

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

#skip_prefixObject



56
57
58
# File 'lib/sus/output/messages.rb', line 56

def skip_prefix
	""
end