Module: DevDoc::Test::Lints::DuplicateSnapshot
- Defined in:
- lib/dev_doc/test/lints/duplicate_snapshot.rb
Overview
Reject byte-identical controller-test snapshots within the same
*_results dir.
Rationale
"Test quality" is normally subjective. Two tests serializing the
exact same rendered response is an objective, computable proxy for
a redundant or weak test. When response_assert_equal snapshots
collide, it's almost always one of:
1. **Same scenario tested twice** — should be one test with the
combined assertions.
2. **Fixtures don't exercise the difference** — the test claims to
verify behaviour X, but the inputs all collapse to the same
rendered state, so it passes without actually testing X. (The
most dangerous case — green but vacuous.)
3. **A negative/absence assertion** — a test for "X is NOT shown"
legitimately renders identically to the baseline. This is the
one *correct* duplicate; acknowledge it with the inline marker.
Aggressive by design: a false positive costs only a quick review and one inline comment, while a silent duplicate hides a real (1) or (2).
Inline opt-out (NOT a central allow-list)
The justification lives next to the test, so it can't rot or detach.
Mark EACH test in an intentionally-duplicate group with
# allow_duplicate_snapshot: <reason> — either as a trailing comment on
its test '...' do line, or on the comment line directly above it (use
the latter when the test line is already long):
test 'index hides the banner' do # allow_duplicate_snapshot: renders like the baseline
...
end
# allow_duplicate_snapshot: renders like the baseline
test 'index hides the banner for a guest who is not in any of the groups' do
...
end
Usage
class DuplicateSnapshotTest < ActiveSupport::TestCase include DevDoc::Test::Lints::DuplicateSnapshot # SNAPSHOT_RESULTS_ROOT = 'test/requests' # override if needed end
Instance Method Summary collapse
Instance Method Details
#test_no_unjustified_duplicate_snapshots ⇒ Object
169 170 171 172 173 174 175 176 |
# File 'lib/dev_doc/test/lints/duplicate_snapshot.rb', line 169 def test_no_unjustified_duplicate_snapshots result = DuplicateSnapshotChecker.new(snapshot_results_root).offenders if result == DuplicateSnapshotChecker::MissingDir skip "no snapshot result dirs under #{snapshot_results_root}" end assert result.empty?, (result) end |