← Use spec sections guides

How to use the Handles section

How-To Use spec sections Intermediate 1061016HOWTO-1061016

HOWTO-1061016Use spec sectionsIntermediate

This guide shows you how to use the Handles section in a SpecDD .sdd file.

Handles lists cases, events, states, branches, errors, or conditions that the subject must handle. It is useful when behavior depends on multiple important cases.

Short answer

Use Handles to name the cases the subject must deal with, such as missing input, save failure, retry state, event arrival, empty data, or unavailable dependencies. Keep each case local to the subject, and use Scenario or Done when for important cases that need verification.

Syntax

Handles:
  missing place name
  missing trip date
  save failure
  moving a missing itinerary item

Rules:

Steps

1. List cases that change behavior

Good:

Handles:
  missing place name
  save failure

Weak:

Handles:
  everything

The case should be specific enough to implement and review.

2. Keep cases local

For an itinerary spec:

Handles:
  missing place name
  moving a place to another day

Do not list destination search ranking cases unless the itinerary spec owns that behavior.

3. Separate handling from errors raised

Handles:
  storage save failure

Raises:
  ItinerarySaveFailed

The subject handles the storage failure and raises a local error.

4. Add scenarios for important cases

Scenario: save failure
  Given trip storage rejects the save
  When the person adds a place
  Then the itinerary remains unchanged
  And a save failure is shown

Scenarios make complicated cases testable.

5. Use Done when for coverage expectations

Done when:
  Missing-place and save-failure behavior are covered by checks.

This keeps important handled cases from being forgotten during implementation.

Common mistakes

How to verify the result

The Handles section is useful when:

← Use spec sections guides