Skip to content

Commit b2dd1a8

Browse files
pftgclaude
andcommitted
fix: use Minitest.after_run for report summary, not at_exit
Root cause: at_exit hooks run in LIFO order. Our at_exit was registered after minitest's autorun, so it fired before tests finished — reporter had total=0 because no assertions had been processed yet. Fix: Use Minitest.after_run (runs after all tests complete) when minitest is available, falling back to at_exit for RSpec/Cucumber. Also remove screenshots&.clear from verify_screenshots! ensure block — clearing now happens in registry.reset after notify_reporters, so assertions are available for the reporter before being cleared. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent d7153ab commit b2dd1a8

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

lib/capybara_screenshot_diff/reporters/html.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def write_report
136136
CapybaraScreenshotDiff.reporters << CapybaraScreenshotDiff::Reporters::HTML.new(embed_images: !!ENV["CI"])
137137
end
138138

139-
at_exit do
139+
snap_diff_finalize = proc do
140140
CapybaraScreenshotDiff.reporters_mutex.synchronize { CapybaraScreenshotDiff.reporters.dup }.each do |reporter|
141141
reporter.finalize
142142
if (msg = reporter.summary)
@@ -146,3 +146,9 @@ def write_report
146146
warn "[snap_diff] Reporter #{reporter.class} failed (#{e.class}: #{e.message})"
147147
end
148148
end
149+
150+
if defined?(Minitest) && Minitest.respond_to?(:after_run)
151+
Minitest.after_run(&snap_diff_finalize)
152+
else
153+
at_exit(&snap_diff_finalize)
154+
end

lib/capybara_screenshot_diff/screenshot_assertion.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ def self.verify_screenshots!(screenshots)
4141
test_screenshot_errors.compact!
4242

4343
test_screenshot_errors.empty? ? nil : test_screenshot_errors
44-
ensure
45-
screenshots&.clear
4644
end
4745

4846
# Asserts that an image has not changed compared to its baseline.

0 commit comments

Comments
 (0)