Class: Printer
- Inherits:
-
Object
- Object
- Printer
- Defined in:
- lib/helpers/printer.rb
Class Method Summary collapse
-
.fail(message) ⇒ Object
Prints a neutral message in red.
-
.neutral(message) ⇒ Object
Prints a neutral message in gray.
-
.pass(message) ⇒ Object
Prints a message in green to the console.
-
.summary(total, successes, failures, neutrals) ⇒ Object
Generates a summary message based on the total number of tests, the number of successful tests, the number of failed tests, and the number of neutral tests.
Class Method Details
.fail(message) ⇒ Object
Prints a neutral message in red.
Params:
-
message: The error message to be displayed.
Returns: None
22 23 24 |
# File 'lib/helpers/printer.rb', line 22 def self.fail() puts "\x1B[31m#{}\x1B[0m" end |
.neutral(message) ⇒ Object
Prints a neutral message in gray.
Parameters:
-
message: A string representing the message to be printed.
Returns: None
32 33 34 |
# File 'lib/helpers/printer.rb', line 32 def self.neutral() puts "\x1B[90m#{}\x1B[0m" end |
.pass(message) ⇒ Object
Prints a message in green to the console.
Parameters:
-
message: A string message to be printed.
Returns: None
11 12 13 |
# File 'lib/helpers/printer.rb', line 11 def self.pass() puts "\x1B[32m#{}\x1B[0m" end |
.summary(total, successes, failures, neutrals) ⇒ Object
Generates a summary message based on the total number of tests, the number of successful tests, the number of failed tests, and the number of neutral tests. The summary message is formatted as a box with the following structure:
-
Summary: ——————-
| | | $total tests ran. | | - $successes passed. | | - $failures failed. | | - $neutrals skipped/inconclusive. |
Parameters:
-
total (int): The total number of tests.
-
successes (int): The number of successful tests.
-
failures (int): The number of failed tests.
-
neutrals (int): The number of neutral tests.
Returns:
-
message (str): The formatted summary message.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/helpers/printer.rb', line 56 def self.summary(total, successes, failures, neutrals) total_char_count = total.to_s.length success_char_count = successes.to_s.length failure_char_count = failures.to_s.length neutral_char_count = neutrals.to_s.length max_char_count = [total_char_count, success_char_count, failure_char_count, neutral_char_count].max base_top_dash_spacer = 18 base_blank_spacer = 28 base_total_spacer = 14 base_success_spacer = 15 base_failure_spacer = 15 base_neutral_spacer = 1 box_length = 29 total_extra_space = max_char_count - total_char_count + base_total_spacer success_extra_space = max_char_count - success_char_count + base_success_spacer failure_extra_space = max_char_count - failure_char_count + base_failure_spacer neutral_extra_space = max_char_count - neutral_char_count + base_neutral_spacer # There are only two fields that might realistically overflow the box # - total and neutrals. Since total will always be >= passed and failed # count, we can just look at total and push out the space from there. all_extra_space = 0 if neutral_extra_space == max_char_count && max_char_count > base_neutral_spacer all_extra_space = max_char_count - base_neutral_spacer elsif total_extra_space == max_char_count && max_char_count > base_total_spacer all_extra_space = max_char_count - base_total_spacer end # Create a box that looks like this: # - Summary: ------------------- # | | # | $total tests ran. | # | - $successes passed. | # | - $failures failed. | # | - $neutrals skipped/inconclusive. | # ------------------------------- = "\n" += ' - Summary: ' (base_top_dash_spacer + all_extra_space).times do += '-' end += "\n" # | | (blank spacer line) += '|' (base_blank_spacer + all_extra_space).times do += ' ' end += "|\n" # | $total tests ran. | += "| #{total} tests ran." (total_extra_space + all_extra_space).times do += ' ' end += "|\n" # | - $successes passed. | += "| - #{successes} passed." (success_extra_space + all_extra_space).times do += ' ' end += "|\n" # | - $failures failed. | += "| - #{failures} failed." (failure_extra_space + all_extra_space).times do += ' ' end += "|\n" # | - $neutrals skipped/inconclusive. | += "| - #{neutrals} skipped/inconclusive." (neutral_extra_space + all_extra_space).times do += ' ' end += "|\n" # ------------------------------- (box_length + all_extra_space).times do += '-' end += "\n" end |