Skip to content

Instantly share code, notes, and snippets.

@caseywatts
Created May 21, 2025 15:36
Show Gist options
  • Save caseywatts/241ab48f0aefa3ce1eec90fc6d953fce to your computer and use it in GitHub Desktop.
Save caseywatts/241ab48f0aefa3ce1eec90fc6d953fce to your computer and use it in GitHub Desktop.
Rspec custom formatter for CI

When looking at a running CI job, it's nice to see some progress occur so you know it's not stuck. Without this formatter, if you look at a running RSpec job, it looks stuck, because it doesn't display any output until it's run every test.

This formatter was created by a coworker, but I wanted to share this out in case it helps other folks!

# spec/wrapped_progress_formatter.rb
#
# Custom RSpec output formatter which hard wraps the output by printing a newline
# after every 40 examples.
#
# This is useful in environments (like GitHub Actions) which buffer output and do not display any
# progress until it sees a newline character. It is nice to see progress occur if you happen to be
# watching a job run.
class WrappedProgressFormatter < RSpec::Core::Formatters::ProgressFormatter
COLUMNS = 40
RSpec::Core::Formatters.register self, :example_finished
def example_finished(_notification)
@examples_run ||= 0
@examples_run += 1
return unless ((@examples_run - 1) % COLUMNS).zero?
output.puts
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment