lint rule: require-in-test-method (leftover red-phase scaffolding) #206

Closed
opened 2026-08-01 14:16:57 +00:00 by jared · 1 comment
Owner

Migrated from jared/os-sdlc#32 (repo retired).

Problem

A test file repeats require "lib_under_test" inside every test method body (leftover red-phase scaffolding from when the lib didn't exist yet, needed to keep a missing-lib load a red test rather than a load-time crash). Once the lib exists, this is stale.

Detection

  • Inputs: *_test.rb files.
  • Algorithm: flag require/require_relative calls that appear inside a def ... end body (rather than at file top level) in test files.
  • Failure message: "require appears inside N test method bodies. Move to a single top-level require and delete any now-stale red-phase comment explaining it."

Correction

Single top-level require/require_relative; delete the stale red-phase comment if present.

Pass/fail examples

  • Must fail: require "..." inside any test method body.
  • Must pass: one top-level require, no in-method requires.

Provenance

Fable finding. Run 18 (ticket #18, decision-dice sandbox, now retired), dual review, 2026-07-21.

Implementation plan

Candidate custom cop for plugins/os-sdlc/lib/os_sdlc/cops/ (Sdlc/Minitest namespace).

Migrated from jared/os-sdlc#32 (repo retired). ## Problem A test file repeats `require "lib_under_test"` inside every test method body (leftover red-phase scaffolding from when the lib didn't exist yet, needed to keep a missing-lib load a red *test* rather than a load-time crash). Once the lib exists, this is stale. ## Detection - **Inputs:** *_test.rb files. - **Algorithm:** flag require/require_relative calls that appear inside a `def ... end` body (rather than at file top level) in test files. - **Failure message:** "require appears inside N test method bodies. Move to a single top-level require and delete any now-stale red-phase comment explaining it." ## Correction Single top-level `require`/`require_relative`; delete the stale red-phase comment if present. ## Pass/fail examples - **Must fail:** `require "..."` inside any test method body. - **Must pass:** one top-level require, no in-method requires. ## Provenance Fable finding. Run 18 (ticket #18, decision-dice sandbox, now retired), dual review, 2026-07-21. ## Implementation plan Candidate custom cop for plugins/os-sdlc/lib/os_sdlc/cops/ (Sdlc/Minitest namespace).
Author
Owner

Implemented as Sdlc/Minitest/RequireInTestMethod (commit 458d3b8, branch worktree-sdlc-lint-cops). 6 tests green, rubocop clean.

Implemented as Sdlc/Minitest/RequireInTestMethod (commit 458d3b8, branch worktree-sdlc-lint-cops). 6 tests green, rubocop clean.
jared closed this issue 2026-08-01 14:33:20 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
jared/cc-os#206
No description provided.