Skip to content

TDD skill: Add explicit refactoring examples #437

Closed as not planned
Closed as not planned

Description

@zaldabus

Feature Request

The test-driven-development skill mentions refactoring in the "When to Use" section but lacks concrete examples of applying RED-GREEN-REFACTOR to common refactoring operations like renaming functions, extracting code to new files, or moving code between modules.

Problem

The skill correctly states:

**Always:**
- New features
- Bug fixes
- Refactoring  <-- Listed but not demonstrated
- Behavior changes

However, all examples focus on new features and bug fixes. There are no examples showing how to apply TDD to refactoring.

Result: Developers (and AI agents) naturally gravitate toward "implementation first, tests second" during refactoring because the skill doesn't reinforce TDD discipline for these operations.

Use Case

Common refactoring patterns that need TDD examples:

  1. Renaming a function

    • Update test to use new name → tests fail → rename implementation → tests pass
  2. Extracting code to a new file

    • Create test file with imports that will fail → tests error → create new module → tests pass
  3. Moving code between modules

    • Update test imports first → tests error → move implementation → tests pass

Proposed Solution

Add a new "Refactoring Examples" section after "Example: Bug Fix" showing concrete RED-GREEN-REFACTOR cycles for common refactoring operations.

Local Implementation

I've already implemented this locally in my cached copy at:
~/.claude/plugins/cache/superpowers-dev/superpowers/3.6.2/skills/test-driven-development/skill.md

Changes made:

  • Added "Refactoring Examples" section with 3 concrete examples
  • Each example shows: tests first (RED), watch failure, implementation (GREEN), verify
  • Added "Key Principle for Refactoring" subsection reinforcing test-first discipline
  • Emphasized that "mechanical" changes still require TDD

Benefits observed:

  • Prevents "implementation first, tests second" pattern during refactors
  • Reinforces TDD discipline applies to ALL code changes, not just new features
  • Provides concrete patterns to follow for common refactoring scenarios

Example Content

### Example: Renaming a Function

**Goal:** Rename `processData()` to `transformUserInput()`

**RED - Update Tests First**
```typescript
import { transformUserInput } from '../processor'; // Use new name

test('transforms user input correctly', () => {
  const result = transformUserInput({ name: 'Alice' });
  expect(result.formattedName).toBe('ALICE');
});

Verify RED

$ npm test
ERROR: Cannot find 'transformUserInput'

GREEN - Rename Implementation
// ... (implementation change)

Would you be open to a PR adding refactoring examples to the TDD skill?

Activity

  1. DamianPereira commented on Feb 8, 2026

    @DamianPereira

    I have a similar (but much more generic) issue with skill loading and system prompts: #439

  2. added
    enhancement
    on Feb 21, 2026
  3. obra commented on Mar 10, 2026

    @obra
    Owner

    Closing — the TDD skill intentionally stays concise. Refactoring examples would add bulk without much benefit since the RED-GREEN-REFACTOR cycle is well understood.

    — Claude Opus 4.6, Claude Code 2.1.72

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions