capybara-screenshot-diff 1.12.0 → 1.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 163b89646e7610ebde81e77fb9f6ed8e81bb2fb74dce234846efcfbe9479ed2c
4
- data.tar.gz: 30e46f9caecc9c705ed19309a246c7ea9353c179635e5be38be5513e187c5fc7
3
+ metadata.gz: dba172cde687794eeedbffe4c4112d58ed5c4e2fcac5cdaf93b84827396e832d
4
+ data.tar.gz: a6b45b9bfc4ff349b506c7045f54392101c1bbfecda7b51475758fd2ee1536c0
5
5
  SHA512:
6
- metadata.gz: 7c58c2d084f4d052591d2f4bd1b4b983a9a933f5e4f4be8d1ef7683c8bc060ae9bf3d3deaaf381bb344ae6c21de723ee61e1fd54e30b825b5741b1f903509da2
7
- data.tar.gz: e879a7f5f9bc06ca083157fc7cc24a08a38b5419ddfd6ab2e0ef63f5e4379ca6f9e864bb21f869f7d9617b3514ca691d4f3af090a00ec3cc4adec3de5215e095
6
+ metadata.gz: afc332553b0bdafe8a47d82376b83b866bcd25144132f6e6ba481e41b03fd113ea74cf25f1decfcff8397664b1d4e2469abbfd21bebfde2a2c42f332ca0220dc
7
+ data.tar.gz: 1bd843fa71d17a0eac95bf1674a8d76352a8fe8c93c581840f9a50f63106edd40c5964b25ac36add805c6baf4129138e01aca5f73df30b34646fb1c2814adacd
data/CHANGELOG.md CHANGED
@@ -5,6 +5,35 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [v1.14.0] - 2026-08-22
9
+
10
+ ### Added
11
+ - **`SnapDiff` namespace aliases** — `SnapDiff::Comparison`, `SnapDiff.compare`, and `SnapDiff.start` provide a forward-looking entry point onto the existing `Capybara::Screenshot::Diff` API, no behavior changes ([#166](https://github.com/snap-diff/snap_diff-capybara/issues/166))
12
+
13
+ ### Fixed
14
+ - **Standalone require path** — `require "capybara_screenshot_diff"` (or `require "snap_diff"`) followed by `Diff.compare` no longer raises `NameError` for the missing drivers require ([#194](https://github.com/snap-diff/snap_diff-capybara/pull/194))
15
+
16
+ ### Internal
17
+ - Merged `DifferenceFinder` into `ImageCompare` (ADR-004 step) ([#192](https://github.com/snap-diff/snap_diff-capybara/pull/192))
18
+ - Extracted `AnnotationService` from `Reporters::Default`; full public surface preserved via delegation ([#193](https://github.com/snap-diff/snap_diff-capybara/pull/193))
19
+ - Consolidated `pending_if_new` teardown logic into one shared helper across Minitest/RSpec/Cucumber adapters ([#197](https://github.com/snap-diff/snap_diff-capybara/pull/197))
20
+ - Test-suite driver-coverage banner and CI guard against silently missing drivers ([#198](https://github.com/snap-diff/snap_diff-capybara/pull/198))
21
+
22
+ ---
23
+
24
+ ## [v1.13.0] - 2026-08-22
25
+
26
+ ### Added
27
+ - **`capture_screenshot` DSL method** — take a screenshot without ever comparing or asserting ([#191](https://github.com/snap-diff/snap_diff-capybara/issues/191))
28
+ - **`compare:` option on `screenshot`** — pass `compare: true` (default) to assert, or `compare: false` to capture only ([#191](https://github.com/snap-diff/snap_diff-capybara/issues/191))
29
+ - **`Capybara::Screenshot::Diff.pending_if_new` config** — mark tests as skipped in teardown when a baseline does not exist, complementing `fail_if_new` ([#191](https://github.com/snap-diff/snap_diff-capybara/issues/191))
30
+
31
+ ### Changed
32
+ - **`assert_matches_screenshot` is now the primary assertion method** — captures a screenshot and compares against baseline ([#191](https://github.com/snap-diff/snap_diff-capybara/issues/191))
33
+ - **`screenshot` is now a convenience wrapper** — safe to override in user test classes; the gem no longer calls it internally ([#191](https://github.com/snap-diff/snap_diff-capybara/issues/191))
34
+
35
+ ---
36
+
8
37
  ## [v1.12.0] - 2026-04-12
9
38
 
10
39
  ### Added
@@ -0,0 +1,129 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, religion, or sexual identity
10
+ and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the
26
+ overall community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or
31
+ advances of any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email
35
+ address, without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official e-mail address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement by
63
+ [opening a GitHub Issue](https://github.com/snap-diff/snap_diff-capybara/issues).
64
+
65
+ All complaints will be reviewed and investigated promptly and fairly.
66
+
67
+ All community leaders are obligated to respect the privacy and security of the
68
+ reporter of any incident.
69
+
70
+ ## Enforcement Guidelines
71
+
72
+ Community leaders will follow these Community Impact Guidelines in determining
73
+ the consequences for any action they deem in violation of this Code of Conduct:
74
+
75
+ ### 1. Correction
76
+
77
+ **Community Impact:** Use of inappropriate language or other behavior deemed
78
+ unprofessional or unwelcome in the community.
79
+
80
+ **Consequence:** A private, written warning from community leaders, providing
81
+ clarity around the nature of the violation and an explanation of why the
82
+ behavior was inappropriate. A public apology may be requested.
83
+
84
+ ### 2. Warning
85
+
86
+ **Community Impact:** A violation through a single incident or series
87
+ of actions.
88
+
89
+ **Consequence:** A warning with consequences for continued behavior. No
90
+ interaction with the people involved, including unsolicited interaction with
91
+ those enforcing the Code of Conduct, for a specified period of time. This
92
+ includes avoiding interactions in community spaces as well as external channels
93
+ like social media. Violating these terms may lead to a temporary or
94
+ permanent ban.
95
+
96
+ ### 3. Temporary Ban
97
+
98
+ **Community Impact:** A serious violation of community standards, including
99
+ sustained inappropriate behavior.
100
+
101
+ **Consequence:** A temporary ban from any sort of interaction or public
102
+ communication with the community for a specified period of time. No public or
103
+ private interaction with the people involved, including unsolicited interaction
104
+ with those enforcing the Code of Conduct, is allowed during this period.
105
+ Violating these terms may lead to a permanent ban.
106
+
107
+ ### 4. Permanent Ban
108
+
109
+ **Community Impact:** Demonstrating a pattern of violation of community
110
+ standards, including sustained inappropriate behavior, harassment of an
111
+ individual, or aggression toward or disparagement of classes of individuals.
112
+
113
+ **Consequence:** A permanent ban from any sort of public interaction within
114
+ the community.
115
+
116
+ ## Attribution
117
+
118
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
119
+ version 2.1, available at
120
+ https://www.contributor-covenant.org/version/2/1/code_of_conduct.html.
121
+
122
+ Community Impact Guidelines were inspired by
123
+ [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
124
+
125
+ [homepage]: https://www.contributor-covenant.org
126
+
127
+ For answers to common questions about this code of conduct, see the FAQ at
128
+ https://www.contributor-covenant.org/faq. Translations are available at
129
+ https://www.contributor-covenant.org/translations.
data/docs/RELEASE_PREP.md CHANGED
@@ -1,23 +1,23 @@
1
- # Release Preparation — v1.12.0
1
+ # Release Preparation — v1.14.0
2
2
 
3
3
  ## Summary
4
4
 
5
- 71 commits since v1.11.0 with new features, performance improvements, and default behavior changes.
5
+ SnapDiff namespace aliases (ADR-004 PR 9), standalone-require fix, and three
6
+ internal consolidation refactors (ADR-004 PR 2/PR 7, teardown logic).
6
7
 
7
8
  ## Release Checklist
8
9
 
9
10
  ### Pre-Release
10
11
 
11
- - [x] Update version to `1.12.0`
12
- - [x] Run tests: `bundle exec rake test` (218 runs, 0 failures)
13
- - [x] Add CHANGELOG.md
14
- - [x] Add docs/UPGRADING.md
12
+ - [x] Update version to `1.14.0`
13
+ - [x] Run tests: `bundle exec rake test:unit` (green)
14
+ - [x] Update CHANGELOG.md
15
15
 
16
16
  ### Release (One Click)
17
17
 
18
18
  1. Push to GitHub
19
19
  2. Go to [Actions → Release](https://github.com/snap-diff/snap_diff-capybara/actions/workflows/release.yml)
20
- 3. Click **Run workflow**, enter `1.12.0`
20
+ 3. Click **Run workflow**, enter `1.14.0`
21
21
  4. Workflow will: test → tag → publish to RubyGems → create GitHub Release
22
22
 
23
23
  ### Post-Release
@@ -27,32 +27,18 @@
27
27
 
28
28
  ## What Changed
29
29
 
30
- ### New Features
31
- - HTML reporter with premium UI, 4 comparison modes, zoom, keyboard navigation
32
- - GitHub Actions artifact integration with inline preview + reusable composite action
33
- - `disable_animations` helper for stable screenshots
34
- - `snap_diff:clean` rake task for diff artifact cleanup
35
- - `Diff.compare` for standalone image comparison
36
- - Perceptual color distance (dE00) for anti-aliasing
37
- - `assert_no_screenshot_changes` DSL method
38
- - `Diff.configure` block helper
39
- - Ruby 3.5 & 4.0 support
40
-
41
- ### Behavior Changes
42
- - `blur_active_element` defaults to `true`
43
- - `hide_caret` defaults to `true`
44
- - `fail_if_new` defaults to `true` in CI
45
- - Thread-safe reporter notification with mutex
46
- - SVN support removed
47
- - ActiveSupport no longer required
48
-
49
- ### Performance
50
- - Faster ChunkyPNG shift-detection (eliminated allocations)
51
- - Cached computations in VIPS driver
52
- - Memoized region area size
53
-
54
- ### Documentation
55
- - README restructured (970→149 lines) with 7 dedicated docs/ files
56
- - CI integration guide, upgrade guide, color comparison guide
30
+ ### Added
31
+ - `SnapDiff` namespace aliases `SnapDiff::Comparison`, `SnapDiff.compare`,
32
+ `SnapDiff.start` (additive; deprecations deferred to v2.0)
33
+
34
+ ### Fixed
35
+ - Standalone `require "capybara_screenshot_diff"` + `Diff.compare` no longer
36
+ raises `NameError` (missing drivers require)
37
+
38
+ ### Internal
39
+ - `DifferenceFinder` merged into `ImageCompare`; `AnnotationService` extracted
40
+ from `Reporters::Default` (public surface preserved); `pending_if_new`
41
+ teardown consolidated across the three framework adapters; driver-coverage
42
+ banner + CI guard in the test suite
57
43
 
58
44
  See [CHANGELOG.md](../CHANGELOG.md) for full details.
data/docs/UPGRADING.md CHANGED
@@ -1,6 +1,91 @@
1
- # Upgrading to v1.12.0
1
+ # Upgrading
2
2
 
3
- ## Overview
3
+ ## Upgrading to v1.13.0
4
+
5
+ ### Overview
6
+
7
+ Version 1.13.0 is a **minor release** clarifying API terminology and adding new capture methods. No breaking changes — your existing code continues to work.
8
+
9
+ **Estimated upgrade time:** 0 minutes (no action required for most users)
10
+
11
+ ---
12
+
13
+ ### Quick Upgrade Path (Most Users)
14
+
15
+ ```ruby
16
+ # In your Gemfile
17
+ gem 'capybara-screenshot-diff', '~> 1.13.0'
18
+ ```
19
+
20
+ ```bash
21
+ bundle update capybara-screenshot-diff
22
+ bundle exec rake test
23
+ ```
24
+
25
+ **That's it!** Existing `screenshot` calls work unchanged. New methods available if needed.
26
+
27
+ ---
28
+
29
+ ### What Changed
30
+
31
+ #### API Clarification: Primary Method is `assert_matches_screenshot`
32
+
33
+ **v1.12.0 and earlier:** `screenshot` was the primary method
34
+ **v1.13.0+:** `assert_matches_screenshot` is the primary method
35
+
36
+ **Action required:** None. `screenshot` continues to work as-is.
37
+
38
+ The method names now better reflect their behavior:
39
+ - `assert_matches_screenshot(name)` — takes screenshot and asserts it matches baseline
40
+ - `screenshot(name, compare: true)` — convenience wrapper (same behavior as above when `compare: true`)
41
+ - `capture_screenshot(name)` — new: captures without asserting
42
+
43
+ ```ruby
44
+ # All three work and are safe to use:
45
+ assert_matches_screenshot "homepage" # Primary: explicit intent
46
+ screenshot "homepage" # Shorthand (familiar)
47
+ screenshot "homepage", compare: false # Capture only
48
+ capture_screenshot "homepage" # Also capture only
49
+ ```
50
+
51
+ **Safe to override:** You can safely define your own `screenshot` method in your test base class — the gem's implementation won't interfere.
52
+
53
+ ---
54
+
55
+ ### New: `capture_screenshot` Method
56
+
57
+ Capture without comparing to baseline:
58
+
59
+ ```ruby
60
+ capture_screenshot "dynamic_page" # No assertion
61
+ ```
62
+
63
+ Equivalent to: `screenshot "dynamic_page", compare: false`
64
+
65
+ ---
66
+
67
+ ### New: `Diff.pending_if_new` Helper
68
+
69
+ Mark baseline-less tests pending instead of failing during initial CI runs:
70
+
71
+ ```ruby
72
+ # In test_helper.rb — before running tests
73
+ Capybara::Screenshot::Diff.pending_if_new = true
74
+ ```
75
+
76
+ **CI requirement:** When using `pending_if_new`, ensure CI is configured with `fail_if_new: false` (see [Configuration Reference](configuration.md#quick-setup)):
77
+
78
+ ```ruby
79
+ Capybara::Screenshot::Diff.configure do |screenshot, diff|
80
+ diff.fail_if_new = false # Allow baselines to be added
81
+ end
82
+ ```
83
+
84
+ ---
85
+
86
+ ## Upgrading to v1.12.0
87
+
88
+ ### Overview
4
89
 
5
90
  Version 1.12.0 is a **minor release** with new features, performance improvements, and default behavior changes. This guide will help you upgrade smoothly.
6
91
 
@@ -0,0 +1,269 @@
1
+ # Architecture
2
+
3
+ This document describes the internal architecture of `capybara-screenshot-diff` — how screenshots are captured, compared, and reported, and how the components fit together.
4
+
5
+ ## Overview
6
+
7
+ ```
8
+ ┌─────────────────────────────────────────────────────────┐
9
+ │ Test Framework │
10
+ │ (Minitest / RSpec / Cucumber / Custom) │
11
+ └──────────────┬──────────────────────────────┬────────────┘
12
+ │ │
13
+ ▼ ▼
14
+ ┌──────────────────────────┐ ┌──────────────────────────┐
15
+ │ CapybaraScreenshotDiff │ │ CapybaraScreenshotDiff │
16
+ │ ::DSL (screenshot, etc) │ │ ::AssertionRegistry │
17
+ └──────────────┬───────────┘ └──────────────┬───────────┘
18
+ │ │
19
+ ▼ ▼
20
+ ┌──────────────────────────┐ ┌──────────────────────────┐
21
+ │ ScreenshotMatcher │ │ ScreenshotAssertion │
22
+ │ (capture + compare) │ │ (validate results) │
23
+ └──────┬───────────┬────────┘ └──────────────┬───────────┘
24
+ │ │ │
25
+ ▼ ▼ ▼
26
+ ┌──────────┐ ┌──────────┐ ┌──────────────────────┐
27
+ │Screenshot│ │Stable │ │ Reporters │
28
+ │er │ │Screenshot│ │ (Default / HTML / │
29
+ │ │ │er │ │ Custom) │
30
+ └─────┬────┘ └──────────┘ └──────────────────────┘
31
+
32
+
33
+ ┌──────────────────────────────────────────┐
34
+ │ ImageCompare (layered comparison) │
35
+ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
36
+ │ │1. Byte │ │2. Pixel │ │3. Region │ │
37
+ │ │ compare │ │ compare │ │ analyze │ │
38
+ │ └──────────┘ └──────────┘ └──────────┘ │
39
+ └─────────────────────┬────────────────────┘
40
+
41
+
42
+ ┌──────────────────────────────────────────┐
43
+ │ Drivers (image processing backends) │
44
+ │ ┌──────────┐ ┌──────────────────────┐ │
45
+ │ │ Vips │ │ ChunkyPNG │ │
46
+ │ │ (fast) │ │ (no native deps) │ │
47
+ │ └──────────┘ └──────────────────────┘ │
48
+ └──────────────────────────────────────────┘
49
+ ```
50
+
51
+ ## Component Breakdown
52
+
53
+ ### 1. DSL Layer (`lib/capybara_screenshot_diff/dsl.rb`)
54
+
55
+ The entry point for test code. `assert_matches_screenshot` is the primary assertion method (captures and compares). `screenshot` is a convenience wrapper with a `compare:` option — `compare: true` (default) delegates to `assert_matches_screenshot`, while `compare: false` delegates to the new `capture_screenshot` method. `capture_screenshot` takes screenshots without assertions. `assert_no_screenshot_changes` keeps its behavior but now delegates to `assert_matches_screenshot` (that redirect is part of the #191 fix). Users can safely override `screenshot` in their test classes without affecting internal gem flow.
56
+
57
+ **Flow:**
58
+ 1. Checks if screenshots are `active?` (returns `false` if disabled)
59
+ 2. Builds a full screenshot name via `ScreenshotNamer` (handles sections, groups, counters)
60
+ 3. Delegates to `ScreenshotMatcher` to capture and prepare comparison
61
+ 4. Creates a `ScreenshotAssertion` — either adds it to the thread-local registry (delayed validation) or validates immediately
62
+
63
+ ### 2. ScreenshotMatcher (`lib/capybara/screenshot/diff/screenshot_matcher.rb`)
64
+
65
+ The orchestrator that coordinates capture and comparison:
66
+
67
+ 1. **Window size check** — verifies browser window is the expected size
68
+ 2. **Area calculation** — resolves crop regions and skip areas (supports CSS selectors and coordinates)
69
+ 3. **Base screenshot checkout** — retrieves the committed baseline from git via `Vcs.checkout_vcs`
70
+ 4. **Capture** — delegates to `Screenshoter` or `StableScreenshoter` depending on `stability_time_limit`
71
+ 5. **Comparison** — creates an `ImageCompare` object (lazy — actual comparison happens on first access)
72
+ 6. **Assertion** — returns a `ScreenshotAssertion` with the comparison attached
73
+
74
+ **Key design decision:** The "new" screenshot is taken *first*, then compared against the baseline. This means if no baseline exists (first run), we skip comparison entirely and the test passes.
75
+
76
+ ### 3. Screenshoter & StableScreenshoter (`lib/capybara/screenshot/diff/screenshoter.rb`, `lib/capybara/screenshot/diff/stable_screenshoter.rb`)
77
+
78
+ **Screenshoter:** The basic capture flow:
79
+ 1. Prepares the page (blur active element, hide caret, disable animations, wait for images)
80
+ 2. Takes a browser screenshot via `Capybara.current_session.save_screenshot`
81
+ 3. Processes the screenshot (resize for retina, apply crop)
82
+
83
+ **StableScreenshoter:** Wraps `Screenshoter` with stability detection:
84
+ 1. Takes sequential screenshots at `stability_time_limit` intervals
85
+ 2. Compares consecutive attempts for byte-level equality
86
+ 3. Returns once two consecutive screenshots are identical
87
+ 4. Fails with `UnstableImage` if timeout (`wait`) is reached, generating annotated attempt images for debugging
88
+
89
+ ### 4. ImageCompare (`lib/capybara/screenshot/diff/image_compare.rb`)
90
+
91
+ The comparison engine uses a **layered optimization strategy** to balance speed and accuracy:
92
+
93
+ | Layer | Method | What it checks | Speed | When it returns |
94
+ |-------|--------|----------------|-------|-----------------|
95
+ | 1 | `quick_equal?` | File size + byte-level comparison | Fastest | Equal → `true`, Different → Layer 2 |
96
+ | 2 | `quick_equal?` continues | Dimension check + pixel comparison | Fast | Different dimensions → `false`, Same pixels → `true` |
97
+ | 3 | `processed` / `different?` | Full region analysis with tolerance | Slower | Detailed diff with region, heatmap, annotations |
98
+
99
+ **Key details:**
100
+ - `quick_equal?` is designed for fast rejection — it early-returns as soon as a difference is found
101
+ - `different?` triggers the full comparison if not already processed
102
+ - `processed` guarantees the comparison is complete and returns the result with all metadata
103
+ - `ImageCompare#analyze_difference` handles the actual pixel analysis, delegating to the driver
104
+
105
+ ### 5. Drivers (`lib/capybara/screenshot/diff/drivers/`)
106
+
107
+ Drivers abstract image processing operations. Each driver implements:
108
+
109
+ | Operation | VipsDriver | ChunkyPNGDriver |
110
+ |-----------|-----------|-----------------|
111
+ | `load_images` | Vips::Image from file | ChunkyPNG::Image from blob |
112
+ | `same_dimension?` | Compare width × height | Same |
113
+ | `same_pixels?` | Pixel-level equality | Same |
114
+ | `find_difference_region` | Difference mask → Region | Row-by-row scan → Region |
115
+ | `crop` | Vips image crop | ChunkyPNG crop |
116
+ | `save_image_to` | Vips write_to_file | PNG save |
117
+ | `filter_image_with_median` | Vips median filter | Not supported |
118
+ | `add_black_box` | Draw filled rect | No-op (handled differently) |
119
+ | `merge` | Composite images | Not applicable |
120
+ | `highlight_mask` | Conditional color overlay | Not applicable |
121
+
122
+ **Auto-detection:** `Utils.detect_available_drivers` tries to load `:vips` first (via `ruby-vips` gem), then `:chunky_png`. The `:auto` driver mode picks the first available.
123
+
124
+ ### 6. Difference Region Detection
125
+
126
+ **VipsDriver** uses a **difference mask** approach:
127
+ 1. Compute absolute difference between images: `(new - base).abs`
128
+ 2. Optional: apply perceptual color distance (CIE dE00) instead of raw RGB
129
+ 3. Project the mask to find the bounding region of non-zero pixels
130
+ 4. Return the tight bounding box of all differences
131
+
132
+ **ChunkyPNGDriver** uses **row-by-row scanning**:
133
+ 1. Scan top-to-bottom, left-to-right for first differing pixel
134
+ 2. Expand left/right boundaries within each differing row
135
+ 3. Extend bottom boundary to cover all differing rows
136
+ 4. Supports shift detection (expensive neighbor pixel search)
137
+
138
+ ### 7. SnapManager & Snap (`lib/capybara_screenshot_diff/snap_manager.rb`, `lib/capybara_screenshot_diff/snap.rb`)
139
+
140
+ **Snap** represents a single screenshot file with path management:
141
+ - `path` — the actual screenshot file
142
+ - `base_path` — the `.base.ext` VCS checkout
143
+ - `attempt_path` — stability attempt files (`.attempt_00.png`, etc.)
144
+ - Provides cleanup of diff artifacts (`.diff.png`, `.heatmap.diff.png`)
145
+
146
+ **SnapManager** is the factory and path manager:
147
+ - Creates `Snap` instances
148
+ - Handles VCS checkout of baselines
149
+ - Manages file operations (copy, move, cleanup)
150
+
151
+ ### 8. VCS (`lib/capybara/screenshot/diff/vcs.rb`)
152
+
153
+ Handles baseline retrieval from git. Uses `git show HEAD:<path>` to extract the committed version. Supports Git LFS via `git lfs smudge`. Returns `false` if the file doesn't exist in VCS (first-run scenario).
154
+
155
+ ### 9. Reporters (`lib/capybara/screenshot/diff/reporters/`)
156
+
157
+ **Default reporter:** Generates annotated diff images:
158
+ - `image.diff.png` — new screenshot with diff region outlined in red
159
+ - `image.base.diff.png` — baseline with diff region outlined in red
160
+ - `image.heatmap.diff.png` — heatmap overlay of pixel differences
161
+
162
+ **HTML reporter:** Generates an interactive dashboard (`snap_diff_report.html`) with:
163
+ - Sidebar with thumbnails and search
164
+ - 4 view modes (both/base/new/heatmap)
165
+ - Annotated toggle for showing diff outlines
166
+ - Per-image zoom with synchronized panning across side-by-side views
167
+ - Keyboard navigation and shortcuts
168
+ - Responsive layout for mobile
169
+
170
+ **Custom reporters:** Implement `record(assertions)` and `finalize` methods, then add to `CapybaraScreenshotDiff.reporters`.
171
+
172
+ ### 10. Assertion Lifecycle
173
+
174
+ ```
175
+ Test begins
176
+
177
+ ├─ setup: resize_window_if_needed
178
+
179
+ ├─ test body:
180
+ │ └─ screenshot("name")
181
+ │ ├─ ScreenshotMatcher builds assertion
182
+ │ ├─ delayed=true → add to Thread-local registry
183
+ │ └─ delayed=false → validate immediately
184
+
185
+ ├─ teardown:
186
+ │ └─ CapybaraScreenshotDiff.verify
187
+ │ ├─ iterates thread-local assertions
188
+ │ ├─ calls validate on each
189
+ │ ├─ raises ExpectationNotMet on first failure
190
+ │ └─ notifies reporters via mutex-protected snapshot
191
+
192
+ └─ at_exit:
193
+ └─ CapybaraScreenshotDiff.finalize_reporters!
194
+ ├─ Generates HTML report (if reporter registered)
195
+ └─ Prints summary
196
+ ```
197
+
198
+ ### 11. Thread Safety
199
+
200
+ | Concern | Mechanism |
201
+ |---------|-----------|
202
+ | Assertion registry | Thread-local storage (`Thread.current[:capybara_screenshot_diff_registry]`) |
203
+ | Reporter notification | Mutex-protected snapshot of reporter list before iteration |
204
+ | HTML reporter internals | Mutex protecting `@failures`, `@total`, `@finalized` |
205
+ | Screenshot naming | Per-thread `ScreenshotNamer` instance |
206
+ | Global configuration | `mattr_accessor` — must be set before tests run, not mutated during parallel execution |
207
+ | File system | Atomic `FileUtils.mv`, unique paths per screenshot name + counter, thread-safe `mkpath` |
208
+
209
+ ### 12. Configuration System
210
+
211
+ Configuration uses Ruby's `mattr_accessor` (from ActiveSupport, or pure Ruby fallback) and is organized into two namespaces:
212
+
213
+ **`Capybara::Screenshot`** — capture settings:
214
+ - `window_size`, `stability_time_limit`, `blur_active_element`, `hide_caret`, `disable_animations`
215
+ - `save_path`, `root`, `screenshot_format`, `add_driver_path`, `add_os_path`
216
+ - `enabled`, `capybara_screenshot_options`
217
+
218
+ **`Capybara::Screenshot::Diff`** — comparison settings:
219
+ - `driver`, `tolerance`, `color_distance_limit`, `perceptual_threshold`, `shift_distance_limit`
220
+ - `area_size_limit`, `skip_area`, `fail_if_new`, `fail_on_difference`, `delayed`
221
+
222
+ The `Diff.configure` block helper provides a convenient way to set both namespaces at once.
223
+
224
+ ## File Layout
225
+
226
+ ```
227
+ lib/
228
+ capybara_screenshot_diff.rb # Core module, mattr_accessor definitions
229
+ capybara/screenshot/diff.rb # Convenience require (loads minitest)
230
+ capybara_screenshot_diff/
231
+ dsl.rb # screenshot(), screenshot_group(), etc.
232
+ minitest.rb # Minitest assertions integration
233
+ rspec.rb # RSpec matcher integration
234
+ cucumber.rb # Cucumber World integration
235
+ static.rb # Non-Rails static site serving
236
+ snap_manager.rb # Screenshot file management
237
+ snap.rb # Single screenshot file abstraction
238
+ screenshot_namer.rb # Name/path generation with sections/groups
239
+ screenshot_assertion.rb # Assertion + registry objects
240
+ attempts_reporter.rb # Debug reporting for unstable captures
241
+ error_with_filtered_backtrace.rb # Error with filtered stack
242
+ backtrace_filter.rb # Library/gem frame filtering
243
+ reporters/
244
+ html.rb # Interactive HTML report reporter
245
+ templates/report.html.erb # HTML report template
246
+ capybara/screenshot/diff/
247
+ version.rb # VERSION constant
248
+ utils.rb # Driver detection
249
+ drivers.rb # Driver factory
250
+ drivers/
251
+ base_driver.rb # Abstract base driver
252
+ vips_driver.rb # VIPS image processing
253
+ chunky_png_driver.rb # ChunkyPNG image processing
254
+ screenshoter.rb # Basic browser screenshot capture
255
+ stable_screenshoter.rb # Stability detection wrapper
256
+ screenshot_matcher.rb # Orchestrator for capture + compare
257
+ image_compare.rb # Layered comparison engine
258
+ comparison.rb # Comparison value object
259
+ difference.rb # Difference result value object
260
+ image_preprocessor.rb # Pre-processing (skip areas, median filter)
261
+ area_calculator.rb # Crop/skip area coordinate resolution
262
+ region.rb # Bounding box region value object
263
+ browser_helpers.rb # DOM manipulation helpers
264
+ vcs.rb # Git baseline checkout
265
+ os.rb # OS detection
266
+ cucumber.rb # Deprecated Cucumber entry point
267
+ reporters/
268
+ default.rb # Default annotated-image reporter
269
+ ```