← Refactoring and maintenance guides

How to update specs during refactoring

How-To Refactoring and maintenance Intermediate 1151002HOWTO-1151002

HOWTO-1151002Refactoring and maintenanceIntermediate

This guide shows you how to update SpecDD specs during refactoring in a spec-driven development workflow.

Specs should stay accurate as structure changes. If code moves, files split, tests relocate, or ownership changes, the specs that describe those paths and responsibilities need to move with the refactor. But a behavior-preserving refactor should not rewrite behavioral rules just because implementation internals changed.

The job is to keep the contract accurate, not to make the spec look new.

Short answer

During a refactor, update Owns, Can modify, Can read, References, Structure, tasks, and Done when when paths, ownership, or verification change. Keep Must, Must not, scenarios, and public contract sections unchanged unless the intended behavior changes. Commit spec and code updates together so future work sees one consistent source of truth.

When to use this guide

Use this guide when:

Steps

1. Decide whether behavior changed

Before editing the spec, ask:

If behavior changed, update the owning behavior spec intentionally. If only structure changed, keep behavior sections stable.

2. Update ownership sections

Before:

Owns:
  ./itinerary.js
  ./itinerary.test.js

After splitting:

Owns:
  ./itinerary-validation.js
  ./itinerary-validation.test.js
  ./itinerary-formatting.js
  ./itinerary-formatting.test.js

If the split creates separate responsibilities, do not simply add every file to one broad Owns. Create smaller specs for the new owners.

3. Update path references

Check:

Use explicit ./, ../, or / prefixes when paths are intended.

4. Move same-basename specs with files

If:

itinerary.js
itinerary.sdd

becomes:

validation/itinerary-validation.js
validation/itinerary-validation.sdd

move and rename the spec so same-basename matching still works. Then update parent Structure, References, or Owns entries that pointed to the old location.

5. Move tests without changing behavior

Tests may move during a refactor. Keep assertions aligned with the same spec behavior.

If tests now prove different behavior, that is not only a test move. Update the behavior spec and review the change as a contract change.

6. Update tasks and Done when

If a task or completion criterion references old structure, update it:

Done when:
  Missing-place validation is covered by the validation unit checks.

Do not leave stale Done when entries pointing to removed tests or old workflows.

7. Lint and review

After refactor-related spec edits:

specdd lint path/to/changed/spec-or-directory

Then review:

Common mistakes

How to verify the result

Specs are updated correctly when:

← Refactoring and maintenance guides