snap_diff-capybara 0.0.1 → 2.0.0.beta1
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 +4 -4
- data/CHANGELOG.md +190 -0
- data/CODE_OF_CONDUCT.md +129 -0
- data/LICENSE.txt +21 -0
- data/Rakefile +65 -0
- data/capybara-screenshot-diff.gemspec +29 -0
- data/docs/RELEASE_PREP.md +44 -0
- data/docs/UPGRADING.md +702 -0
- data/docs/architecture.md +289 -0
- data/docs/ci-integration.md +238 -0
- data/docs/configuration.md +395 -0
- data/docs/docker-testing.md +24 -0
- data/docs/drivers.md +102 -0
- data/docs/framework-setup.md +87 -0
- data/docs/images/snap_diff_annotated.png +0 -0
- data/docs/images/snap_diff_web_ui.png +0 -0
- data/docs/migration-guide.md +286 -0
- data/docs/organization.md +204 -0
- data/docs/reporters.md +46 -0
- data/docs/thread_safety.md +112 -0
- data/gems.rb +39 -0
- data/lib/capybara/screenshot/diff/annotation_service.rb +7 -0
- data/lib/capybara/screenshot/diff/area_calculator.rb +7 -0
- data/lib/capybara/screenshot/diff/browser_helpers.rb +7 -0
- data/lib/capybara/screenshot/diff/config_legacy.rb +113 -0
- data/lib/capybara/screenshot/diff/cucumber.rb +3 -0
- data/lib/capybara/screenshot/diff/difference.rb +8 -0
- data/lib/capybara/screenshot/diff/drivers/base_driver.rb +9 -0
- data/lib/capybara/screenshot/diff/drivers/chunky_png_driver.rb +7 -0
- data/lib/capybara/screenshot/diff/drivers/vips_driver.rb +7 -0
- data/lib/capybara/screenshot/diff/drivers.rb +9 -0
- data/lib/capybara/screenshot/diff/image_compare.rb +12 -0
- data/lib/capybara/screenshot/diff/image_preprocessor.rb +7 -0
- data/lib/capybara/screenshot/diff/os.rb +14 -0
- data/lib/capybara/screenshot/diff/region.rb +107 -0
- data/lib/capybara/screenshot/diff/reporters/default.rb +109 -0
- data/lib/capybara/screenshot/diff/screenshot_matcher.rb +7 -0
- data/lib/capybara/screenshot/diff/screenshoter.rb +7 -0
- data/lib/capybara/screenshot/diff/stable_screenshoter.rb +7 -0
- data/lib/capybara/screenshot/diff/utils.rb +7 -0
- data/lib/capybara/screenshot/diff/vcs.rb +7 -0
- data/lib/capybara/screenshot/diff/version.rb +15 -0
- data/lib/capybara/screenshot/diff.rb +3 -0
- data/lib/capybara-screenshot-diff.rb +3 -0
- data/lib/capybara_screenshot_diff/attempts_reporter.rb +7 -0
- data/lib/capybara_screenshot_diff/cucumber.rb +8 -0
- data/lib/capybara_screenshot_diff/dsl.rb +12 -0
- data/lib/capybara_screenshot_diff/error_with_filtered_backtrace.rb +8 -0
- data/lib/capybara_screenshot_diff/minitest.rb +14 -0
- data/lib/capybara_screenshot_diff/reporters/html.rb +7 -0
- data/lib/capybara_screenshot_diff/rspec.rb +8 -0
- data/lib/capybara_screenshot_diff/screenshot_assertion.rb +71 -0
- data/lib/capybara_screenshot_diff/screenshot_namer.rb +7 -0
- data/lib/capybara_screenshot_diff/snap.rb +7 -0
- data/lib/capybara_screenshot_diff/snap_manager.rb +7 -0
- data/lib/capybara_screenshot_diff/static.rb +9 -0
- data/lib/capybara_screenshot_diff.rb +50 -0
- data/lib/snap_diff/annotation_service.rb +84 -0
- data/lib/snap_diff/area_calculator.rb +56 -0
- data/lib/snap_diff/attempts_reporter.rb +51 -0
- data/lib/snap_diff/browser_helpers.rb +121 -0
- data/lib/snap_diff/capture/viewport.rb +40 -0
- data/lib/snap_diff/comparison.rb +238 -0
- data/lib/snap_diff/comparison_result.rb +104 -0
- data/lib/snap_diff/config.rb +78 -0
- data/lib/snap_diff/deprecation.rb +84 -0
- data/lib/snap_diff/driver.rb +37 -0
- data/lib/snap_diff/drivers/chunky_png_driver.rb +298 -0
- data/lib/snap_diff/drivers/vips_driver.rb +171 -0
- data/lib/snap_diff/drivers.rb +14 -0
- data/lib/snap_diff/dsl.rb +143 -0
- data/lib/snap_diff/error_with_filtered_backtrace.rb +32 -0
- data/lib/snap_diff/image_preprocessor.rb +68 -0
- data/lib/snap_diff/integrations/cucumber.rb +22 -0
- data/lib/snap_diff/integrations/minitest.rb +70 -0
- data/lib/snap_diff/integrations/rspec.rb +68 -0
- data/lib/snap_diff/legacy_shims.rb +99 -0
- data/lib/snap_diff/os.rb +17 -0
- data/lib/snap_diff/reporters/html.rb +143 -0
- data/lib/snap_diff/reporters/templates/report.html.erb +463 -0
- data/lib/snap_diff/reporting.rb +53 -0
- data/lib/snap_diff/screenshot_assertion.rb +143 -0
- data/lib/snap_diff/screenshot_matcher.rb +113 -0
- data/lib/snap_diff/screenshot_namer.rb +81 -0
- data/lib/snap_diff/screenshoter.rb +129 -0
- data/lib/snap_diff/snap.rb +66 -0
- data/lib/snap_diff/snap_manager.rb +125 -0
- data/lib/snap_diff/stable_screenshoter.rb +103 -0
- data/lib/snap_diff/static.rb +11 -0
- data/lib/snap_diff/utils.rb +38 -0
- data/lib/snap_diff/vcs.rb +35 -0
- data/lib/snap_diff/version.rb +5 -0
- data/lib/snap_diff.rb +65 -0
- metadata +160 -10
- data/README.md +0 -3
data/docs/UPGRADING.md
ADDED
|
@@ -0,0 +1,702 @@
|
|
|
1
|
+
# Upgrading
|
|
2
|
+
|
|
3
|
+
## Upgrading to v2.0 (alpha)
|
|
4
|
+
|
|
5
|
+
### Overview
|
|
6
|
+
|
|
7
|
+
Version 2.0 introduces a new canonical namespace (`SnapDiff`) for cleaner, more discoverable code. The public DSL remains unchanged — your existing `screenshot` and `assert_matches_screenshot` calls work without modification. This guide covers the optional migration path for settings and the new namespace.
|
|
8
|
+
|
|
9
|
+
**Status:** `2.0.0.alpha1` is an opt-in prerelease. RubyGems never installs prereleases by default resolution — normal `bundle update` keeps you on the 1.x line. The final 2.0.0 ships only after adopter feedback; please report anything surprising on [#166](https://github.com/snap-diff/snap_diff-capybara/issues/166).
|
|
10
|
+
|
|
11
|
+
**Estimated upgrade time:** 5–15 minutes (most users need only the Gemfile pin)
|
|
12
|
+
|
|
13
|
+
**Breaking changes:** None for the DSL; deprecation warnings if you reference legacy constants (suppressible), plus two known alpha caveats (see below)
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
### The Short Version (Most Users)
|
|
18
|
+
|
|
19
|
+
```ruby
|
|
20
|
+
# In your Gemfile — the exact prerelease version is required to opt in
|
|
21
|
+
gem "capybara-screenshot-diff", "2.0.0.alpha1"
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
bundle install
|
|
26
|
+
bundle exec rake test
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
**That's it.** Your existing code works unchanged. The old namespaces (`Capybara::Screenshot::Diff`, `CapybaraScreenshotDiff`) are shimmed with deprecation warnings; the new one (`SnapDiff`) is available if you want to modernize.
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
### What Changed
|
|
34
|
+
|
|
35
|
+
#### 1. New Canonical Namespace: `SnapDiff`
|
|
36
|
+
|
|
37
|
+
The implementation now lives in `lib/snap_diff/` under the `SnapDiff` namespace. Every legacy constant still resolves — lazily, to the *same object* — but emits a one-time-per-constant deprecation warning. The main renames:
|
|
38
|
+
|
|
39
|
+
| Legacy name | v2 canonical name |
|
|
40
|
+
|-------------|-------------------|
|
|
41
|
+
| `Capybara::Screenshot::Diff::ImageCompare` | `SnapDiff::Comparison` |
|
|
42
|
+
| `Capybara::Screenshot::Diff::Difference` | `SnapDiff::ComparisonResult` |
|
|
43
|
+
| `Capybara::Screenshot::Diff::Drivers::BaseDriver` | `SnapDiff::Driver` (now a mixin — see below) |
|
|
44
|
+
| `CapybaraScreenshotDiff::SnapManager` / `::Snap` | `SnapDiff::SnapManager` / `SnapDiff::Snap` |
|
|
45
|
+
| `CapybaraScreenshotDiff::RED_RGBA` / `::ORANGE_RGBA` | `SnapDiff::RED_RGBA` / `SnapDiff::ORANGE_RGBA` |
|
|
46
|
+
|
|
47
|
+
**What stays the same:**
|
|
48
|
+
- `screenshot(name)` — still works
|
|
49
|
+
- `assert_matches_screenshot(name)` — still works, still the recommended form
|
|
50
|
+
- `capture_screenshot(name)` — still works
|
|
51
|
+
- All `compare: false/true` flags and overrides work identically
|
|
52
|
+
|
|
53
|
+
**What's new (optional):**
|
|
54
|
+
|
|
55
|
+
```ruby
|
|
56
|
+
# Old (still works; constant access now warns once per process)
|
|
57
|
+
Capybara::Screenshot::Diff.compare("baseline.png", "current.png")
|
|
58
|
+
Capybara::Screenshot::Diff.configure { |screenshot, diff| ... }
|
|
59
|
+
|
|
60
|
+
# New (recommended for new code)
|
|
61
|
+
SnapDiff.compare("baseline.png", "current.png")
|
|
62
|
+
SnapDiff.start { |screenshot, diff| ... } # same shape as old configure
|
|
63
|
+
SnapDiff.configure { |config| ... } # consolidated config object
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
#### 2. Consolidated Configuration: `SnapDiff.config`
|
|
67
|
+
|
|
68
|
+
Instead of scattering settings across `Capybara::Screenshot` and `Capybara::Screenshot::Diff`, v2.0 offers a single `SnapDiff::Config` object. Both the old and new paths read and write the same underlying storage — writes through either are visible through the other.
|
|
69
|
+
|
|
70
|
+
**The DSL never changes.** `screenshot` and `assert_matches_screenshot` work exactly as before.
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
### Settings Migration Table
|
|
75
|
+
|
|
76
|
+
The most commonly-used settings and how to update them:
|
|
77
|
+
|
|
78
|
+
| Setting | v1.x (still works in v2) | v2.0 (recommended) | What it does |
|
|
79
|
+
|---------|----------------------|------------------|------|
|
|
80
|
+
| `blur_active_element` | `Capybara::Screenshot.blur_active_element = true` | `SnapDiff.config.blur_active_element = true` | Hide cursor/focus indicator in screenshots (default: `true`) |
|
|
81
|
+
| `hide_caret` | `Capybara::Screenshot.hide_caret = true` | `SnapDiff.config.hide_caret = true` | Make input caret transparent for stable comparisons (default: `true`) |
|
|
82
|
+
| `tolerance` | `Capybara::Screenshot::Diff.tolerance = 0.0005` | `SnapDiff.config.tolerance = 0.0005` | Pixel-level color difference threshold (higher = less strict) |
|
|
83
|
+
| `save_path` | `Capybara::Screenshot.save_path = "doc/screenshots"` | `SnapDiff.config.save_path = "doc/screenshots"` | Where baseline screenshots are stored |
|
|
84
|
+
| `window_size` | `Capybara::Screenshot.window_size = [1280, 1024]` | `SnapDiff.config.window_size = [1280, 1024]` | Browser viewport size for consistent screenshots |
|
|
85
|
+
|
|
86
|
+
**All 27 settings** from both legacy namespaces are available via `SnapDiff.config.<attr_name>` — see the [Configuration Reference](configuration.md) for the full list. One rename to note: `Capybara::Screenshot.enabled` becomes `SnapDiff.config.screenshot_enabled` (it would otherwise collide with `Capybara::Screenshot::Diff.enabled`, which keeps the bare `enabled` name).
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
### Three Ways to Configure
|
|
91
|
+
|
|
92
|
+
All three are equivalent and use the same underlying storage. Pick the one that fits your style.
|
|
93
|
+
|
|
94
|
+
#### Option 1: Traditional block (v1 shape, still works)
|
|
95
|
+
|
|
96
|
+
```ruby
|
|
97
|
+
# In test_helper.rb or spec_helper.rb
|
|
98
|
+
Capybara::Screenshot::Diff.configure do |screenshot, diff|
|
|
99
|
+
screenshot.window_size = [1280, 1024]
|
|
100
|
+
screenshot.blur_active_element = false
|
|
101
|
+
diff.tolerance = 0.0005
|
|
102
|
+
diff.driver = :vips
|
|
103
|
+
end
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
#### Option 2: SnapDiff block with old shape (backward-compatible)
|
|
107
|
+
|
|
108
|
+
```ruby
|
|
109
|
+
SnapDiff.start do |screenshot, diff|
|
|
110
|
+
screenshot.window_size = [1280, 1024]
|
|
111
|
+
screenshot.blur_active_element = false
|
|
112
|
+
diff.tolerance = 0.0005
|
|
113
|
+
diff.driver = :vips
|
|
114
|
+
end
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
#### Option 3: Consolidated config (cleanest)
|
|
118
|
+
|
|
119
|
+
```ruby
|
|
120
|
+
SnapDiff.configure do |config|
|
|
121
|
+
config.window_size = [1280, 1024]
|
|
122
|
+
config.blur_active_element = false
|
|
123
|
+
config.tolerance = 0.0005
|
|
124
|
+
config.driver = :vips
|
|
125
|
+
end
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
### Prepare Today on v1.x (Zero Risk)
|
|
131
|
+
|
|
132
|
+
You don't have to wait for v2.0 to start using the new namespace. `SnapDiff.compare` and `SnapDiff.start` were added in v1.14; `SnapDiff.config` / `SnapDiff.configure` in v1.15. All of them work on the current 1.x line:
|
|
133
|
+
|
|
134
|
+
```ruby
|
|
135
|
+
# Works TODAY on v1.15+, zero risk
|
|
136
|
+
SnapDiff.compare("baseline.png", "current.png")
|
|
137
|
+
SnapDiff.start { |screenshot, diff| ... }
|
|
138
|
+
SnapDiff.configure { |config| ... }
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
This means you can migrate your codebase incrementally **now**, before opting into 2.0.
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
### Deprecation Warnings
|
|
146
|
+
|
|
147
|
+
In v2.0, resolving a legacy *constant* emits one deprecation warning per constant per process:
|
|
148
|
+
|
|
149
|
+
```
|
|
150
|
+
[snap_diff deprecation] `Capybara::Screenshot::Diff::ImageCompare` is deprecated (constant); use `SnapDiff::Comparison` instead.
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
**Warnings appear for:** legacy constant access — `Capybara::Screenshot::Diff::ImageCompare`, `::Difference`, `::Drivers`, `CapybaraScreenshotDiff::SnapManager`, etc.
|
|
154
|
+
|
|
155
|
+
**Warnings do NOT appear for:**
|
|
156
|
+
- Requiring the gem: `require "capybara_screenshot_diff/minitest"` etc. is not deprecated
|
|
157
|
+
- The DSL: `screenshot`, `assert_matches_screenshot`, `capture_screenshot` are never deprecated
|
|
158
|
+
- Settings access: `Capybara::Screenshot.blur_active_element`, `Capybara::Screenshot::Diff.tolerance=`, and the `Diff.configure` block stay silent — they remain the canonical storage that `SnapDiff.config` forwards to
|
|
159
|
+
- A few advertised entry-point constants that stay eagerly defined by design: `Capybara::Screenshot::Os`, `CapybaraScreenshotDiff::DSL`, `Capybara::Screenshot::Diff::VERSION`, and the driver leaf classes (`Drivers::VipsDriver`, `Drivers::ChunkyPNGDriver`)
|
|
160
|
+
|
|
161
|
+
Warnings go through `Kernel#warn`, so test suites that hook `Warning.warn` (e.g. raise-on-warning setups) see them like any other Ruby warning.
|
|
162
|
+
|
|
163
|
+
#### Silencing Warnings
|
|
164
|
+
|
|
165
|
+
If warnings appear in a test run and you're not ready to migrate yet:
|
|
166
|
+
|
|
167
|
+
```ruby
|
|
168
|
+
# In test_helper.rb, before running tests
|
|
169
|
+
SnapDiff.silence_deprecations = true
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
# Or as an environment variable
|
|
174
|
+
export SNAP_DIFF_SILENCE_DEPRECATIONS=1
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
### Known Alpha Caveats
|
|
180
|
+
|
|
181
|
+
Two deliberate consequences of the lazy shim design — both flagged for feedback on [#166](https://github.com/snap-diff/snap_diff-capybara/issues/166):
|
|
182
|
+
|
|
183
|
+
1. **`defined?` / `const_defined?` on lazily-shimmed legacy names returns `false`/`nil`.** The shims resolve via `const_missing`, which those checks never trigger. Feature detection like `defined?(Capybara::Screenshot::Diff::ImageCompare)` must move to the `SnapDiff::` name. Rescuing legacy *error classes* is unaffected — they remain eagerly defined.
|
|
184
|
+
|
|
185
|
+
2. **Reopening `module Capybara::Screenshot::Diff::Drivers` shadows the shim.** The historical custom-driver monkey-patch pattern defines a fresh, empty `Drivers` module instead of reaching the real one. Define custom drivers under `SnapDiff::Drivers` instead — and note `BaseDriver` is gone as a superclass: `class MyDriver < BaseDriver` becomes `include SnapDiff::Driver` (it's a mixin now).
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
### FAQ
|
|
190
|
+
|
|
191
|
+
#### "My tests pass but I see warnings. Should I worry?"
|
|
192
|
+
|
|
193
|
+
No. Warnings are informational and fully suppressible. They're designed to catch legacy namespace references, not break existing CI. If silence is preferable for now, set `SNAP_DIFF_SILENCE_DEPRECATIONS=1` and migrate at your pace.
|
|
194
|
+
|
|
195
|
+
#### "Does the DSL change at all?"
|
|
196
|
+
|
|
197
|
+
No. `screenshot`, `assert_matches_screenshot`, and `capture_screenshot` are stable and unchanged. All overrides (`:compare`, `:tolerance`, etc.) work identically.
|
|
198
|
+
|
|
199
|
+
#### "Can I mix old and new config in the same suite?"
|
|
200
|
+
|
|
201
|
+
Yes. Both paths write to the same underlying storage:
|
|
202
|
+
|
|
203
|
+
```ruby
|
|
204
|
+
Capybara::Screenshot::Diff.configure do |screenshot, diff|
|
|
205
|
+
screenshot.window_size = [1280, 1024]
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
SnapDiff.configure do |config|
|
|
209
|
+
config.tolerance = 0.0005 # Same storage, visible to the old path too
|
|
210
|
+
end
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
#### "What if I need to roll back?"
|
|
214
|
+
|
|
215
|
+
All settings and baselines are compatible with v1.x. Simply pin your Gemfile back to `"~> 1.15"` and `bundle update capybara-screenshot-diff`.
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
### Summary Checklist
|
|
220
|
+
|
|
221
|
+
- [ ] Pin `gem "capybara-screenshot-diff", "2.0.0.alpha1"` in your Gemfile
|
|
222
|
+
- [ ] Run `bundle install`
|
|
223
|
+
- [ ] Run your test suite to verify no regressions
|
|
224
|
+
- [ ] (Optional) Migrate config to the `SnapDiff` namespace
|
|
225
|
+
- [ ] (Optional) Silence deprecation warnings if not ready to migrate
|
|
226
|
+
- [ ] Report anything surprising on [#166](https://github.com/snap-diff/snap_diff-capybara/issues/166)
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
## Upgrading to v1.13.0
|
|
231
|
+
|
|
232
|
+
### Overview
|
|
233
|
+
|
|
234
|
+
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.
|
|
235
|
+
|
|
236
|
+
**Estimated upgrade time:** 0 minutes (no action required for most users)
|
|
237
|
+
|
|
238
|
+
---
|
|
239
|
+
|
|
240
|
+
### Quick Upgrade Path (Most Users)
|
|
241
|
+
|
|
242
|
+
```ruby
|
|
243
|
+
# In your Gemfile
|
|
244
|
+
gem 'capybara-screenshot-diff', '~> 1.13.0'
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
```bash
|
|
248
|
+
bundle update capybara-screenshot-diff
|
|
249
|
+
bundle exec rake test
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
**That's it!** Existing `screenshot` calls work unchanged. New methods available if needed.
|
|
253
|
+
|
|
254
|
+
---
|
|
255
|
+
|
|
256
|
+
### What Changed
|
|
257
|
+
|
|
258
|
+
#### API Clarification: Primary Method is `assert_matches_screenshot`
|
|
259
|
+
|
|
260
|
+
**v1.12.0 and earlier:** `screenshot` was the primary method
|
|
261
|
+
**v1.13.0+:** `assert_matches_screenshot` is the primary method
|
|
262
|
+
|
|
263
|
+
**Action required:** None. `screenshot` continues to work as-is.
|
|
264
|
+
|
|
265
|
+
The method names now better reflect their behavior:
|
|
266
|
+
- `assert_matches_screenshot(name)` — takes screenshot and asserts it matches baseline
|
|
267
|
+
- `screenshot(name, compare: true)` — convenience wrapper (same behavior as above when `compare: true`)
|
|
268
|
+
- `capture_screenshot(name)` — new: captures without asserting
|
|
269
|
+
|
|
270
|
+
```ruby
|
|
271
|
+
# All three work and are safe to use:
|
|
272
|
+
assert_matches_screenshot "homepage" # Primary: explicit intent
|
|
273
|
+
screenshot "homepage" # Shorthand (familiar)
|
|
274
|
+
screenshot "homepage", compare: false # Capture only
|
|
275
|
+
capture_screenshot "homepage" # Also capture only
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
**Safe to override:** You can safely define your own `screenshot` method in your test base class — the gem's implementation won't interfere.
|
|
279
|
+
|
|
280
|
+
---
|
|
281
|
+
|
|
282
|
+
### New: `capture_screenshot` Method
|
|
283
|
+
|
|
284
|
+
Capture without comparing to baseline:
|
|
285
|
+
|
|
286
|
+
```ruby
|
|
287
|
+
capture_screenshot "dynamic_page" # No assertion
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
Equivalent to: `screenshot "dynamic_page", compare: false`
|
|
291
|
+
|
|
292
|
+
---
|
|
293
|
+
|
|
294
|
+
### New: `Diff.pending_if_new` Helper
|
|
295
|
+
|
|
296
|
+
Mark baseline-less tests pending instead of failing during initial CI runs:
|
|
297
|
+
|
|
298
|
+
```ruby
|
|
299
|
+
# In test_helper.rb — before running tests
|
|
300
|
+
Capybara::Screenshot::Diff.pending_if_new = true
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
**CI requirement:** When using `pending_if_new`, ensure CI is configured with `fail_if_new: false` (see [Configuration Reference](configuration.md#quick-setup)):
|
|
304
|
+
|
|
305
|
+
```ruby
|
|
306
|
+
Capybara::Screenshot::Diff.configure do |screenshot, diff|
|
|
307
|
+
diff.fail_if_new = false # Allow baselines to be added
|
|
308
|
+
end
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
---
|
|
312
|
+
|
|
313
|
+
## Upgrading to v1.12.0
|
|
314
|
+
|
|
315
|
+
### Overview
|
|
316
|
+
|
|
317
|
+
Version 1.12.0 is a **minor release** with new features, performance improvements, and default behavior changes. This guide will help you upgrade smoothly.
|
|
318
|
+
|
|
319
|
+
**Estimated upgrade time:** 5-15 minutes depending on your setup
|
|
320
|
+
|
|
321
|
+
---
|
|
322
|
+
|
|
323
|
+
## Quick Upgrade Path (Most Users)
|
|
324
|
+
|
|
325
|
+
For **most users**, upgrading is as simple as:
|
|
326
|
+
|
|
327
|
+
```ruby
|
|
328
|
+
# In your Gemfile
|
|
329
|
+
gem 'capybara-screenshot-diff', '~> 1.12.0'
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
```bash
|
|
333
|
+
bundle update capybara-screenshot-diff
|
|
334
|
+
bundle exec rake test # Verify tests still pass
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
**That's it!** The zero-config setup still works out of the box. Your existing screenshot comparisons will continue to work with v1.12.0.
|
|
338
|
+
|
|
339
|
+
---
|
|
340
|
+
|
|
341
|
+
## Breaking Changes & Migration Steps
|
|
342
|
+
|
|
343
|
+
### 1. Default Behavior Changes (Most Important)
|
|
344
|
+
|
|
345
|
+
Three settings now have different defaults. This is the most likely source of unexpected test failures.
|
|
346
|
+
|
|
347
|
+
#### `blur_active_element` — Now defaults to `true`
|
|
348
|
+
|
|
349
|
+
**Before (v1.11.x):** Cursor blinking could delay screenshots
|
|
350
|
+
**After (v1.12.0):** Cursor is automatically hidden
|
|
351
|
+
|
|
352
|
+
**Action required:** Only if you want the old behavior
|
|
353
|
+
|
|
354
|
+
```ruby
|
|
355
|
+
# To restore v1.x behavior:
|
|
356
|
+
Capybara::Screenshot.blur_active_element = false
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
#### `hide_caret` — Now defaults to `true`
|
|
360
|
+
|
|
361
|
+
**Before (v1.11.x):** Input caret visible in screenshots
|
|
362
|
+
**After (v1.12.0):** Caret is transparent for stable screenshots
|
|
363
|
+
|
|
364
|
+
**Action required:** Only if you want the old behavior
|
|
365
|
+
|
|
366
|
+
```ruby
|
|
367
|
+
# To restore v1.x behavior:
|
|
368
|
+
Capybara::Screenshot.hide_caret = false
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
#### `fail_if_new` — Now defaults to `true` in CI
|
|
372
|
+
|
|
373
|
+
**Before (v1.11.x):** New screenshots allowed in CI
|
|
374
|
+
**After (v1.12.0):** New screenshots fail tests in CI (when `ENV['CI']` is set)
|
|
375
|
+
|
|
376
|
+
**Action required:** Only if you want to allow new screenshots in CI
|
|
377
|
+
|
|
378
|
+
```ruby
|
|
379
|
+
# To allow new screenshots in CI:
|
|
380
|
+
Capybara::Screenshot::Diff.fail_if_new = false
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
**Why this changed:** This prevents accidental baseline additions in CI pipelines. Most teams want this behavior.
|
|
384
|
+
|
|
385
|
+
---
|
|
386
|
+
|
|
387
|
+
### 2. SVN Support Removed
|
|
388
|
+
|
|
389
|
+
**Before (v1.11.x):** Could use SVN for version control
|
|
390
|
+
**After (v1.12.0):** Git only
|
|
391
|
+
|
|
392
|
+
**Action required:** If using SVN, migrate to Git
|
|
393
|
+
|
|
394
|
+
```bash
|
|
395
|
+
# Check if you're using SVN for screenshots
|
|
396
|
+
git grep svn test/ # Look for svn commands in your tests
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
If you find SVN usage:
|
|
400
|
+
1. Export your SVN repository to Git
|
|
401
|
+
2. Update your CI/CD to use Git
|
|
402
|
+
3. Re-commit all screenshot baselines with Git
|
|
403
|
+
|
|
404
|
+
**Why this changed:** SVN support was rarely used and added maintenance burden.
|
|
405
|
+
|
|
406
|
+
---
|
|
407
|
+
|
|
408
|
+
### 3. ActiveSupport No Longer Required
|
|
409
|
+
|
|
410
|
+
**Before (v1.11.x):** ActiveSupport was a runtime dependency
|
|
411
|
+
**After (v1.12.0):** Pure Ruby, no ActiveSupport required
|
|
412
|
+
|
|
413
|
+
**Action required:** None (this is a positive change!)
|
|
414
|
+
|
|
415
|
+
If your project only had ActiveSupport because of this gem, you can now remove it:
|
|
416
|
+
|
|
417
|
+
```ruby
|
|
418
|
+
# In your Gemfile — can likely be removed if only used for this gem
|
|
419
|
+
# gem 'activesupport' # ← Remove if not used elsewhere
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
**Why this changed:** Lighter installations, faster boot times.
|
|
423
|
+
|
|
424
|
+
---
|
|
425
|
+
|
|
426
|
+
### 4. Internal API Changes
|
|
427
|
+
|
|
428
|
+
**Before (v1.11.x):** Could use internal classes like `CaptureStrategy`, `ComparisonLoader`
|
|
429
|
+
**After (v1.12.0):** These have been inlined/refactored
|
|
430
|
+
|
|
431
|
+
**Action required:** Only if using internal APIs
|
|
432
|
+
|
|
433
|
+
Check your codebase:
|
|
434
|
+
|
|
435
|
+
```bash
|
|
436
|
+
# Search for internal API usage
|
|
437
|
+
grep -r "CaptureStrategy" test/ lib/
|
|
438
|
+
grep -r "ComparisonLoader" test/ lib/
|
|
439
|
+
grep -r "ScreenshotCoordinator" test/ lib/
|
|
440
|
+
grep -r "ImagePreprocessor" test/ lib/
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
If you find usage, these were never part of the public API and should be replaced with the documented public API.
|
|
444
|
+
|
|
445
|
+
**Why this changed:** Simplified architecture, better performance, easier maintenance.
|
|
446
|
+
|
|
447
|
+
---
|
|
448
|
+
|
|
449
|
+
## New Features to Try
|
|
450
|
+
|
|
451
|
+
### HTML Reporter (Recommended)
|
|
452
|
+
|
|
453
|
+
Get an interactive dashboard showing all screenshot differences:
|
|
454
|
+
|
|
455
|
+
```ruby
|
|
456
|
+
# Add to test_helper.rb or spec_helper.rb
|
|
457
|
+
require 'capybara_screenshot_diff/reporters/html'
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
After running tests:
|
|
461
|
+
|
|
462
|
+
```bash
|
|
463
|
+
open doc/screenshots/snap_diff_report.html
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
**Features:**
|
|
467
|
+
- Side-by-side comparison with diff toggle
|
|
468
|
+
- Thumbnail sidebar for navigation
|
|
469
|
+
- Search functionality
|
|
470
|
+
- Summary statistics
|
|
471
|
+
|
|
472
|
+
---
|
|
473
|
+
|
|
474
|
+
### Standalone Image Comparison
|
|
475
|
+
|
|
476
|
+
Compare any two images without Capybara or a browser:
|
|
477
|
+
|
|
478
|
+
```ruby
|
|
479
|
+
result = Capybara::Screenshot::Diff.compare("baseline.png", "current.png")
|
|
480
|
+
result.quick_equal? # => true if byte-identical
|
|
481
|
+
result.different? # => true if visually different
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
**Use cases:**
|
|
485
|
+
- PDF regression testing
|
|
486
|
+
- Generated image validation
|
|
487
|
+
- CI artifact verification
|
|
488
|
+
|
|
489
|
+
---
|
|
490
|
+
|
|
491
|
+
### Perceptual Color Distance (Anti-aliasing Fix)
|
|
492
|
+
|
|
493
|
+
Eliminate false positives from font rendering differences:
|
|
494
|
+
|
|
495
|
+
```ruby
|
|
496
|
+
# Global configuration
|
|
497
|
+
Capybara::Screenshot::Diff.perceptual_threshold = 2.0
|
|
498
|
+
|
|
499
|
+
# Or per-screenshot
|
|
500
|
+
screenshot 'dashboard', perceptual_threshold: 2.0
|
|
501
|
+
```
|
|
502
|
+
|
|
503
|
+
**dE00 Scale Reference:**
|
|
504
|
+
- `< 1.0` — Not perceptible by human eyes
|
|
505
|
+
- `1-2` — Perceptible through close observation (anti-aliasing, font hinting)
|
|
506
|
+
- `2-10` — Perceptible at a glance (color shifts, layout changes)
|
|
507
|
+
- `> 10` — Clearly different colors
|
|
508
|
+
|
|
509
|
+
**Why use this:** If you see false positives from font rendering differences across CI environments.
|
|
510
|
+
|
|
511
|
+
---
|
|
512
|
+
|
|
513
|
+
### `assert_no_screenshot_changes`
|
|
514
|
+
|
|
515
|
+
Assert that an action produces no visual change:
|
|
516
|
+
|
|
517
|
+
```ruby
|
|
518
|
+
test "clicking cancel doesn't change page" do
|
|
519
|
+
visit '/edit'
|
|
520
|
+
screenshot 'before_cancel'
|
|
521
|
+
|
|
522
|
+
click_button 'Cancel'
|
|
523
|
+
|
|
524
|
+
assert_no_screenshot_changes 'after_cancel'
|
|
525
|
+
end
|
|
526
|
+
```
|
|
527
|
+
|
|
528
|
+
---
|
|
529
|
+
|
|
530
|
+
### Simplified Configuration
|
|
531
|
+
|
|
532
|
+
Use the new `Diff.configure` block:
|
|
533
|
+
|
|
534
|
+
```ruby
|
|
535
|
+
# In test_helper.rb — one line, that's it
|
|
536
|
+
Capybara::Screenshot::Diff.configure do |screenshot, diff|
|
|
537
|
+
screenshot.window_size = [1280, 1024]
|
|
538
|
+
screenshot.stability_time_limit = 1
|
|
539
|
+
diff.driver = :vips
|
|
540
|
+
diff.tolerance = 0.0005
|
|
541
|
+
end
|
|
542
|
+
```
|
|
543
|
+
|
|
544
|
+
---
|
|
545
|
+
|
|
546
|
+
## Performance Improvements
|
|
547
|
+
|
|
548
|
+
Enjoy faster screenshot comparisons:
|
|
549
|
+
|
|
550
|
+
- **ChunkyPNG:** Eliminated array allocations in shift-detection (~30% faster for large images)
|
|
551
|
+
- **VIPS:** Cached computations at construction (~15% faster)
|
|
552
|
+
- **General:** Memoized region area size, replaced closures with blocks
|
|
553
|
+
|
|
554
|
+
**No action required** — these are automatic improvements.
|
|
555
|
+
|
|
556
|
+
---
|
|
557
|
+
|
|
558
|
+
## Ruby & Rails Compatibility
|
|
559
|
+
|
|
560
|
+
### Supported Versions
|
|
561
|
+
|
|
562
|
+
- **Ruby:** 3.2, 3.3, 3.4, 3.5 (new!), 4.0 (new!)
|
|
563
|
+
- **Rails:** 7.1, 7.2, 8.0
|
|
564
|
+
|
|
565
|
+
### Upgrade Notes
|
|
566
|
+
|
|
567
|
+
**Ruby 4.0:** Fully compatible! If you see DSLStub ordering issues, they're fixed in v1.12.0.
|
|
568
|
+
|
|
569
|
+
**Rails 8.0:** Works out of the box with updated dependencies.
|
|
570
|
+
|
|
571
|
+
---
|
|
572
|
+
|
|
573
|
+
## Testing Your Upgrade
|
|
574
|
+
|
|
575
|
+
### Step 1: Update Gemfile
|
|
576
|
+
|
|
577
|
+
```ruby
|
|
578
|
+
gem 'capybara-screenshot-diff', '~> 1.12.0'
|
|
579
|
+
```
|
|
580
|
+
|
|
581
|
+
### Step 2: Bundle Update
|
|
582
|
+
|
|
583
|
+
```bash
|
|
584
|
+
bundle update capybara-screenshot-diff
|
|
585
|
+
```
|
|
586
|
+
|
|
587
|
+
### Step 3: Run Tests
|
|
588
|
+
|
|
589
|
+
```bash
|
|
590
|
+
bundle exec rake test
|
|
591
|
+
```
|
|
592
|
+
|
|
593
|
+
### Step 4: Check for New Screenshot Failures
|
|
594
|
+
|
|
595
|
+
If tests fail with new screenshot errors in CI:
|
|
596
|
+
|
|
597
|
+
1. **Option A:** Commit the new baselines (recommended if changes are intentional)
|
|
598
|
+
2. **Option B:** Set `fail_if_new = false` temporarily (not recommended long-term)
|
|
599
|
+
|
|
600
|
+
### Step 5: Enable HTML Reporter (Optional)
|
|
601
|
+
|
|
602
|
+
```ruby
|
|
603
|
+
require 'capybara_screenshot_diff/reporters/html'
|
|
604
|
+
```
|
|
605
|
+
|
|
606
|
+
Run tests and open `doc/screenshots/snap_diff_report.html` to review differences.
|
|
607
|
+
|
|
608
|
+
---
|
|
609
|
+
|
|
610
|
+
## Troubleshooting
|
|
611
|
+
|
|
612
|
+
### "Tests fail with new screenshots in CI"
|
|
613
|
+
|
|
614
|
+
**Cause:** `fail_if_new` now defaults to `true` in CI
|
|
615
|
+
|
|
616
|
+
**Solution:**
|
|
617
|
+
|
|
618
|
+
```bash
|
|
619
|
+
# Commit the new baselines
|
|
620
|
+
git add doc/screenshots/
|
|
621
|
+
git commit -m "Add screenshot baselines for v1.12.0 upgrade"
|
|
622
|
+
```
|
|
623
|
+
|
|
624
|
+
Or temporarily allow them:
|
|
625
|
+
|
|
626
|
+
```ruby
|
|
627
|
+
Capybara::Screenshot::Diff.fail_if_new = false
|
|
628
|
+
```
|
|
629
|
+
|
|
630
|
+
### "Screenshots look different after upgrade"
|
|
631
|
+
|
|
632
|
+
**Cause:** `blur_active_element` and `hide_caret` now default to `true`
|
|
633
|
+
|
|
634
|
+
**Solution:** Restore v1.x behavior temporarily:
|
|
635
|
+
|
|
636
|
+
```ruby
|
|
637
|
+
Capybara::Screenshot.blur_active_element = false
|
|
638
|
+
Capybara::Screenshot.hide_caret = false
|
|
639
|
+
```
|
|
640
|
+
|
|
641
|
+
Then re-record baselines with the new defaults (recommended):
|
|
642
|
+
|
|
643
|
+
```bash
|
|
644
|
+
# Delete old baselines
|
|
645
|
+
rm doc/screenshots/*.png
|
|
646
|
+
|
|
647
|
+
# Run tests to generate new baselines
|
|
648
|
+
bundle exec rake test
|
|
649
|
+
|
|
650
|
+
# Commit new baselines
|
|
651
|
+
git add doc/screenshots/
|
|
652
|
+
git commit -m "Re-record baselines with v1.12.0 defaults"
|
|
653
|
+
```
|
|
654
|
+
|
|
655
|
+
### "NoMethodError on internal class"
|
|
656
|
+
|
|
657
|
+
**Cause:** Using internal APIs that were refactored
|
|
658
|
+
|
|
659
|
+
**Solution:** Use the public API instead. Check the documentation for the correct interface.
|
|
660
|
+
|
|
661
|
+
---
|
|
662
|
+
|
|
663
|
+
## Rollback Plan
|
|
664
|
+
|
|
665
|
+
If you need to rollback:
|
|
666
|
+
|
|
667
|
+
```ruby
|
|
668
|
+
# Pin to previous version
|
|
669
|
+
gem 'capybara-screenshot-diff', '~> 1.12.0'
|
|
670
|
+
```
|
|
671
|
+
|
|
672
|
+
```bash
|
|
673
|
+
bundle update capybara-screenshot-diff
|
|
674
|
+
```
|
|
675
|
+
|
|
676
|
+
All screenshot baselines are compatible — no data loss.
|
|
677
|
+
|
|
678
|
+
---
|
|
679
|
+
|
|
680
|
+
## Need Help?
|
|
681
|
+
|
|
682
|
+
- **Documentation:** [README.md](README.md)
|
|
683
|
+
- **Changelog:** [CHANGELOG.md](CHANGELOG.md)
|
|
684
|
+
- **Issues:** [GitHub Issues](https://github.com/snap-diff/snap_diff-capybara/issues)
|
|
685
|
+
- **DeepWiki:** [Code Documentation](https://deepwiki.com/snap-diff/snap_diff-capybara)
|
|
686
|
+
|
|
687
|
+
---
|
|
688
|
+
|
|
689
|
+
## Summary Checklist
|
|
690
|
+
|
|
691
|
+
- [ ] Update gem version to `~> 1.12.0`
|
|
692
|
+
- [ ] Run `bundle update capybara-screenshot-diff`
|
|
693
|
+
- [ ] Run test suite
|
|
694
|
+
- [ ] Check for new screenshot failures in CI
|
|
695
|
+
- [ ] Decide on `fail_if_new` behavior
|
|
696
|
+
- [ ] Decide on `blur_active_element` and `hide_caret` defaults
|
|
697
|
+
- [ ] Enable HTML reporter (optional)
|
|
698
|
+
- [ ] Re-record baselines if needed
|
|
699
|
+
- [ ] Commit changes
|
|
700
|
+
- [ ] Review upgrade issues in [GitHub Issues](https://github.com/snap-diff/snap_diff-capybara/issues)
|
|
701
|
+
|
|
702
|
+
**Congratulations!** You're now running v1.12.0 🎉
|