Craft Custom Expectation

Crafting custom expectations. When and how to extract.

attac-t 8d6a887 2 files · 2.4 KB Updated

File contents

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.

attac-t/the-foundry/tree/main/plugins/pest/skills/craft-custom-expectation commit 8d6a88769a

Frequently asked questions

npx skillmds@latest add attac-t/craft-custom-expectation