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 ’…‘ do` line (or a comment line directly above) of EACH test in an intentionally duplicate group: `# allow_duplicate_snapshot: <reason>`.
'allow_duplicate_snapshot'.freeze
- TEST_DEFINITION =
Matches a minitest ‘test ’…‘ do` declaration; captures the quote (1), the name (2), and the trailing content after `do` (3).
/^\s*test\s+(["'])(.+?)\1\s+do\b(.*)$/- MissingDir =
Sentinel returned by ‘#offenders` when no `*_results` dirs exist, so the Minitest wrapper can `skip` rather than `assert`.
Module.new
Instance Method Summary collapse
-
#initialize(results_root) ⇒ DuplicateSnapshotChecker
constructor
A new instance of DuplicateSnapshotChecker.
-
#offenders ⇒ Object
Returns Array<String> of offender descriptions (one per duplicate group that has at least one un-marked member), ‘[]` if there are no unjustified duplicates, or `MissingDir` if there are no `*_results` dirs at all.
Constructor Details
#initialize(results_root) ⇒ DuplicateSnapshotChecker
Returns a new instance of DuplicateSnapshotChecker.
30 31 32 |
# File 'lib/dev_doc/test/lints/duplicate_snapshot.rb', line 30 def initialize(results_root) @results_root = Pathname(results_root) end |
Instance Method Details
#offenders ⇒ Object
Returns Array<String> of offender descriptions (one per duplicate group that has at least one un-marked member), ‘[]` if there are no unjustified duplicates, or `MissingDir` if there are no `*_results` dirs at all.
38 39 40 41 42 43 |
# File 'lib/dev_doc/test/lints/duplicate_snapshot.rb', line 38 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 |