Skip to content

Commit bbf724f

Browse files
authored
refactor: split canonical vs legacy-surface tests (3.0 readiness) (#236)
* test: move the v1-surface tests into test/legacy/ and add rake test:canonical The five tests whose SUBJECT is the v1 compatibility surface now live in test/legacy/, so the 3.0 deletion is one more path on the same git rm: git rm -r lib/capybara* ... test/legacy A directory rather than a list in the Rakefile: nothing to keep in sync. - rake test unchanged, runs everything (today's gate) - rake test:canonical NEW, everything except test/legacy (the 3.0 gate) - rake test:unit test/unit + test/legacy, so the release gate keeps its coverage (legacy/ marks lifetime, not kind) errors_alias_test.rb was mixed: the four CapybaraScreenshotDiff::* alias pairs are v1 surface, the hierarchy assertions outlive them. Split rather than moved whole -- test/unit/errors_test.rb keeps the two canonical tests verbatim, so no assertion is lost at 3.0. 530 runs, 1519 assertions, 0 failures (unchanged). * test: point the whole canonical suite at SnapDiff names The suite still spoke v1 everywhere, so it would have broken on the 3.0 deletion even though the gem no longer does. Mechanical, no behaviour and no assertion values changed: - harness: test_helper + system_test_case load snap_diff/integrations/* and configure through SnapDiff.config; the support stubs (DSLStub, ScreenshoterStub, TestDoubles, DriverCoverage, NonMinitest) stop reopening gem namespaces and become plain top-level modules - 33 test files were defined inside module Capybara::Screenshot(::Diff) / CapybaraScreenshotDiff -- de-nested to top-level classes, so no bare constant resolves into a namespace 3.0 deletes - 270 legacy constant/accessor/session call sites repointed (CapybaraScreenshotDiff.registry -> SnapDiff.session, .reporters -> SnapDiff::Reporting.reporters, Capybara::Screenshot.root -> SnapDiff.config.root, ...) and 25 legacy require paths - legacy-surface tests now require the v1 entry point themselves, since the shared harness no longer loads it Three claims would have become tautologies under a blind repoint (assert_same SnapDiff.session, SnapDiff.session and friends): they were forwarder-identity claims about the v1 view. Preserved verbatim in the new test/legacy/legacy_forwarders_test.rb together with SnapDiff.start, which yields the two v1 holders and cannot outlive them. rake test:unit 534 runs, 1526 assertions, 0F/0E (was 530/1519) rake test 562 runs, 1571 assertions, 0F/0E/1S (was 558/1564) +4 runs: legacy_forwarders_test keeps the v1 claim where the canonical file also kept its own version (register-appends, reporters_mutex, serve). * test: split the mixed config/entry-point files along the same line Four files asserted the canonical behaviour AND the v1 view of it in one place, so a receiver repoint turned real claims into tautologies. Each is now two files; the v1 half is verbatim, and the canonical half stands on its own after 3.0: - snap_diff_config_test -> + test/legacy/legacy_config_accessors_test (CONFIG_MAPPING completeness, the mattr_accessor round trips, active? through the legacy forwarder, SnapDiff.start) - config_default_timing_test -> + test/legacy/legacy_config_default_timing_test canonical keeps snap_diff + snap_diff/integrations/minitest and reads SnapDiff.config only; the legacy file re-runs the SAME probe scripts under the v1 entries and adds the both-surfaces-agree loop, which is exactly what check_both asserted -- one source of truth, no drift - support_load_probe_test -> + test/legacy/legacy_entry_point_probe_test (advertised v1 constants, the CapybaraScreenshotDiff session surface, EAGER_USER_FACING / EAGER_EVERYWHERE under their OLD names) - errors_alias_test (earlier commit) -> test/unit/errors_test snap_diff-capybara joins CANONICAL_ENTRY_POINTS: 3.0 keeps that entry point (repointed at snap_diff/integrations/minitest), and it was covered only as a legacy entry, so it would have lost all coverage. Also repointed the last legacy call sites the sweep left: the rspec fixtures stubbed Capybara::Screenshot::Diff.pending_if_new, which the core stopped reading in #235 -- a silent no-op stub, now SnapDiff.config. rake test:unit 544 runs, 1544 assertions, 0F/0E rake test 572 runs, 1589 assertions, 0F/0E/1S * test: port the canonical claims that only a legacy-surface test was pinning Audit of every assertion moving into test/legacy/, asking: if this file vanished at 3.0, would any CANONICAL behaviour become untested? Two hits, both now duplicated (not moved) into a canonical test -- the v1 originals stay put, they still guard the v1 contract for all of 2.x: - namespace_forwarding_test was the only place proving SnapDiff::Drivers .loaded is ONE hash mutated in place (it asserted the v1 LOADED_DRIVERS constant is that same object, and that registering through it shows up canonically). Utils.find_driver_class_for caches through .loaded, so a copy-returning refactor would break user driver registration silently. -> drivers_test ".loaded is a single hash mutated in place" mutation: `.loaded.dup[...] = ...` -> red, Expected :probe_driver, got nil - the entry-point probe was the only place asserting an entry point defines its advertised CONSTANTS when it is the ONLY require (the f89cea2 bug class) -- but only for the v1 names. -> support_load_probe_test "every canonical entry point defines its advertised constants standalone", same claim over snap_diff/dsl, /integrations/minitest, /integrations/rspec, snap_diff-capybara. Entry-specific, because bare snap_diff carries neither DSL nor reporters by design. mutation: a bogus constant in the list -> red, naming it Also: attempts_reporter_test now requires snap_diff/attempts_reporter -- stable_screenshoter pulls it in lazily and the v1 umbrella was what loaded it eagerly, so it was the one canonical test the deletion actually broke. Judged legacy-only and safe to lose at 3.0: const_missing/eager alias semantics, deprecation warn-once + silencing, CONFIG_MAPPING completeness, the alias-only scan of lib/capybara*, and the CapybaraScreenshotDiff session/reporter forwarders -- every one is about a name 3.0 deletes, and its canonical counterpart is pinned in test/unit/. rake test 574 runs, 1593 assertions, 0F/0E/1S * fix: the canonical gate demanded SnapDiff.start, which 3.0 deletes Caught by independent review: `rake test:canonical` in the deleted tree is 1F, not the 0F I published. CANONICAL_SURFACE listed `start`, applied to all 7 canonical entry points. SnapDiff.start is defined only in lib/snap_diff/legacy_shims.rb:169 and yields the two v1 config holders, so it cannot outlive them (#235 decided this). A canonical gate demanding a method 3.0 deletes is a gate that goes red the day the deletion lands -- and I widened it in e789c8a by adding snap_diff-capybara. My own PR body filed .start under "safe to lose at 3.0". mutation (start put back, deleted tree): require "snap_diff" -> missing: start require "snap_diff/dsl" -> missing: start require "snap_diff/integrations/minitest" -> missing: start ... all 7 entry points .start keeps full coverage on the legacy side: legacy_forwarders_test pins what it yields and that it applies a setting, and a new per-entry-point probe in legacy_entry_point_probe_test pins the availability claim the canonical gate used to make -- for the entries that actually keep it. Also, per review: - "bare require never loads the umbrella" moves to legacy_forwarders_test. Its subject is lib/capybara_screenshot_diff.rb; once 3.0 deletes that file the $LOADED_FEATURES grep is empty by construction and the guard can never fail again. (-1 canonical run: 458 -> 457.) - backtrace_filter_test built synthetic paths under lib/capybara_screenshot_diff/. Pure string inputs to a prefix matcher, so no assertion changes -- but one of them named the real file the filter defaults to, which 3.0 deletes. rake test:unit 547 runs, 1550 assertions, 0F/0E/0S rake test 575 runs, 1595 assertions, 0F/0E/1S rake test:canonical 457 runs, 1288 assertions, 0F/0E/1S ... and 457/1288/0F/0E/1S in the deleted tree, identical.
1 parent 9822cc6 commit bbf724f

70 files changed

Lines changed: 3545 additions & 3250 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Rakefile‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,46 @@ require "rake/testtask"
55

66
task default: :test
77

8+
# THE 3.0 SPLIT.
9+
#
10+
# test/legacy/ holds every test whose SUBJECT is the v1 compatibility surface
11+
# -- the old Capybara::Screenshot / CapybaraScreenshotDiff namespaces, their
12+
# deprecation warnings, and the gates that keep lib/capybara* alias-only.
13+
# Those tests guard the v1 contract for the whole 2.x line, so they stay and
14+
# stay green; in 3.0 they are deleted by the same commit that deletes what
15+
# they test:
16+
#
17+
# git rm -r lib/capybara* lib/capybara_screenshot_diff.rb \
18+
# lib/snap_diff/legacy_shims.rb lib/snap_diff/deprecation.rb \
19+
# test/legacy
20+
#
21+
# A directory rather than a list in this file: there is nothing to keep in
22+
# sync, and the deletion is one `git rm -r`.
23+
#
24+
# `rake test` -- everything, today's gate.
25+
# `rake test:canonical` -- exactly what must still pass once test/legacy and
26+
# the v1 trees are gone. THE 3.0 GATE.
27+
# `rake test:unit` -- unit-sized tests; test/legacy is unit-sized too
28+
# (legacy/ marks lifetime, not kind), so it is in.
29+
LEGACY_SURFACE_TESTS = "test/legacy/**/*_test.rb"
30+
831
Rake::TestTask.new(:test) do |t|
932
t.libs << "test"
1033
t.libs << "lib"
1134
t.test_files = FileList["test/**/*_test.rb"]
1235
end
1336

37+
desc "Run every test that must survive the 3.0 deletion of the v1 surface"
38+
Rake::TestTask.new("test:canonical") do |t|
39+
t.libs << "test"
40+
t.libs << "lib"
41+
t.test_files = FileList["test/**/*_test.rb"].exclude(LEGACY_SURFACE_TESTS)
42+
end
43+
1444
Rake::TestTask.new("test:unit") do |t|
1545
t.libs << "test"
1646
t.libs << "lib"
17-
t.test_files = FileList["test/unit/**/*_test.rb"]
47+
t.test_files = FileList["test/unit/**/*_test.rb", LEGACY_SURFACE_TESTS]
1848
end
1949

2050
Rake::TestTask.new("test:integration") do |t|

‎test/fixtures/rspec_after_hook_order_masking_spec.rb‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
end
1717
end
1818

19-
require "capybara_screenshot_diff/rspec"
19+
require "snap_diff/integrations/rspec"
2020
require "support/stub_test_methods"
2121

2222
unless defined?(SCREEN_SIZE)
@@ -40,23 +40,23 @@
4040
before do
4141
Capybara.current_driver = Capybara.javascript_driver
4242
Capybara.page.current_window.resize_to(*SCREEN_SIZE)
43-
Capybara::Screenshot.window_size = SCREEN_SIZE
43+
SnapDiff.config.window_size = SCREEN_SIZE
4444

45-
Capybara::Screenshot.save_path = "doc/screenshots"
46-
Capybara::Screenshot.root = Rails.root / "../test/fixtures/app"
47-
Capybara::Screenshot.add_os_path = true
48-
Capybara::Screenshot.add_driver_path = true
49-
Capybara::Screenshot::Diff.driver = ENV.fetch("SCREENSHOT_DRIVER", "chunky_png").to_sym
50-
Capybara::Screenshot::Diff.tolerance = 0.5
45+
SnapDiff.config.save_path = "doc/screenshots"
46+
SnapDiff.config.root = Rails.root / "../test/fixtures/app"
47+
SnapDiff.config.add_os_path = true
48+
SnapDiff.config.add_driver_path = true
49+
SnapDiff.config.driver = ENV.fetch("SCREENSHOT_DRIVER", "chunky_png").to_sym
50+
SnapDiff.config.tolerance = 0.5
5151
# This fixture runs standalone in its own subprocess (no
5252
# ActiveSupport::TestCase setup forcing this off), and CI sets $CI,
5353
# which flips the default on and would raise before we ever get here.
54-
Capybara::Screenshot::Diff.fail_if_new = false
54+
SnapDiff.config.fail_if_new = false
5555
end
5656

5757
it "keeps a real after-hook failure failing even when a new screenshot is pending" do
5858
name = "pending-masking-after-hook-order"
59-
allow(Capybara::Screenshot::Diff).to receive(:pending_if_new).and_return(true)
59+
allow(SnapDiff.config).to receive(:pending_if_new).and_return(true)
6060
visit "/"
6161
screenshot name
6262
ensure

‎test/fixtures/rspec_pending_masking_spec.rb‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require "capybara/rspec"
44

5-
require "capybara_screenshot_diff/rspec"
5+
require "snap_diff/integrations/rspec"
66
require "support/stub_test_methods"
77

88
unless defined?(SCREEN_SIZE)
@@ -27,23 +27,23 @@
2727
before do
2828
Capybara.current_driver = Capybara.javascript_driver
2929
Capybara.page.current_window.resize_to(*SCREEN_SIZE)
30-
Capybara::Screenshot.window_size = SCREEN_SIZE
30+
SnapDiff.config.window_size = SCREEN_SIZE
3131

32-
Capybara::Screenshot.save_path = "doc/screenshots"
33-
Capybara::Screenshot.root = Rails.root / "../test/fixtures/app"
34-
Capybara::Screenshot.add_os_path = true
35-
Capybara::Screenshot.add_driver_path = true
36-
Capybara::Screenshot::Diff.driver = ENV.fetch("SCREENSHOT_DRIVER", "chunky_png").to_sym
37-
Capybara::Screenshot::Diff.tolerance = 0.5
32+
SnapDiff.config.save_path = "doc/screenshots"
33+
SnapDiff.config.root = Rails.root / "../test/fixtures/app"
34+
SnapDiff.config.add_os_path = true
35+
SnapDiff.config.add_driver_path = true
36+
SnapDiff.config.driver = ENV.fetch("SCREENSHOT_DRIVER", "chunky_png").to_sym
37+
SnapDiff.config.tolerance = 0.5
3838
# This fixture runs standalone in its own subprocess (no
3939
# ActiveSupport::TestCase setup forcing this off), and CI sets $CI,
4040
# which flips the default on and would raise before we ever get here.
41-
Capybara::Screenshot::Diff.fail_if_new = false
41+
SnapDiff.config.fail_if_new = false
4242
end
4343

4444
it "keeps a genuine failure failing even when a new screenshot is pending" do
4545
name = "pending-masking-real-failure"
46-
allow(Capybara::Screenshot::Diff).to receive(:pending_if_new).and_return(true)
46+
allow(SnapDiff.config).to receive(:pending_if_new).and_return(true)
4747
visit "/"
4848
screenshot name
4949

‎test/fixtures/rspec_spec.rb‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require "capybara/rspec"
44

5-
require "capybara_screenshot_diff/rspec"
5+
require "snap_diff/integrations/rspec"
66
require "support/stub_test_methods"
77

88
unless defined?(SCREEN_SIZE)
@@ -14,17 +14,17 @@
1414
before do
1515
Capybara.current_driver = Capybara.javascript_driver
1616
Capybara.page.current_window.resize_to(*SCREEN_SIZE)
17-
Capybara::Screenshot.window_size = SCREEN_SIZE
18-
19-
Capybara::Screenshot.save_path = "doc/screenshots"
20-
Capybara::Screenshot.root = Rails.root / "../test/fixtures/app"
21-
Capybara::Screenshot.add_os_path = true
22-
Capybara::Screenshot.add_driver_path = true
23-
Capybara::Screenshot::Diff.driver = ENV.fetch("SCREENSHOT_DRIVER", "chunky_png").to_sym
24-
Capybara::Screenshot::Diff.tolerance = 0.5
17+
SnapDiff.config.window_size = SCREEN_SIZE
18+
19+
SnapDiff.config.save_path = "doc/screenshots"
20+
SnapDiff.config.root = Rails.root / "../test/fixtures/app"
21+
SnapDiff.config.add_os_path = true
22+
SnapDiff.config.add_driver_path = true
23+
SnapDiff.config.driver = ENV.fetch("SCREENSHOT_DRIVER", "chunky_png").to_sym
24+
SnapDiff.config.tolerance = 0.5
2525
end
2626

27-
it "should include CapybaraScreenshotDiff in rspec" do
27+
it "should include SnapDiff::DSL in rspec" do
2828
expect(self.class.ancestors).to include SnapDiff::DSL
2929
end
3030

@@ -45,7 +45,7 @@
4545

4646
it "marks the example pending when a new screenshot has no baseline and pending_if_new is enabled" do
4747
name = "pending-if-new-example"
48-
allow(Capybara::Screenshot::Diff).to receive(:pending_if_new).and_return(true)
48+
allow(SnapDiff.config).to receive(:pending_if_new).and_return(true)
4949
visit "/"
5050
screenshot name
5151
ensure

0 commit comments

Comments
 (0)