snap_diff-capybara 0.0.1 → 2.0.0.alpha1

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.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +167 -0
  3. data/CODE_OF_CONDUCT.md +129 -0
  4. data/LICENSE.txt +21 -0
  5. data/Rakefile +65 -0
  6. data/capybara-screenshot-diff.gemspec +29 -0
  7. data/docs/RELEASE_PREP.md +44 -0
  8. data/docs/UPGRADING.md +475 -0
  9. data/docs/architecture.md +267 -0
  10. data/docs/ci-integration.md +238 -0
  11. data/docs/configuration.md +395 -0
  12. data/docs/docker-testing.md +24 -0
  13. data/docs/drivers.md +102 -0
  14. data/docs/framework-setup.md +87 -0
  15. data/docs/images/snap_diff_annotated.png +0 -0
  16. data/docs/images/snap_diff_web_ui.png +0 -0
  17. data/docs/migration-guide.md +286 -0
  18. data/docs/organization.md +204 -0
  19. data/docs/reporters.md +46 -0
  20. data/docs/thread_safety.md +112 -0
  21. data/gems.rb +39 -0
  22. data/lib/capybara/screenshot/diff/annotation_service.rb +7 -0
  23. data/lib/capybara/screenshot/diff/area_calculator.rb +7 -0
  24. data/lib/capybara/screenshot/diff/browser_helpers.rb +7 -0
  25. data/lib/capybara/screenshot/diff/config_legacy.rb +113 -0
  26. data/lib/capybara/screenshot/diff/cucumber.rb +3 -0
  27. data/lib/capybara/screenshot/diff/difference.rb +8 -0
  28. data/lib/capybara/screenshot/diff/drivers/base_driver.rb +9 -0
  29. data/lib/capybara/screenshot/diff/drivers/chunky_png_driver.rb +7 -0
  30. data/lib/capybara/screenshot/diff/drivers/vips_driver.rb +7 -0
  31. data/lib/capybara/screenshot/diff/drivers.rb +9 -0
  32. data/lib/capybara/screenshot/diff/image_compare.rb +12 -0
  33. data/lib/capybara/screenshot/diff/image_preprocessor.rb +7 -0
  34. data/lib/capybara/screenshot/diff/os.rb +14 -0
  35. data/lib/capybara/screenshot/diff/region.rb +107 -0
  36. data/lib/capybara/screenshot/diff/reporters/default.rb +109 -0
  37. data/lib/capybara/screenshot/diff/screenshot_matcher.rb +7 -0
  38. data/lib/capybara/screenshot/diff/screenshoter.rb +7 -0
  39. data/lib/capybara/screenshot/diff/stable_screenshoter.rb +7 -0
  40. data/lib/capybara/screenshot/diff/utils.rb +7 -0
  41. data/lib/capybara/screenshot/diff/vcs.rb +7 -0
  42. data/lib/capybara/screenshot/diff/version.rb +15 -0
  43. data/lib/capybara/screenshot/diff.rb +3 -0
  44. data/lib/capybara-screenshot-diff.rb +3 -0
  45. data/lib/capybara_screenshot_diff/attempts_reporter.rb +7 -0
  46. data/lib/capybara_screenshot_diff/cucumber.rb +8 -0
  47. data/lib/capybara_screenshot_diff/dsl.rb +12 -0
  48. data/lib/capybara_screenshot_diff/error_with_filtered_backtrace.rb +8 -0
  49. data/lib/capybara_screenshot_diff/minitest.rb +14 -0
  50. data/lib/capybara_screenshot_diff/reporters/html.rb +7 -0
  51. data/lib/capybara_screenshot_diff/rspec.rb +8 -0
  52. data/lib/capybara_screenshot_diff/screenshot_assertion.rb +71 -0
  53. data/lib/capybara_screenshot_diff/screenshot_namer.rb +7 -0
  54. data/lib/capybara_screenshot_diff/snap.rb +7 -0
  55. data/lib/capybara_screenshot_diff/snap_manager.rb +7 -0
  56. data/lib/capybara_screenshot_diff/static.rb +9 -0
  57. data/lib/capybara_screenshot_diff.rb +50 -0
  58. data/lib/snap_diff/annotation_service.rb +84 -0
  59. data/lib/snap_diff/area_calculator.rb +56 -0
  60. data/lib/snap_diff/attempts_reporter.rb +51 -0
  61. data/lib/snap_diff/browser_helpers.rb +121 -0
  62. data/lib/snap_diff/capture/viewport.rb +40 -0
  63. data/lib/snap_diff/comparison.rb +238 -0
  64. data/lib/snap_diff/comparison_result.rb +104 -0
  65. data/lib/snap_diff/config.rb +78 -0
  66. data/lib/snap_diff/deprecation.rb +84 -0
  67. data/lib/snap_diff/driver.rb +37 -0
  68. data/lib/snap_diff/drivers/chunky_png_driver.rb +298 -0
  69. data/lib/snap_diff/drivers/vips_driver.rb +171 -0
  70. data/lib/snap_diff/drivers.rb +14 -0
  71. data/lib/snap_diff/dsl.rb +143 -0
  72. data/lib/snap_diff/error_with_filtered_backtrace.rb +32 -0
  73. data/lib/snap_diff/image_preprocessor.rb +68 -0
  74. data/lib/snap_diff/integrations/cucumber.rb +22 -0
  75. data/lib/snap_diff/integrations/minitest.rb +70 -0
  76. data/lib/snap_diff/integrations/rspec.rb +68 -0
  77. data/lib/snap_diff/legacy_shims.rb +99 -0
  78. data/lib/snap_diff/os.rb +17 -0
  79. data/lib/snap_diff/reporters/html.rb +143 -0
  80. data/lib/snap_diff/reporters/templates/report.html.erb +463 -0
  81. data/lib/snap_diff/reporting.rb +53 -0
  82. data/lib/snap_diff/screenshot_assertion.rb +143 -0
  83. data/lib/snap_diff/screenshot_matcher.rb +113 -0
  84. data/lib/snap_diff/screenshot_namer.rb +81 -0
  85. data/lib/snap_diff/screenshoter.rb +129 -0
  86. data/lib/snap_diff/snap.rb +66 -0
  87. data/lib/snap_diff/snap_manager.rb +125 -0
  88. data/lib/snap_diff/stable_screenshoter.rb +103 -0
  89. data/lib/snap_diff/static.rb +11 -0
  90. data/lib/snap_diff/utils.rb +38 -0
  91. data/lib/snap_diff/vcs.rb +35 -0
  92. data/lib/snap_diff/version.rb +5 -0
  93. data/lib/snap_diff.rb +65 -0
  94. metadata +160 -10
  95. data/README.md +0 -3
data/docs/UPGRADING.md ADDED
@@ -0,0 +1,475 @@
1
+ # Upgrading
2
+
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
89
+
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.
91
+
92
+ **Estimated upgrade time:** 5-15 minutes depending on your setup
93
+
94
+ ---
95
+
96
+ ## Quick Upgrade Path (Most Users)
97
+
98
+ For **most users**, upgrading is as simple as:
99
+
100
+ ```ruby
101
+ # In your Gemfile
102
+ gem 'capybara-screenshot-diff', '~> 1.12.0'
103
+ ```
104
+
105
+ ```bash
106
+ bundle update capybara-screenshot-diff
107
+ bundle exec rake test # Verify tests still pass
108
+ ```
109
+
110
+ **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.
111
+
112
+ ---
113
+
114
+ ## Breaking Changes & Migration Steps
115
+
116
+ ### 1. Default Behavior Changes (Most Important)
117
+
118
+ Three settings now have different defaults. This is the most likely source of unexpected test failures.
119
+
120
+ #### `blur_active_element` — Now defaults to `true`
121
+
122
+ **Before (v1.11.x):** Cursor blinking could delay screenshots
123
+ **After (v1.12.0):** Cursor is automatically hidden
124
+
125
+ **Action required:** Only if you want the old behavior
126
+
127
+ ```ruby
128
+ # To restore v1.x behavior:
129
+ Capybara::Screenshot.blur_active_element = false
130
+ ```
131
+
132
+ #### `hide_caret` — Now defaults to `true`
133
+
134
+ **Before (v1.11.x):** Input caret visible in screenshots
135
+ **After (v1.12.0):** Caret is transparent for stable screenshots
136
+
137
+ **Action required:** Only if you want the old behavior
138
+
139
+ ```ruby
140
+ # To restore v1.x behavior:
141
+ Capybara::Screenshot.hide_caret = false
142
+ ```
143
+
144
+ #### `fail_if_new` — Now defaults to `true` in CI
145
+
146
+ **Before (v1.11.x):** New screenshots allowed in CI
147
+ **After (v1.12.0):** New screenshots fail tests in CI (when `ENV['CI']` is set)
148
+
149
+ **Action required:** Only if you want to allow new screenshots in CI
150
+
151
+ ```ruby
152
+ # To allow new screenshots in CI:
153
+ Capybara::Screenshot::Diff.fail_if_new = false
154
+ ```
155
+
156
+ **Why this changed:** This prevents accidental baseline additions in CI pipelines. Most teams want this behavior.
157
+
158
+ ---
159
+
160
+ ### 2. SVN Support Removed
161
+
162
+ **Before (v1.11.x):** Could use SVN for version control
163
+ **After (v1.12.0):** Git only
164
+
165
+ **Action required:** If using SVN, migrate to Git
166
+
167
+ ```bash
168
+ # Check if you're using SVN for screenshots
169
+ git grep svn test/ # Look for svn commands in your tests
170
+ ```
171
+
172
+ If you find SVN usage:
173
+ 1. Export your SVN repository to Git
174
+ 2. Update your CI/CD to use Git
175
+ 3. Re-commit all screenshot baselines with Git
176
+
177
+ **Why this changed:** SVN support was rarely used and added maintenance burden.
178
+
179
+ ---
180
+
181
+ ### 3. ActiveSupport No Longer Required
182
+
183
+ **Before (v1.11.x):** ActiveSupport was a runtime dependency
184
+ **After (v1.12.0):** Pure Ruby, no ActiveSupport required
185
+
186
+ **Action required:** None (this is a positive change!)
187
+
188
+ If your project only had ActiveSupport because of this gem, you can now remove it:
189
+
190
+ ```ruby
191
+ # In your Gemfile — can likely be removed if only used for this gem
192
+ # gem 'activesupport' # ← Remove if not used elsewhere
193
+ ```
194
+
195
+ **Why this changed:** Lighter installations, faster boot times.
196
+
197
+ ---
198
+
199
+ ### 4. Internal API Changes
200
+
201
+ **Before (v1.11.x):** Could use internal classes like `CaptureStrategy`, `ComparisonLoader`
202
+ **After (v1.12.0):** These have been inlined/refactored
203
+
204
+ **Action required:** Only if using internal APIs
205
+
206
+ Check your codebase:
207
+
208
+ ```bash
209
+ # Search for internal API usage
210
+ grep -r "CaptureStrategy" test/ lib/
211
+ grep -r "ComparisonLoader" test/ lib/
212
+ grep -r "ScreenshotCoordinator" test/ lib/
213
+ grep -r "ImagePreprocessor" test/ lib/
214
+ ```
215
+
216
+ If you find usage, these were never part of the public API and should be replaced with the documented public API.
217
+
218
+ **Why this changed:** Simplified architecture, better performance, easier maintenance.
219
+
220
+ ---
221
+
222
+ ## New Features to Try
223
+
224
+ ### HTML Reporter (Recommended)
225
+
226
+ Get an interactive dashboard showing all screenshot differences:
227
+
228
+ ```ruby
229
+ # Add to test_helper.rb or spec_helper.rb
230
+ require 'capybara_screenshot_diff/reporters/html'
231
+ ```
232
+
233
+ After running tests:
234
+
235
+ ```bash
236
+ open doc/screenshots/snap_diff_report.html
237
+ ```
238
+
239
+ **Features:**
240
+ - Side-by-side comparison with diff toggle
241
+ - Thumbnail sidebar for navigation
242
+ - Search functionality
243
+ - Summary statistics
244
+
245
+ ---
246
+
247
+ ### Standalone Image Comparison
248
+
249
+ Compare any two images without Capybara or a browser:
250
+
251
+ ```ruby
252
+ result = Capybara::Screenshot::Diff.compare("baseline.png", "current.png")
253
+ result.quick_equal? # => true if byte-identical
254
+ result.different? # => true if visually different
255
+ ```
256
+
257
+ **Use cases:**
258
+ - PDF regression testing
259
+ - Generated image validation
260
+ - CI artifact verification
261
+
262
+ ---
263
+
264
+ ### Perceptual Color Distance (Anti-aliasing Fix)
265
+
266
+ Eliminate false positives from font rendering differences:
267
+
268
+ ```ruby
269
+ # Global configuration
270
+ Capybara::Screenshot::Diff.perceptual_threshold = 2.0
271
+
272
+ # Or per-screenshot
273
+ screenshot 'dashboard', perceptual_threshold: 2.0
274
+ ```
275
+
276
+ **dE00 Scale Reference:**
277
+ - `< 1.0` — Not perceptible by human eyes
278
+ - `1-2` — Perceptible through close observation (anti-aliasing, font hinting)
279
+ - `2-10` — Perceptible at a glance (color shifts, layout changes)
280
+ - `> 10` — Clearly different colors
281
+
282
+ **Why use this:** If you see false positives from font rendering differences across CI environments.
283
+
284
+ ---
285
+
286
+ ### `assert_no_screenshot_changes`
287
+
288
+ Assert that an action produces no visual change:
289
+
290
+ ```ruby
291
+ test "clicking cancel doesn't change page" do
292
+ visit '/edit'
293
+ screenshot 'before_cancel'
294
+
295
+ click_button 'Cancel'
296
+
297
+ assert_no_screenshot_changes 'after_cancel'
298
+ end
299
+ ```
300
+
301
+ ---
302
+
303
+ ### Simplified Configuration
304
+
305
+ Use the new `Diff.configure` block:
306
+
307
+ ```ruby
308
+ # In test_helper.rb — one line, that's it
309
+ Capybara::Screenshot::Diff.configure do |screenshot, diff|
310
+ screenshot.window_size = [1280, 1024]
311
+ screenshot.stability_time_limit = 1
312
+ diff.driver = :vips
313
+ diff.tolerance = 0.0005
314
+ end
315
+ ```
316
+
317
+ ---
318
+
319
+ ## Performance Improvements
320
+
321
+ Enjoy faster screenshot comparisons:
322
+
323
+ - **ChunkyPNG:** Eliminated array allocations in shift-detection (~30% faster for large images)
324
+ - **VIPS:** Cached computations at construction (~15% faster)
325
+ - **General:** Memoized region area size, replaced closures with blocks
326
+
327
+ **No action required** — these are automatic improvements.
328
+
329
+ ---
330
+
331
+ ## Ruby & Rails Compatibility
332
+
333
+ ### Supported Versions
334
+
335
+ - **Ruby:** 3.2, 3.3, 3.4, 3.5 (new!), 4.0 (new!)
336
+ - **Rails:** 7.1, 7.2, 8.0
337
+
338
+ ### Upgrade Notes
339
+
340
+ **Ruby 4.0:** Fully compatible! If you see DSLStub ordering issues, they're fixed in v1.12.0.
341
+
342
+ **Rails 8.0:** Works out of the box with updated dependencies.
343
+
344
+ ---
345
+
346
+ ## Testing Your Upgrade
347
+
348
+ ### Step 1: Update Gemfile
349
+
350
+ ```ruby
351
+ gem 'capybara-screenshot-diff', '~> 1.12.0'
352
+ ```
353
+
354
+ ### Step 2: Bundle Update
355
+
356
+ ```bash
357
+ bundle update capybara-screenshot-diff
358
+ ```
359
+
360
+ ### Step 3: Run Tests
361
+
362
+ ```bash
363
+ bundle exec rake test
364
+ ```
365
+
366
+ ### Step 4: Check for New Screenshot Failures
367
+
368
+ If tests fail with new screenshot errors in CI:
369
+
370
+ 1. **Option A:** Commit the new baselines (recommended if changes are intentional)
371
+ 2. **Option B:** Set `fail_if_new = false` temporarily (not recommended long-term)
372
+
373
+ ### Step 5: Enable HTML Reporter (Optional)
374
+
375
+ ```ruby
376
+ require 'capybara_screenshot_diff/reporters/html'
377
+ ```
378
+
379
+ Run tests and open `doc/screenshots/snap_diff_report.html` to review differences.
380
+
381
+ ---
382
+
383
+ ## Troubleshooting
384
+
385
+ ### "Tests fail with new screenshots in CI"
386
+
387
+ **Cause:** `fail_if_new` now defaults to `true` in CI
388
+
389
+ **Solution:**
390
+
391
+ ```bash
392
+ # Commit the new baselines
393
+ git add doc/screenshots/
394
+ git commit -m "Add screenshot baselines for v1.12.0 upgrade"
395
+ ```
396
+
397
+ Or temporarily allow them:
398
+
399
+ ```ruby
400
+ Capybara::Screenshot::Diff.fail_if_new = false
401
+ ```
402
+
403
+ ### "Screenshots look different after upgrade"
404
+
405
+ **Cause:** `blur_active_element` and `hide_caret` now default to `true`
406
+
407
+ **Solution:** Restore v1.x behavior temporarily:
408
+
409
+ ```ruby
410
+ Capybara::Screenshot.blur_active_element = false
411
+ Capybara::Screenshot.hide_caret = false
412
+ ```
413
+
414
+ Then re-record baselines with the new defaults (recommended):
415
+
416
+ ```bash
417
+ # Delete old baselines
418
+ rm doc/screenshots/*.png
419
+
420
+ # Run tests to generate new baselines
421
+ bundle exec rake test
422
+
423
+ # Commit new baselines
424
+ git add doc/screenshots/
425
+ git commit -m "Re-record baselines with v1.12.0 defaults"
426
+ ```
427
+
428
+ ### "NoMethodError on internal class"
429
+
430
+ **Cause:** Using internal APIs that were refactored
431
+
432
+ **Solution:** Use the public API instead. Check the documentation for the correct interface.
433
+
434
+ ---
435
+
436
+ ## Rollback Plan
437
+
438
+ If you need to rollback:
439
+
440
+ ```ruby
441
+ # Pin to previous version
442
+ gem 'capybara-screenshot-diff', '~> 1.12.0'
443
+ ```
444
+
445
+ ```bash
446
+ bundle update capybara-screenshot-diff
447
+ ```
448
+
449
+ All screenshot baselines are compatible — no data loss.
450
+
451
+ ---
452
+
453
+ ## Need Help?
454
+
455
+ - **Documentation:** [README.md](README.md)
456
+ - **Changelog:** [CHANGELOG.md](CHANGELOG.md)
457
+ - **Issues:** [GitHub Issues](https://github.com/snap-diff/snap_diff-capybara/issues)
458
+ - **DeepWiki:** [Code Documentation](https://deepwiki.com/snap-diff/snap_diff-capybara)
459
+
460
+ ---
461
+
462
+ ## Summary Checklist
463
+
464
+ - [ ] Update gem version to `~> 1.12.0`
465
+ - [ ] Run `bundle update capybara-screenshot-diff`
466
+ - [ ] Run test suite
467
+ - [ ] Check for new screenshot failures in CI
468
+ - [ ] Decide on `fail_if_new` behavior
469
+ - [ ] Decide on `blur_active_element` and `hide_caret` defaults
470
+ - [ ] Enable HTML reporter (optional)
471
+ - [ ] Re-record baselines if needed
472
+ - [ ] Commit changes
473
+ - [ ] Review upgrade issues in [GitHub Issues](https://github.com/snap-diff/snap_diff-capybara/issues)
474
+
475
+ **Congratulations!** You're now running v1.12.0 🎉