Sdlc/Minitest/TestMethodAfterPrivate: skip singleton test methods and match ::Minitest::Test #1358

Closed
opened 2026-10-25 21:23:16 +00:00 by jared · 5 comments
Owner

Problem

Rewritten 2026-10-27 from docs/lint-lessons/analyses/sdlc-minitest-test-method-after-private.md.

Sdlc/Minitest/TestMethodAfterPrivate flags def self.test_x after private, but private does not change singleton methods. It misses class C < ::Minitest::Test, because it compares parent_class.source with the string "Minitest::Test".

Approach

Required work:

  1. In plugins/os-sdlc/lib/os_sdlc/cops/minitest/test_method_after_private.rb, report only def nodes, never defs — check: present def_type? in plugins/os-sdlc/lib/os_sdlc/cops/minitest/test_method_after_private.rb
  2. Compare the superclass with parent_class&.const_name == "Minitest::Test" — check: present const_name in plugins/os-sdlc/lib/os_sdlc/cops/minitest/test_method_after_private.rb
  3. Add fixtures to plugins/os-sdlc/tests/cops/test_method_after_private_test.rb: must-fire for a ::Minitest::Test base; must-pass for def self.test_x after private and for def self.test_x with private_class_method.

Acceptance criteria

  1. Given private then def self.test_x in a Minitest::Test class, when the cop runs, then it reports no offense.
  2. Given private then def test_x in a class that inherits ::Minitest::Test, when the cop runs, then it reports one offense.
  3. Given the existing bare-private fixture, when the cop runs, then it still reports one offense.

Owner sketch

class RuboCop::Cop::Sdlc::Minitest::TestMethodAfterPrivate
  def minitest_test_class?(node) = node.parent_class&.const_name == "Minitest::Test"
end

Origin

  • Trigger: #1325 zero-false-positive audit of every Sdlc cop.
  • Improvised this session: none
  • Chain: false positive and miss ← matcher accepts defs and compares superclass source text ← DESIGN (test_method_after_private.rb:21-27)
  • Root candidate: none found; searched TestMethodAfterPrivate, after private, singleton test, Minitest, test_method, PrivateMethodDefs
  • Where: plugins/os-sdlc/lib/os_sdlc/cops/test_method_after_private.rb
  • Session: eb98cdcd-6783-46a0-b7df-cf18a8fe2a56
  • Transcript: /home/jared/.claude/projects/-home-jared-dev-cc-os--claude-worktrees-ticket-1325/eb98cdcd-6783-46a0-b7df-cf18a8fe2a56.jsonl
## Problem Rewritten 2026-10-27 from docs/lint-lessons/analyses/sdlc-minitest-test-method-after-private.md. `Sdlc/Minitest/TestMethodAfterPrivate` flags `def self.test_x` after `private`, but `private` does not change singleton methods. It misses `class C < ::Minitest::Test`, because it compares `parent_class.source` with the string `"Minitest::Test"`. ## Approach Required work: 1. In `plugins/os-sdlc/lib/os_sdlc/cops/minitest/test_method_after_private.rb`, report only `def` nodes, never `defs` — check: present `def_type?` in `plugins/os-sdlc/lib/os_sdlc/cops/minitest/test_method_after_private.rb` 2. Compare the superclass with `parent_class&.const_name == "Minitest::Test"` — check: present `const_name` in `plugins/os-sdlc/lib/os_sdlc/cops/minitest/test_method_after_private.rb` 3. Add fixtures to `plugins/os-sdlc/tests/cops/test_method_after_private_test.rb`: must-fire for a `::Minitest::Test` base; must-pass for `def self.test_x` after `private` and for `def self.test_x` with `private_class_method`. ## Acceptance criteria 1. Given `private` then `def self.test_x` in a `Minitest::Test` class, when the cop runs, then it reports no offense. 2. Given `private` then `def test_x` in a class that inherits `::Minitest::Test`, when the cop runs, then it reports one offense. 3. Given the existing bare-`private` fixture, when the cop runs, then it still reports one offense. ## Owner sketch ```ruby class RuboCop::Cop::Sdlc::Minitest::TestMethodAfterPrivate def minitest_test_class?(node) = node.parent_class&.const_name == "Minitest::Test" end ``` ## Origin - Trigger: #1325 zero-false-positive audit of every Sdlc cop. - Improvised this session: none - Chain: false positive and miss ← matcher accepts `defs` and compares superclass source text ← DESIGN (`test_method_after_private.rb:21-27`) - Root candidate: none found; searched TestMethodAfterPrivate, after private, singleton test, Minitest, test_method, PrivateMethodDefs - Where: plugins/os-sdlc/lib/os_sdlc/cops/test_method_after_private.rb - Session: eb98cdcd-6783-46a0-b7df-cf18a8fe2a56 - Transcript: /home/jared/.claude/projects/-home-jared-dev-cc-os--claude-worktrees-ticket-1325/eb98cdcd-6783-46a0-b7df-cf18a8fe2a56.jsonl
Author
Owner

Skeptic DROP (depth-1, 0 hits today): proposed new cop Sdlc/Minitest/SingletonTestMethod — def self.test_* or test_* inside class << self in a Minitest::Test class never runs. Draft: docs/lint-lessons/analyses/sdlc-minitest-test-method-after-private.md question (b).

Skeptic DROP (depth-1, 0 hits today): proposed new cop Sdlc/Minitest/SingletonTestMethod — `def self.test_*` or `test_*` inside `class << self` in a Minitest::Test class never runs. Draft: docs/lint-lessons/analyses/sdlc-minitest-test-method-after-private.md question (b).
Author
Owner

Body rewritten 2026-10-27 from the false-positive process; analysis and lint lesson merged to main (docs/lint-lessons/analyses/, plugins/os-sdlc/lint-lessons/).

Body rewritten 2026-10-27 from the false-positive process; analysis and lint lesson merged to main (docs/lint-lessons/analyses/, plugins/os-sdlc/lint-lessons/).
Author
Owner

2026-10-27: work started in fast-batch-cop-matchers (AFK). Ticket confirmed valid on main a02b9458.

2026-10-27: work started in fast-batch-cop-matchers (AFK). Ticket confirmed valid on main a02b9458.
Author
Owner

Follow-up cop Sdlc/Minitest/SingletonTestMethod (analysis option A) not filed. Skeptic DROP: 0 sites of def self.test_ in plugins/ and ~/dev/ruby-gems; speculative; depth-1 rule. Note here if it ever bites.

Follow-up cop Sdlc/Minitest/SingletonTestMethod (analysis option A) not filed. Skeptic DROP: 0 sites of def self.test_ in plugins/ and ~/dev/ruby-gems; speculative; depth-1 rule. Note here if it ever bites.
Author
Owner

Resolution

Done: TestMethodAfterPrivate matches parent_class&.const_name == 'Minitest::Test' and reports def nodes only (defs skipped). Commit 748df9cf (merged f5310f2b).

Evidence: Fixtures: ::Minitest::Test base fires; private + def self.test_x passes; private_class_method passes; bare-private fixture still fires. Suite 2825 runs 0 failures; sweep 0 new hits.

Follow-ups: SingletonTestMethod cop dropped by skeptic: 0 sites. Lesson unchanged (already described singleton methods).

## Resolution **Done:** TestMethodAfterPrivate matches parent_class&.const_name == 'Minitest::Test' and reports def nodes only (defs skipped). Commit 748df9cf (merged f5310f2b). **Evidence:** Fixtures: ::Minitest::Test base fires; private + def self.test_x passes; private_class_method passes; bare-private fixture still fires. Suite 2825 runs 0 failures; sweep 0 new hits. **Follow-ups:** SingletonTestMethod cop dropped by skeptic: 0 sites. Lesson unchanged (already described singleton methods).
jared closed this issue 2026-10-27 21:53:11 +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#1358
No description provided.