Class: DevDoc::Test::Lints::DuplicateSnapshotChecker
- Inherits:
-
Object
- Object
- DevDoc::Test::Lints::DuplicateSnapshotChecker
- Defined in:
- lib/dev_doc/test/lints/duplicate_snapshot.rb
Overview
Framework-agnostic check: scans a directory of controller-test
snapshot result dirs (*_results/*.json) and reports groups of
byte-identical snapshots within the same dir.
Wrapped by the Minitest module DuplicateSnapshot below — see that
module for the rationale and inline opt-out format. Tests cover the
checker directly so they don't have to mock a test framework.
Constant Summary collapse
- MARKER =
Inline opt-out token. Append to the
test '...' doline (or a comment line directly above) of EACH test in an intentionally duplicate group:# allow_duplicate_snapshot: <reason>. 'allow_duplicate_snapshot'.freeze
- MARKER_WITH_REASON =
A bare marker with no reason is mechanics without policy — the reason is the reviewable part, so it is mandatory.
/#{MARKER}\s*:\s*\S/- TEST_DEFINITION =
Matches a minitest
test '...' dodeclaration; captures the quote (1), the name (2), and the trailing content afterdo(3). /^\s*test\s+(["'])(.+?)\1\s+do\b(.*)$/- MissingDir =
Sentinel returned by
#offenderswhen no*_resultsdirs exist, so the Minitest wrapper canskiprather thanassert. Module.new
Instance Method Summary collapse
-
#initialize(results_root) ⇒ DuplicateSnapshotChecker
constructor
A new instance of DuplicateSnapshotChecker.
-
#offenders ⇒ Object
Returns Array
of offender descriptions (one per duplicate group that has at least one un-marked member), []if there are no unjustified duplicates, orMissingDirif there are no*_resultsdirs at all.
Constructor Details
#initialize(results_root) ⇒ DuplicateSnapshotChecker
Returns a new instance of DuplicateSnapshotChecker.
34 35 36 |
# File 'lib/dev_doc/test/lints/duplicate_snapshot.rb', line 34 def initialize(results_root) @results_root = Pathname(results_root) end |
Instance Method Details
#offenders ⇒ Object
Returns Array[] if there are
no unjustified duplicates, or MissingDir if there are no
*_results dirs at all.
42 43 44 45 46 47 |
# File 'lib/dev_doc/test/lints/duplicate_snapshot.rb', line 42 def offenders dirs = Dir.glob(@results_root.join('*_results')).select { |d| File.directory?(d) } return MissingDir if dirs.empty? dirs.sort.flat_map { |dir| offenders_in(dir) } end |