Skip to content

test: migrate suite to SnapDiff canonical names - #221

Merged
pftg merged 1 commit into
masterfrom
refactor/v2-test-migration
Aug 22, 2026
Merged

test: migrate suite to SnapDiff canonical names#221
pftg merged 1 commit into
masterfrom
refactor/v2-test-migration

Conversation

@pftg

@pftg pftg commented Aug 22, 2026

Copy link
Copy Markdown
Collaborator

v2 step 8 (ADR-004): the test suite now exercises the canonical SnapDiff:: names everywhere except tests whose purpose IS the legacy surface. Test-only change — no lib/ edits.

What changed

1. Old-name references migrated to SnapDiff:: equivalents (26 test files): ImageCompareComparison, DifferenceComparisonResult, SnapManager, ScreenshotAssertion, Vcs, StableScreenshoter, Screenshoter, BrowserHelpers, Reporters::HTML, Snap, DSL, plus the ScreenshoterStub superclass. Test-class nesting under the old modules was kept (references migrated, classes not renamed, per proportionate-churn).

2. Suite-wide deprecation silencing replaced with a loud guard. #218's global SnapDiff.silence_deprecations = true is gone. Instead test_helper installs a Warning.extend hook that raises on any [snap_diff deprecation] warning, so accidental old-name use inside the suite fails at the resolution site. Legacy-surface tests opt out per test:

  • namespace_forwarding_test silences deprecations in its own setup/teardown (it resolves every mapped old name on purpose);
  • legacy_namespace_deprecation_test / snap_diff_deprecation_test set SnapDiffDeprecationGuard.expected around the warnings they capture and assert on (a module flag, not a thread-local, so warnings emitted from threads a test spawns are covered — the deprecation thread-safety test needs exactly that).

3. Deliberate legacy keeps (each scoped + documented in place):

  • test/unit/namespace_forwarding_test.rb, test/unit/legacy_namespace_deprecation_test.rb, test/unit/support_load_probe_test.rb — their purpose is the legacy surface.
  • test/unit/snap_diff_test.rb — the alias-pinning test ("SnapDiff::Comparison aliases …ImageCompare") keeps the old name with local silencing; its sibling assertions migrated.
  • test/unit/static_test.rb — one of three cases now pins the legacy CapybaraScreenshotDiff.serve forwarder; the other two use canonical SnapDiff.serve.
  • test/fixtures/rspec_*.rb — keep require "capybara_screenshot_diff/rspec" (legacy entry point under test); incidental SnapManager refs migrated.
  • test/system_test_case.rb — keeps include Capybara::Screenshot::Diff (the v1 mixin path) and include CapybaraScreenshotDiff::Minitest::Assertions, so the integration suite still exercises the legacy DSL entry end-to-end.
  • Not migrated because they are the canonical current homes, not shims: Capybara::Screenshot/Diff mattr config accessors (storage of record per SnapDiff::Config delegation), Capybara::Screenshot::Diff::AVAILABLE_DRIVERS, CapybaraScreenshotDiff session surface (reset/verify/registry/…) and error classes (ExpectationNotMet etc.), top-level Region, Capybara::Screenshot::Diff::Reporters::Default.

Shim-coverage gaps checked: the legacy DSL mixin (include Capybara::Screenshot::Diff) stays covered via system_test_case; the legacy rspec/minitest entry points via the fixtures and entry-point probes; TestMethods does not exist in lib — no new tests needed. Finding (out of scope for this test-only PR): the session surface (reset/verify/registry) and error classes exist only on CapybaraScreenshotDiff, with no SnapDiff equivalent yet.

Evidence

  • Baseline (6df54dc) and after: rake test:unit 488 runs / 0 failures / 0 errors / 0 skips; rake test 521 runs / 0 failures / 6 skips — unchanged run counts, zero deprecation output on stderr.
  • Empirical sweep: ran the unit suite unsilenced before migrating — 24 distinct old constants warned; after migration: 0.
  • Mutation check: reintroducing Capybara::Screenshot::Diff::Vcs in migrated dsl_test.rbRuntimeError: old-namespace constant resolved inside the test suite … raised from the guard (then restored).
  • standardrb test/ — 62 files, no offenses.

🤖 Generated with Claude Code

Summary by Sourcery

Make the test suite validate canonical SnapDiff APIs and fail loudly on unintended legacy namespace usage.

Enhancements:

  • Migrate the test suite to exercise canonical SnapDiff:: names while retaining explicitly scoped coverage for legacy namespaces and entry points.
  • Replace global deprecation silencing with a suite-wide guard that fails on unexpected legacy-name warnings and supports intentional deprecation tests.

Tests:

  • Update test references, fixtures, helpers, and integration coverage to use canonical APIs while preserving deliberate legacy-surface assertions.

v2 step 8 (ADR-004): the test suite now exercises the canonical SnapDiff::
names everywhere except tests whose purpose IS the legacy surface.

- Migrate every deprecated old-namespace constant reference in test/ to
  its SnapDiff:: equivalent (ImageCompare -> Comparison, Difference ->
  ComparisonResult, SnapManager, ScreenshotAssertion, Vcs,
  StableScreenshoter, Screenshoter, BrowserHelpers, Reporters::HTML,
  Snap, DSL, ...).
- Replace the suite-wide SnapDiff.silence_deprecations = true (from #218)
  with the opposite guard: a Warning hook in test_helper that RAISES on
  any [snap_diff deprecation] warning, so accidental old-name use inside
  the suite fails loud at the resolution site. Legacy-surface tests opt
  out per test: namespace_forwarding_test silences deprecations in its
  own setup; legacy_namespace_deprecation_test and
  snap_diff_deprecation_test flag their captured warnings as expected
  (module flag, not thread-local, so warnings from spawned threads are
  covered too).
- Deliberate legacy keeps, each scoped and documented in place:
  namespace_forwarding_test / legacy_namespace_deprecation_test /
  support_load_probe_test (their purpose), snap_diff_test's alias-pinning
  test, one static_test case pinning the CapybaraScreenshotDiff.serve
  forwarder, the legacy entry-point requires in the rspec fixtures, and
  system_test_case's 'include Capybara::Screenshot::Diff' v1 mixin path.

rake test:unit 488/0/0 and rake test 521/0/6 -- unchanged run counts,
zero deprecation output. Mutation-checked: reintroducing one old
constant in a migrated file makes the guard raise.
@sourcery-ai

sourcery-ai Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Migrates the test suite from legacy CapybaraScreenshotDiff/Capybara::Screenshot::Diff constant names to the canonical SnapDiff:: API, and replaces the prior global deprecation silencing with an explicit guard that raises on unexpected shim usage, while keeping a handful of targeted legacy-surface tests and entry points intact and documented.

File-Level Changes

Change Details Files
Migrate tests from legacy CapybaraScreenshotDiff / Capybara::Screenshot::Diff constants to canonical SnapDiff:: names.
  • Repoint usages of ImageCompare to SnapDiff::Comparison and Difference to SnapDiff::ComparisonResult in helpers and driver contract tests.
  • Replace CapybaraScreenshotDiff::SnapManager and related calls (snapshot, path_for, cleanup!, screenshots, instance.root) with SnapDiff::SnapManager equivalents.
  • Switch DSL mixin, screenshot assertion classes, browser helpers, reporters, Vcs, StableScreenshoter, Screenshoter, and ScreenshotMatcher references to their SnapDiff:: counterparts.
  • Update non-Minitest and integration tests (including rspec fixtures and DSL stubs) to depend on SnapDiff::DSL and SnapDiff::.* services while preserving legacy require/include entry points where intentionally under test.
  • Keep test class/module nesting under CapybaraScreenshotDiff/Capybara::Screenshot::Diff where appropriate, only migrating constant references to avoid noisy renames.
test/fixtures/rspec_after_hook_order_masking_spec.rb
test/fixtures/rspec_pending_masking_spec.rb
test/fixtures/rspec_spec.rb
test/integration/browser_screenshot_test.rb
test/integration/report_screenshot_test.rb
test/integration/test_methods_system_test.rb
test/support/capybara_screenshot_diff/dsl_stub.rb
test/support/driver_contract_tests.rb
test/support/non_minitest_assertions.rb
test/support/screenshoter_stub.rb
test/system_test_case.rb
test/test_helper.rb
test/unit/attempts_reporter_test.rb
test/unit/diff_test.rb
test/unit/dsl_test.rb
test/unit/minitest_assertions_test.rb
test/unit/reporter_interplay_test.rb
test/unit/screenshot_assertion_test.rb
test/unit/screenshot_matcher_test.rb
test/unit/screenshot_test.rb
test/unit/screenshoter_test.rb
test/unit/snap_diff_test.rb
test/unit/stable_screenshoter_test.rb
test/unit/static_test.rb
Introduce a suite-wide deprecation guard that raises on unexpected legacy shim usage and let specific tests opt out.
  • Remove global SnapDiff.silence_deprecations = true from test_helper and instead define a SnapDiffDeprecationGuard module that hooks Warning.warn.
  • In the guard, raise when a message contains the snap_diff deprecation tag and no expectation flag is set, otherwise delegate to the original warn.
  • Extend Warning with SnapDiffDeprecationGuard in test_helper so it is active across the suite, and document the non-thread-local expected flag semantics.
  • Mark legacy_namespace_deprecation_test and snap_diff_deprecation_test as expected emitters by toggling SnapDiffDeprecationGuard.expected around their warning assertions.
  • Add per-test silencing of SnapDiff.silence_deprecations in namespace_forwarding_test and the alias-pinning test in snap_diff_test so their deliberate legacy constant resolutions do not trip the guard.
test/test_helper.rb
test/unit/legacy_namespace_deprecation_test.rb
test/unit/namespace_forwarding_test.rb
test/unit/snap_diff_deprecation_test.rb
test/unit/snap_diff_test.rb
Preserve and document intentional legacy entry points and surfaces under test.
  • Keep require "capybara_screenshot_diff/rspec" in rspec fixtures while migrating incidental SnapManager references to SnapDiff::SnapManager.
  • Retain include Capybara::Screenshot::Diff and CapybaraScreenshotDiff::Minitest::Assertions in system_test_case to ensure the integration suite still exercises the v1 DSL mixin path end-to-end.
  • Explicitly leave Capybara::Screenshot/Diff mattr config accessors, AVAILABLE_DRIVERS, CapybaraScreenshotDiff session surface and error classes, Region, and the default reporter on their existing namespaces since they are current homes rather than shims.
  • Annotate the StaticTest case that uses CapybaraScreenshotDiff.serve as deliberately pinning the legacy forwarder while other StaticTest cases call SnapDiff.serve.
  • Document in tests where legacy use is necessary (namespace_forwarding_test, legacy_namespace_deprecation_test, support_load_probe_test, rspec fixtures, system_test_case) that they are exercising the legacy surface by design.
test/fixtures/rspec_spec.rb
test/system_test_case.rb
test/unit/static_test.rb
test/unit/namespace_forwarding_test.rb
test/unit/legacy_namespace_deprecation_test.rb
test/unit/support_load_probe_test.rb

Possibly linked issues

  • #ADR-004: The test-only migration advances ADR-004’s SnapDiff canonical namespace transition and validates legacy shims remain intentional.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Aug 22, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@pftg, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 18 minutes

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

Wait for the limit to reset, then comment @coderabbitai review or push new commits to the PR.

An organization admin can change what happens after included review limits in Billing.

How do review limits work?

CodeRabbit enforces per-developer PR review limits within each organization.

For paid Pro and Pro+ reviews, CodeRabbit uses a developer's included PR review attempts over the past 7 days to set the current hourly allowance. At typical activity levels, the full plan allowance applies. Higher sustained activity can lower the allowance until earlier attempts leave the 7-day window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 084b318f-0b00-492e-8944-b6d8e1994417

📥 Commits

Reviewing files that changed from the base of the PR and between 6df54dc and ac02b6e.

📒 Files selected for processing (27)
  • test/fixtures/rspec_after_hook_order_masking_spec.rb
  • test/fixtures/rspec_pending_masking_spec.rb
  • test/fixtures/rspec_spec.rb
  • test/integration/browser_screenshot_test.rb
  • test/integration/report_screenshot_test.rb
  • test/integration/test_methods_system_test.rb
  • test/support/capybara_screenshot_diff/dsl_stub.rb
  • test/support/driver_contract_tests.rb
  • test/support/non_minitest_assertions.rb
  • test/support/screenshoter_stub.rb
  • test/system_test_case.rb
  • test/test_helper.rb
  • test/unit/attempts_reporter_test.rb
  • test/unit/diff_test.rb
  • test/unit/dsl_test.rb
  • test/unit/legacy_namespace_deprecation_test.rb
  • test/unit/minitest_assertions_test.rb
  • test/unit/namespace_forwarding_test.rb
  • test/unit/reporter_interplay_test.rb
  • test/unit/screenshot_assertion_test.rb
  • test/unit/screenshot_matcher_test.rb
  • test/unit/screenshot_test.rb
  • test/unit/screenshoter_test.rb
  • test/unit/snap_diff_deprecation_test.rb
  • test/unit/snap_diff_test.rb
  • test/unit/stable_screenshoter_test.rb
  • test/unit/static_test.rb

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@pftg
pftg merged commit 35f083a into master Aug 22, 2026
8 checks passed
@pftg
pftg deleted the refactor/v2-test-migration branch August 22, 2026 21:08
pftg added a commit that referenced this pull request Aug 22, 2026
…napDiff homes (ADR-008 steps 4+5) (#227)

* refactor: move reporters/default.rb to its snap_diff home (mv only)

Pure git mv so the rename survives with history; the rewrap to
SnapDiff::Reporters::Default and the old-path forwarder land in the
next commit.

* refactor: default reporter becomes SnapDiff::Reporters::Default (ADR-008 step 4)

The last old-namespace CLASS dependency in the core: comparison.rb now
requires and constructs SnapDiff::Reporters::Default. The old constant
Capybara::Screenshot::Diff::Reporters::Default joins the legacy_shims
mapping (lazy, warn-once, same-object -- pinned by the MAPPING-driven
forwarding and deprecation tests, now 30 pairs). The old file path stays
requirable as a forwarder.

Test edits are canonical-name migrations only (per the #221 policy --
the raise-on-deprecation guard would trip on the old name otherwise):
default_test.rb and image_compare_test.rb reference
SnapDiff::Reporters::Default; no expectations changed.

* refactor: images-holder struct becomes SnapDiff::Comparison::Images (ADR-008 step 5a)

Resolves the Comparison name collision: the images-holder struct that
lived at Capybara::Screenshot::Diff::Comparison (blocked from a SnapDiff
home because SnapDiff::Comparison is the comparator class) is now nested
inside the comparator as SnapDiff::Comparison::Images. The old constant
joins the legacy_shims mapping (lazy, warn-once, same-object -- 31 pairs
now). comparison.rb constructs Images directly; no old-namespace class
reference remains in the compare path.

Test edits are canonical-name migrations only (per the #221 policy;
the raise-on-deprecation guard would otherwise trip): the struct
constructions in driver_contract_tests, image_preprocessor_test,
annotation_service_test and default_test now spell the canonical name.
No expectations changed.

* refactor: driver registry gets its SnapDiff home (ADR-008 step 5b)

SnapDiff::Drivers.loaded is now the canonical driver-class cache (ex
Capybara::Screenshot::Diff::LOADED_DRIVERS, which comparison.rb no
longer defines); the old constant stays as an EAGER same-object alias
in legacy_shims because user code registers custom drivers by mutating
the hash in place -- a lazy copy would silently drop registrations, and
warning on a supported surface would be noise.

SnapDiff::Drivers.available is the canonical reader for the detected
drivers list; the value itself stays on the eager
Capybara::Screenshot::Diff::AVAILABLE_DRIVERS constant (config_legacy
detection moment unchanged, and image_compare_test pins that constant
as the stub point for the no-drivers error path). Utils'
find_driver_class_for now reads both registries through the canonical
accessors, removing the last old-namespace reads from the core compare
path. Guard tests pin same-object identity and legacy-write ->
canonical-read visibility.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant