Skip to content

Commit 974eeaf

Browse files
pftgclaude
andcommitted
refactor: remove external_at_exit flag, rely on @Finalized guard
The external_at_exit flag was overkill — @Finalized in #finalize already prevents double work. Simpler: at_exit always registers, framework adapters also register native hooks, @Finalized ensures only the first call does work. Also move custom framework docs from README to docs/framework-setup.md. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent ddbf51e commit 974eeaf

7 files changed

Lines changed: 14 additions & 26 deletions

File tree

README.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -194,17 +194,6 @@ Comparisons add ~50ms per image with VIPS. Without `ruby-vips`, ChunkyPNG is use
194194
`DEBUG=1 bundle exec rake test` keeps `.diff.png` files for inspection.
195195
</details>
196196

197-
## Custom Test Frameworks
198-
199-
Minitest, RSpec, and Cucumber are supported out of the box. For other frameworks, call `finalize_reporters!` after all tests complete:
200-
201-
```ruby
202-
# In your framework's "after suite" hook:
203-
CapybaraScreenshotDiff.finalize_reporters!
204-
```
205-
206-
This generates the HTML report and prints the summary. Without this call, the gem falls back to `at_exit` which may fire before your tests finish.
207-
208197
## Installation
209198

210199
**Requirements:** Ruby 3.2+. Rails 7.1+ for Rails integration; non-Rails projects supported via `CapybaraScreenshotDiff.serve()`. For the `:vips` driver: [libvips 8.9+](https://libvips.github.io/libvips/install.html). On macOS: `brew install vips`. On Ubuntu: `apt-get install libvips-dev`.

docs/framework-setup.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,14 @@ Then('I should not see any visual difference') do
7474
end
7575
```
7676

77+
## Custom Test Frameworks
78+
79+
Minitest, RSpec, and Cucumber are supported out of the box. For other frameworks, call `finalize_reporters!` in your framework's "after suite" hook:
80+
81+
```ruby
82+
CapybaraScreenshotDiff.finalize_reporters!
83+
```
84+
85+
This generates the HTML report and prints the summary. Without this call, the gem falls back to `at_exit` which may not fire at the right time depending on your framework's boot order.
86+
7787
[← Back to README](../README.md)

lib/capybara_screenshot_diff/cucumber.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@
99
Capybara::Screenshot::BrowserHelpers.resize_window_if_needed
1010
end
1111

12-
CapybaraScreenshotDiff.external_at_exit = true
1312
AfterAll { CapybaraScreenshotDiff.finalize_reporters! }

lib/capybara_screenshot_diff/minitest.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,4 @@ def before_teardown
4848
end
4949
end
5050

51-
if ::Minitest.respond_to?(:after_run)
52-
CapybaraScreenshotDiff.external_at_exit = true
53-
::Minitest.after_run { CapybaraScreenshotDiff.finalize_reporters! }
54-
end
51+
::Minitest.after_run { CapybaraScreenshotDiff.finalize_reporters! } if ::Minitest.respond_to?(:after_run)

lib/capybara_screenshot_diff/reporters/html.rb

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

139-
# Register at_exit as fallback for frameworks without explicit adapters.
140-
# Framework adapters (Minitest, RSpec, Cucumber) set external_at_exit = true
141-
# and call finalize_reporters! via native hooks for correct ordering.
142-
at_exit do
143-
next if CapybaraScreenshotDiff.external_at_exit?
144-
CapybaraScreenshotDiff.finalize_reporters!
145-
end
139+
# Safety net for all frameworks. Framework adapters also call finalize_reporters!
140+
# via native hooks for correct ordering. The @finalized guard prevents double work.
141+
at_exit { CapybaraScreenshotDiff.finalize_reporters! }

lib/capybara_screenshot_diff/rspec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,5 @@
4242
end
4343
end
4444

45-
CapybaraScreenshotDiff.external_at_exit = true
4645
config.after(:suite) { CapybaraScreenshotDiff.finalize_reporters! }
4746
end

lib/capybara_screenshot_diff/screenshot_assertion.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,6 @@ def reporters
130130
end
131131

132132
attr_reader :reporters_mutex
133-
attr_accessor :external_at_exit
134-
alias_method :external_at_exit?, :external_at_exit
135133

136134
def finalize_reporters!
137135
reporters_mutex.synchronize { reporters.dup }.each do |reporter|

0 commit comments

Comments
 (0)