Module: Sus::Output::Messages
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
-
#assert(condition, orientation, message, backtrace) ⇒ Object
Print an assertion result.
-
#error(error, identity, prefix = error_prefix) ⇒ Object
Print an error message.
- #error_prefix ⇒ Object
-
#fail_prefix(orientation) ⇒ Object
Get the prefix for a failed assertion based on orientation.
-
#inform(message, identity) ⇒ Object
Print an informational message.
- #inform_prefix ⇒ Object
-
#pass_prefix(orientation) ⇒ Object
Get the prefix for a passed assertion based on orientation.
-
#skip(reason, identity) ⇒ Object
Print a skip message.
- #skip_prefix ⇒ Object
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, , backtrace) if condition self.puts(:indent, *pass_prefix(orientation), , backtrace) else self.puts(:indent, *fail_prefix(orientation), , 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..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_prefix ⇒ Object
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(, identity) self.puts(:indent, :inform, inform_prefix, ) end |
#inform_prefix ⇒ Object
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_prefix ⇒ Object
56 57 58 |
# File 'lib/sus/output/messages.rb', line 56 def skip_prefix "⏸ " end |