Skip to content

feat: always print summary after tests (like SimpleCov)#181

Merged
pftg merged 3 commits into
masterfrom
feat/always-print-report-summary
Apr 12, 2026
Merged

feat: always print summary after tests (like SimpleCov)#181
pftg merged 3 commits into
masterfrom
feat/always-print-report-summary

Conversation

@pftg

@pftg pftg commented Apr 12, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add #summary method to HTML reporter that prints after every test run
  • Follows SimpleCov pattern: always show status so devs know reporter is active

Output examples

[snap_diff] 47 screenshots compared, 2 failures. Report: doc/screenshots/snap_diff_report.html
[snap_diff] 47 screenshots compared, no failures.

When no screenshots are taken (reporter not used or disabled), nothing prints.

Context

In jetthoughts.github.io, after upgrading to v1.12.0 with the HTML reporter enabled, there was no visible output confirming the reporter was working. SimpleCov always prints Coverage report generated for ... to coverage/index.html regardless of pass/fail.

Test plan

  • 5 new tests for summary output (failures, pass, empty)
  • 223 unit tests pass

🤖 Generated with Claude Code

Summary by Sourcery

Add a summary output for the HTML reporter that always prints a concise test run status at exit.

New Features:

  • Introduce an HTML reporter summary method that reports screenshot counts, failure status, and report path.
  • Print a standardized snap_diff summary line after each run when the reporter is used.

Tests:

  • Add unit tests covering HTML reporter finalize return values and summary output for failing, passing, and empty runs.

Add `#summary` method to HTML reporter that prints screenshot count
and report path after every test run:
- "3 screenshots compared, 1 failure. Report: doc/screenshots/snap_diff_report.html"
- "5 screenshots compared, no failures."
- Nothing printed when no screenshots were taken

Follows the SimpleCov pattern: always show status so developers know
the reporter is active and where to find results.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Apr 12, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@pftg has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 4 minutes and 45 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 4 minutes and 45 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c87d6866-2404-47eb-92f7-6fec1b397a44

📥 Commits

Reviewing files that changed from the base of the PR and between f9ae0cf and 19572f6.

📒 Files selected for processing (2)
  • lib/capybara_screenshot_diff/reporters/html.rb
  • test/unit/reporters/html_reporter_test.rb
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/always-print-report-summary

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sourcery-ai

sourcery-ai Bot commented Apr 12, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Adds a reusable summary API to the HTML reporter and updates the at_exit hook to always print a concise test run summary (screenshots count, failures, and report path) after tests, along with tests to cover the new behavior and finalize return values.

Sequence diagram for at_exit HTML reporter summary printing

sequenceDiagram
  actor TestProcess
  participant AtExitHook
  participant ReportersRegistry as ReportersRegistry
  participant HTMLReporter as HTMLReporter
  participant Stdout as Stdout

  TestProcess->>AtExitHook: process exits
  AtExitHook->>ReportersRegistry: reporters = reporters.dup
  loop each reporter
    AtExitHook->>HTMLReporter: finalize()
    HTMLReporter-->>AtExitHook: finalize_complete
    AtExitHook->>HTMLReporter: summary()
    alt summary present
      HTMLReporter-->>AtExitHook: "[snap_diff] ..."
      AtExitHook->>Stdout: puts summary
    else no summary (total == 0)
      HTMLReporter-->>AtExitHook: nil
    end
  end
Loading

Class diagram for HTML reporter with summary API

classDiagram
  class CapybaraScreenshotDiff {
  }

  class ReportersRegistry {
    +Mutex reporters_mutex
    +Array reporters
  }

  class HTMLReporter {
    +Integer total
    +Array failures
    +Pathname output_path
    +Float success_rate()
    +String summary()
    +String render()
    +Pathname write_report()
    +void finalize()
  }

  class AtExitHook {
    +void run()
  }

  CapybaraScreenshotDiff --> ReportersRegistry : has
  ReportersRegistry --> HTMLReporter : manages
  AtExitHook --> ReportersRegistry : reads_reporters
  AtExitHook ..> HTMLReporter : calls_finalize
  AtExitHook ..> HTMLReporter : calls_summary
  AtExitHook ..> AtExitHook : writes_to_stdout
Loading

File-Level Changes

Change Details Files
Introduce a summary API on the HTML reporter that formats screenshot and failure counts into a single status line.
  • Add HTML#summary that returns nil when no screenshots were recorded
  • Format singular/plural for screenshot and failure labels and include report path only when there are failures
  • Align summary text with the intended CLI output format for snap_diff
lib/capybara_screenshot_diff/reporters/html.rb
Change reporter finalization behavior to always print the new summary instead of only printing the report path when failures exist.
  • Stop relying on HTML#finalize return value to signal report generation; finalize is now called for side effects only
  • Update at_exit hook to call reporter.summary and print it when present, gated by respond_to?(:summary)
  • Ensure no output is printed when no screenshots were recorded
lib/capybara_screenshot_diff/reporters/html.rb
Add unit tests to validate finalize return values and the new summary output behavior for different result scenarios.
  • Add tests asserting finalize returns Pathname when failures exist and nil when all pass
  • Add tests for summary content when there are failures, when all pass, and when no screenshots are recorded
  • Reuse existing helper methods to construct passing and failing assertions in tests
test/unit/reporters/html_reporter_test.rb

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • In the at_exit hook you call reporter.summary twice (puts reporter.summary if ... && reporter.summary); consider assigning it to a local variable to avoid duplicate work and ensure consistent output if the method ever gains side effects.
  • The summary string construction contains inline pluralization logic for both screenshots and failures; consider extracting a small helper (e.g., pluralize(count, singular, plural = nil)) to keep the method more readable and reduce duplication.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In the `at_exit` hook you call `reporter.summary` twice (`puts reporter.summary if ... && reporter.summary`); consider assigning it to a local variable to avoid duplicate work and ensure consistent output if the method ever gains side effects.
- The summary string construction contains inline pluralization logic for both screenshots and failures; consider extracting a small helper (e.g., `pluralize(count, singular, plural = nil)`) to keep the method more readable and reduce duplication.

## Individual Comments

### Comment 1
<location path="test/unit/reporters/html_reporter_test.rb" line_range="165-174" />
<code_context>
+        assert_nil result
+      end
+
+      test "#summary returns screenshot count and status" do
+        reporter = HTML.new(output_path: @output_path)
+        reporter.record([build_passing_assertion("ok"), build_failing_assertion("fail")])
+        reporter.finalize
+
+        summary = reporter.summary
+        assert_includes summary, "1 failure"
+        assert_includes summary, "2 screenshots"
+        assert_includes summary, @output_path.to_s
+      end
+
</code_context>
<issue_to_address>
**suggestion (testing):** Add a test case for pluralizing the failures label (e.g. "2 failures")

This test verifies the singular failure text and plural screenshots. To fully cover `summary`, please add another example with at least two failing assertions so the summary must include `"2 failures"`. That way both branches of the failures pluralization logic are tested and protected against regressions.

```suggestion
      test "#summary returns screenshot count and status" do
        reporter = HTML.new(output_path: @output_path)
        reporter.record([build_passing_assertion("ok"), build_failing_assertion("fail")])
        reporter.finalize

        summary = reporter.summary
        assert_includes summary, "1 failure"
        assert_includes summary, "2 screenshots"
        assert_includes summary, @output_path.to_s
      end

      test "#summary pluralizes failures label for multiple failures" do
        reporter = HTML.new(output_path: @output_path)
        reporter.record([
          build_failing_assertion("first failure"),
          build_failing_assertion("second failure")
        ])
        reporter.finalize

        summary = reporter.summary
        assert_includes summary, "2 failures"
        assert_includes summary, "2 screenshots"
        assert_includes summary, @output_path.to_s
      end
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread test/unit/reporters/html_reporter_test.rb
pftg and others added 2 commits April 13, 2026 00:02
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
- Fix double summary evaluation: assign to local variable (was called twice)
- Remove respond_to? guard: only HTML reporters exist, fail fast if not
- Always warn on reporter errors (was silenced unless DEBUG)
- Remove dead success_rate method (zero callers)
- Fix fragile test assertion: check output_path instead of string "report"

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@pftg pftg merged commit d7153ab into master Apr 12, 2026
8 checks passed
@pftg pftg deleted the feat/always-print-report-summary branch April 12, 2026 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant