Class: SpecForge::Forge::Display
- Inherits:
-
Object
- Object
- SpecForge::Forge::Display
- Defined in:
- lib/spec_forge/forge/display.rb
Overview
Handles formatted output for forge execution
Display manages the console output during test runs, adapting its verbosity based on the configured level (0-3). It formats step headers, action indicators, expectation results, and failure summaries.
Constant Summary collapse
- LINE_LENGTH =
Maximum line length for output formatting
120
Instance Attribute Summary collapse
-
#verbosity_level ⇒ Integer
readonly
Current verbosity level (0-3).
Instance Method Summary collapse
-
#action(message, **options) ⇒ void
Displays an action message with optional symbol indicator.
-
#blueprint_end(blueprint, success: true) ⇒ void
Called when a blueprint finishes execution.
-
#blueprint_start(blueprint) ⇒ void
Called when a blueprint begins execution.
-
#default_mode? ⇒ Boolean
Returns whether display is in default (minimal) mode.
-
#empty_line ⇒ void
Outputs a blank line for visual separation.
-
#expectation_failed(message, indent: 0) ⇒ void
Displays a failing expectation indicator (red F).
-
#expectation_finished(failed_examples:, total_count:, index: 0, show_index: false) ⇒ void
Displays the result summary for a completed expectation.
-
#expectation_passed(message, indent: 0) ⇒ void
Displays a passing expectation indicator (green dot).
-
#forge_end(forge) ⇒ void
Called when the entire forge run completes.
-
#forge_start(forge) ⇒ void
Called when the forge run begins.
-
#initialize(verbosity_level: 0) ⇒ Display
constructor
Creates a new display handler with the specified verbosity level.
-
#max_verbose? ⇒ Boolean
Returns whether display is in maximum verbose (trace) mode.
-
#stats(forge) ⇒ void
Displays final statistics and any failures from the forge run.
-
#step_end(forge, step, error: nil) ⇒ void
Called when a step finishes execution.
-
#step_start(step) ⇒ void
Called when a step begins execution.
-
#verbose? ⇒ Boolean
Returns whether display is in verbose mode or higher.
-
#very_verbose? ⇒ Boolean
Returns whether display is in very verbose (debug) mode or higher.
Constructor Details
#initialize(verbosity_level: 0) ⇒ Display
Creates a new display handler with the specified verbosity level
29 30 31 32 |
# File 'lib/spec_forge/forge/display.rb', line 29 def initialize(verbosity_level: 0) @verbosity_level = verbosity_level || 0 @color = Pastel.new end |
Instance Attribute Details
#verbosity_level ⇒ Integer (readonly)
Returns Current verbosity level (0-3).
20 21 22 |
# File 'lib/spec_forge/forge/display.rb', line 20 def verbosity_level @verbosity_level end |
Instance Method Details
#action(message, **options) ⇒ void
This method returns an undefined value.
Displays an action message with optional symbol indicator
Only shown when verbosity is above default (0). Used to indicate step actions like callbacks, requests, and store operations.
90 91 92 93 94 |
# File 'lib/spec_forge/forge/display.rb', line 90 def action(, **) return if default_mode? puts format(, indent: 1, **) end |
#blueprint_end(blueprint, success: true) ⇒ void
This method returns an undefined value.
Called when a blueprint finishes execution
286 287 288 289 290 291 292 293 294 295 296 297 298 |
# File 'lib/spec_forge/forge/display.rb', line 286 def blueprint_end(blueprint, success: true) return if default_mode? style = success ? :bright_green : :bright_red visual_length = "[#{blueprint.name}] Cleanup".size line = "#{@color.decorate("[#{blueprint.name}]", style)} Cleanup" length = LINE_LENGTH - visual_length filler = @color.decorate("━" * length, style) puts "#{line} #{filler}" end |
#blueprint_start(blueprint) ⇒ void
This method returns an undefined value.
Called when a blueprint begins execution
Displays a header line with the blueprint name. Only shown in verbose modes.
200 201 202 203 204 205 206 207 208 |
# File 'lib/spec_forge/forge/display.rb', line 200 def blueprint_start(blueprint) return if default_mode? visual_length = "[#{blueprint.name}] Setup".size line = "#{@color.bright_blue("[#{blueprint.name}]")} Setup" filler = @color.bright_blue("━" * (LINE_LENGTH - visual_length)) puts "#{line} #{filler}" end |
#default_mode? ⇒ Boolean
Returns whether display is in default (minimal) mode
39 40 41 |
# File 'lib/spec_forge/forge/display.rb', line 39 def default_mode? verbosity_level == 0 end |
#empty_line ⇒ void
This method returns an undefined value.
Outputs a blank line for visual separation
75 76 77 |
# File 'lib/spec_forge/forge/display.rb', line 75 def empty_line puts "" end |
#expectation_failed(message, indent: 0) ⇒ void
This method returns an undefined value.
Displays a failing expectation indicator (red F)
118 119 120 121 122 |
# File 'lib/spec_forge/forge/display.rb', line 118 def expectation_failed(, indent: 0) return if verbose? print @color.red("F") end |
#expectation_finished(failed_examples:, total_count:, index: 0, show_index: false) ⇒ void
This method returns an undefined value.
Displays the result summary for a completed expectation
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/spec_forge/forge/display.rb', line 134 def expectation_finished(failed_examples:, total_count:, index: 0, show_index: false) return if default_mode? failed_count = failed_examples.size print format_with_indent("#{index}: ", indent: 1) if show_index if failed_count == 0 action( "(#{total_count}/#{total_count} passed)", symbol: :success, symbol_styles: :green, indent: show_index ? 0 : 1 ) else action( "(#{failed_count}/#{total_count} failed)", symbol: :error, symbol_styles: :red, indent: show_index ? 0 : 1 ) end return if failed_examples.blank? puts "" failed_examples.each do |example| = example[:exception][:message].strip.prepend("\n") puts format_with_indent("#{example[:description]} #{@color.red()}", indent: 3) # puts JSON.pretty_generate(example[:exception][:backtrace]) # DEBUG puts "" end end |
#expectation_passed(message, indent: 0) ⇒ void
This method returns an undefined value.
Displays a passing expectation indicator (green dot)
104 105 106 107 108 |
# File 'lib/spec_forge/forge/display.rb', line 104 def expectation_passed(, indent: 0) return if verbose? print @color.green(".") end |
#forge_end(forge) ⇒ void
This method returns an undefined value.
Called when the entire forge run completes
307 308 309 310 311 312 313 314 |
# File 'lib/spec_forge/forge/display.rb', line 307 def forge_end(forge) return if default_mode? line = "#{@color.magenta("[forge]")} Quenched" filler = @color.magenta("━" * (LINE_LENGTH - 16)) puts "#{line} #{filler}" end |
#forge_start(forge) ⇒ void
This method returns an undefined value.
Called when the forge run begins
Displays a header line indicating the forge has started. Only shown in verbose modes.
181 182 183 184 185 186 187 188 |
# File 'lib/spec_forge/forge/display.rb', line 181 def forge_start(forge) return if default_mode? line = "#{@color.magenta("[forge]")} Ignited" filler = @color.magenta("━" * (LINE_LENGTH - 15)) # [forge] ignited puts "#{line} #{filler}" end |
#max_verbose? ⇒ Boolean
Returns whether display is in maximum verbose (trace) mode
66 67 68 |
# File 'lib/spec_forge/forge/display.rb', line 66 def max_verbose? verbosity_level >= 3 end |
#stats(forge) ⇒ void
This method returns an undefined value.
Displays final statistics and any failures from the forge run
Shows failure details (if any), summary counts for blueprints, steps, expectations, and failures, plus total execution time.
326 327 328 329 330 331 332 333 334 335 336 337 |
# File 'lib/spec_forge/forge/display.rb', line 326 def stats(forge) puts "" if forge.failures.size > 0 puts "Failures:\n\n" puts format_failures(forge.failures) end puts format_stats(forge) puts "" puts @color.dim("Finished in #{sprintf("%.2g", forge.timer.time_elapsed)}s") end |
#step_end(forge, step, error: nil) ⇒ void
This method returns an undefined value.
Called when a step finishes execution
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/spec_forge/forge/display.rb', line 256 def step_end(forge, step, error: nil) return unless verbose? puts "" if max_verbose? || (very_verbose? && error) indent = error ? 3 : 1 details = format_debug_details(forge, step, indent:) return if details.blank? if error puts format_with_indent(@color.red(error.), indent:) unless error.is_a?(Error::ExpectationFailure) puts "" puts format_with_indent(@color.dim("━" * (LINE_LENGTH * 0.75)), indent:) puts "" end puts details end end |
#step_start(step) ⇒ void
This method returns an undefined value.
Called when a step begins execution
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/spec_forge/forge/display.rb', line 217 def step_start(step) return if default_mode? line_number = step.source.line_number.to_s.rjust(2, "0") line = "#{step.source.file_name}:#{line_number}" if step.included_by.present? line_number = step.included_by.line_number.to_s.rjust(2, "0") line = "#{step.included_by.file_name}:#{line_number} → #{line}" end visual_length = line.size + 2 line = @color.cyan("[#{line}]") filler_size = LINE_LENGTH - visual_length # +1 offset to match forge/blueprint headers if step.name.present? name = step.name filler_size -= (name.size + 1) else name = @color.dim("(unnamed)") filler_size -= 10 # (unnamed) + 1 end filler = @color.cyan("━" * filler_size) puts "#{line} #{name} #{filler}" end |
#verbose? ⇒ Boolean
Returns whether display is in verbose mode or higher
48 49 50 |
# File 'lib/spec_forge/forge/display.rb', line 48 def verbose? verbosity_level >= 1 end |
#very_verbose? ⇒ Boolean
Returns whether display is in very verbose (debug) mode or higher
57 58 59 |
# File 'lib/spec_forge/forge/display.rb', line 57 def very_verbose? verbosity_level >= 2 end |