Skip to content

Commit b97f576

Browse files
pftgclaude
andcommitted
docs: add Non-Rails setup, GitHub Actions integration, animation tip
- Non-Rails section: Rack-based setup for Hugo/Jekyll/static sites - GitHub Actions: upload HTML report as artifact on failure - Troubleshooting: mention Capybara.disable_animation for CSS animations Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent ac6d4e0 commit b97f576

3 files changed

Lines changed: 78 additions & 1 deletion

File tree

README.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,41 @@ CapybaraScreenshotDiff.reporters << MyReporter.new
827827

828828
Reporters are notified before assertions are cleared on each test teardown. `finalize` is called via `at_exit`.
829829

830+
### Non-Rails Projects (Hugo, Jekyll, Static Sites)
831+
832+
```ruby
833+
# test/test_helper.rb
834+
require 'capybara_screenshot_diff/static'
835+
836+
CapybaraScreenshotDiff.serve("_site") # or "public", "build", "dist"
837+
```
838+
839+
This sets up Capybara to serve static files and configures screenshot paths automatically.
840+
841+
### GitHub Actions Integration
842+
843+
Upload the HTML report as a CI artifact so reviewers can browse screenshot diffs directly:
844+
845+
```yaml
846+
# .github/workflows/test.yml
847+
- name: Run tests
848+
run: bundle exec rake test
849+
850+
- name: Upload screenshot report
851+
if: failure()
852+
uses: actions/upload-artifact@v4
853+
with:
854+
name: screenshot-diffs
855+
path: tmp/snap_diff-report/
856+
retention-days: 7
857+
```
858+
859+
To enable the HTML report, add to your test helper:
860+
861+
```ruby
862+
require 'capybara_screenshot_diff/reporters/html'
863+
```
864+
830865
## Troubleshooting
831866

832867
**"No existing screenshot found"**
@@ -838,7 +873,8 @@ Font rendering varies across OS versions. Use `tolerance: 0.001` or `perceptual_
838873
to ignore sub-pixel differences. Set `window_size` to ensure consistent browser dimensions.
839874

840875
**Animations cause flaky diffs**
841-
Set `stability_time_limit: 1` to wait for the page to stabilize before capturing.
876+
Set `Capybara.disable_animation = true` in your test helper to disable CSS animations globally.
877+
For JS animations, add `stability_time_limit: 1` to wait for the page to stabilize.
842878
The gem takes multiple screenshots and compares them until two consecutive ones match.
843879

844880
**Dynamic content (timestamps, ads) always differs**
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
require "rack/files"
4+
require "capybara_screenshot_diff/minitest"
5+
6+
module CapybaraScreenshotDiff
7+
def self.serve(directory, root: Dir.pwd)
8+
Capybara.app = Rack::Files.new(directory)
9+
Capybara::Screenshot.root = root
10+
end
11+
end

test/unit/static_test.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# frozen_string_literal: true
2+
3+
require "test_helper"
4+
require "capybara_screenshot_diff/static"
5+
6+
module CapybaraScreenshotDiff
7+
class StaticTest < ActiveSupport::TestCase
8+
teardown do
9+
Capybara.app = Rails.application
10+
end
11+
12+
test ".serve sets Capybara.app to serve the directory" do
13+
CapybaraScreenshotDiff.serve("test/fixtures")
14+
15+
assert_kind_of Rack::Files, Capybara.app
16+
end
17+
18+
test ".serve sets Screenshot.root to pwd" do
19+
CapybaraScreenshotDiff.serve("test/fixtures")
20+
21+
assert_equal Pathname(Dir.pwd), Capybara::Screenshot.root
22+
end
23+
24+
test ".serve accepts custom root" do
25+
CapybaraScreenshotDiff.serve("test/fixtures", root: "/tmp")
26+
27+
assert_equal Pathname("/tmp"), Capybara::Screenshot.root
28+
end
29+
end
30+
end

0 commit comments

Comments
 (0)