# Craft Custom Expectation

> Crafting custom expectations. When and how to extract.

- Skill: `attac-t/craft-custom-expectation` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add attac-t/craft-custom-expectation`
- Raw SKILL.md: https://api.skillmd.com/api/skills/attac-t/craft-custom-expectation/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: attac-t (https://skillmd.com/u/attac-t)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/attac-t/craft-custom-expectation

---


# Skill: Craft Custom Expectation

> "Extract when patterns repeat."

## The Standard

1. **Rule of Three**: Extract when the same pattern appears 3+ times.
2. **Separate File**: Put all custom expectations in `tests/Expectations.php`.
3. **Return $this**: Always return `$this` to enable chaining.

## The Anti-Patterns

| Don't                | Do                             | Why                     |
|----------------------|--------------------------------|-------------------------|
| Extract single-use   | Keep inline                    | Clarity over abstraction |
| Forget `return $this` | Always return                 | Chaining breaks         |
| Scatter across files | Centralize in `Expectations.php` | Discoverability       |
| Reinvent built-ins   | Use Pest's expectations        | Maintenance             |

## Real-World Examples

See [examples.md](examples.md).

