Class: Zenspec::Formatters::ProgressFormatter

Inherits:
RSpec::Core::Formatters::BaseFormatter
  • Object
show all
Defined in:
lib/zenspec/formatters/progress_formatter.rb

Overview

RSpec formatter that displays test progress using Docker-style progress bar

Examples:

Usage

# In your .rspec file or command line:
--require zenspec/formatters/progress_formatter
--format Zenspec::Formatters::ProgressFormatter

Command line

rspec --require zenspec/formatters/progress_formatter \
      --format Zenspec::Formatters::ProgressFormatter

Instance Method Summary collapse

Constructor Details

#initialize(output) ⇒ ProgressFormatter

Returns a new instance of ProgressFormatter.



28
29
30
31
32
33
# File 'lib/zenspec/formatters/progress_formatter.rb', line 28

def initialize(output)
  super
  @loader = nil
  @failed_examples = []
  @pending_examples = []
end

Instance Method Details

#dump_failures(notification) ⇒ Object

Called to print failure details



84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/zenspec/formatters/progress_formatter.rb', line 84

def dump_failures(notification)
  return if notification.failed_examples.empty?

  output.puts
  output.puts "Failures:"
  output.puts

  notification.failed_examples.each_with_index do |example, index|
    output.puts "  #{index + 1}) #{example.full_description}"
    output.puts "     #{failure_message(example)}"
    output.puts "     # #{format_location(example)}"
    output.puts
  end
end

#dump_summary(summary) ⇒ Object

Called at the end to print summary



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/zenspec/formatters/progress_formatter.rb', line 68

def dump_summary(summary)
  @loader.finish(description: "Completed")

  output.puts
  output.puts summary_line(summary)

  return unless @pending_examples.any?

  output.puts
  output.puts "Pending examples:"
  @pending_examples.each do |example|
    output.puts "  #{example.full_description}"
  end
end

#example_failed(notification) ⇒ Object

Called when an example fails



56
57
58
59
# File 'lib/zenspec/formatters/progress_formatter.rb', line 56

def example_failed(notification)
  @failed_examples << notification.example
  @loader.increment(description: build_description(notification.example, ""))
end

#example_passed(notification) ⇒ Object

Called when an example passes



51
52
53
# File 'lib/zenspec/formatters/progress_formatter.rb', line 51

def example_passed(notification)
  @loader.increment(description: build_description(notification.example, ""))
end

#example_pending(notification) ⇒ Object

Called when an example is pending



62
63
64
65
# File 'lib/zenspec/formatters/progress_formatter.rb', line 62

def example_pending(notification)
  @pending_examples << notification.example
  @loader.increment(description: build_description(notification.example, "*"))
end

#example_started(_notification) ⇒ Object

Called when an example starts



46
47
48
# File 'lib/zenspec/formatters/progress_formatter.rb', line 46

def example_started(_notification)
  # Can add custom logic here if needed
end

#start(notification) ⇒ Object

Called at the start of the test suite



36
37
38
39
40
41
42
43
# File 'lib/zenspec/formatters/progress_formatter.rb', line 36

def start(notification)
  @total_count = notification.count
  @loader = ProgressLoader.new(
    total: @total_count,
    description: "Running examples",
    output: output
  )
end