The Six Magic Tricks
by Sandi Metz
| Origin | Query (returns something) | Command (changes something) |
|---|---|---|
| Incoming | ① ✅ Assert return value | ② ✅ Assert public side effect |
| To Self | ③ 🚫 Ignore | ④ 🚫 Ignore |
| Outgoing | ⑤ 🚫 Ignore | ⑥ ✅ Mock expectation |
The Six Magic Tricks
by Sandi Metz
| Origin | Query (returns something) | Command (changes something) |
|---|---|---|
| Incoming | ① ✅ Assert return value | ② ✅ Assert public side effect |
| To Self | ③ 🚫 Ignore | ④ 🚫 Ignore |
| Outgoing | ⑤ 🚫 Ignore | ⑥ ✅ Mock expectation |
| Quality | Meaning |
|---|---|
| Thorough | Fully prove object behavior |
| Stable | Don’t break on refactors |
| Fast | Run quickly and often |
| Few | Only test what matters |
| Circus Performer | Software Developer |
|---|---|
| Risks falling mid-act | Risks breaking existing features |
| Trusts the net beneath | Trusts the test suite beneath |
| Performs with confidence | Deploys with confidence |
| Version | Endpoint | Controller | Action |
|---|---|---|---|
| v1 | /api/v1/rcad/processar |
Api::V1::RcadController |
processar |
| v2 | /api/v2/rcad/processar |
Api::V2::RcadController |
processar |
✅ Yes — they coexist, letting you upgrade or test new API versions without breaking the old one.
| Component | Example | Description |
|---|---|---|
| Scheme (Protocol) | http |
Defines how data is transferred (e.g., http, https, ftp) |
| Host | localhost |
The domain or IP address where the resource lives |
| Port | 3000 |
The communication port (often 80 for HTTP, 443 for HTTPS) |
| Path | /api/v1/rcad/processar |
The exact location or route of the resource on the server |
| Query String | ?user=gilberto&mode=fast |
Extra parameters sent to the server |
| Fragment | #summary |
A reference to a section or element within the resource |
| Component | Example | Description |
|---|---|---|
| Scheme (Protocol) | http |
Defines how data is transferred (e.g., http, https, ftp) |
| Host | localhost |
The domain or IP address where the resource lives |
| Port | 3000 |
The communication port (often 80 for HTTP, 443 for HTTPS) |
| Path | /api/v1/rcad/processar |
The exact location or route of the resource on the server |
| Query String | ?user=gilberto&mode=fast |
Extra parameters sent to the server |
| Fragment | #summary |
A reference to a section or element within the resource |
| Concept | Analogy | Effect on code |
|---|---|---|
| Stable interface | The plug socket standard | Code keeps working |
| Changing implementation | Wires inside the plug | Code breaks often |
| Quality | Meaning |
|---|---|
| Thorough | Fully prove object behavior |
| Stable | Don’t break on refactors |
| Fast | Run quickly and often |
| Few | Only test what matters |
| Origin | Query (returns something) | Command (changes something) |
|---|---|---|
| Incoming | ① | ② |
| To Self | ③ | ④ |
| Outgoing | ⑤ | ⑥ |
| Command | Purpose |
|---|---|
bundle binstubs --all |
Generate binstubs for all gems |
bundle binstubs rspec-core |
Generate binstub only for RSpec |
bundle exec spring binstub rails rspec |
Add Spring preload hooks |
bin/spring stop |
Restart Spring after changes |
bin/rspec |
Run tests fast in the correct environment |