Commit 2d74b61
Improve test assertions using explicit have_received checks (#854)
## Summary
- Replace indirect `call_count` counter patterns with explicit RSpec spy
assertions
- Use `have_received(:capture3).with(hook_command)` to verify hook was
called
- Use `not_to have_received` to explicitly verify hook was skipped
- Simplify mock setup by using direct return values where possible
## Why this matters
The previous tests used indirect assertions like `expect(call_count).to
eq(1)` which:
- Don't explicitly prove what was or wasn't called
- Are brittle to implementation changes
- Require understanding the counter logic to interpret
The new assertions like `expect(Open3).not_to
have_received(:capture3).with(anything, hook_command, anything)` are:
- Self-documenting - explicitly states "hook was NOT called"
- More robust to implementation changes
- Produce clearer failure messages
## Test plan
- [ ] CI tests pass
- [ ] Verify test output is meaningful when assertions fail
Based on discussion:
https://github.com/shakacode/shakapacker/discussions/new?category=ideas
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Tests**
* Simplified and hardened precompile hook tests using direct spy
assertions, ensuring consistent verification across configured,
unconfigured, skipped, and edge-case scenarios (spaces or env
assignments) and verifying webpack runs independently of the hook.
* **Documentation**
* Updated testing guidance to recommend explicit spy assertions with
examples and warn against indirect call-count patterns.
<sub>✏️ Tip: You can customize this high-level summary in your review
settings.</sub>
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 5c89f18 commit 2d74b61
2 files changed
+28
-35
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
15 | 19 | | |
16 | 20 | | |
17 | 21 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| 66 | + | |
66 | 67 | | |
67 | | - | |
68 | | - | |
69 | 68 | | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
| 69 | + | |
74 | 70 | | |
75 | 71 | | |
76 | | - | |
77 | 72 | | |
78 | 73 | | |
79 | 74 | | |
80 | 75 | | |
81 | | - | |
82 | | - | |
| 76 | + | |
83 | 77 | | |
84 | 78 | | |
85 | | - | |
| 79 | + | |
86 | 80 | | |
87 | 81 | | |
88 | 82 | | |
| |||
91 | 85 | | |
92 | 86 | | |
93 | 87 | | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
| 88 | + | |
99 | 89 | | |
100 | 90 | | |
101 | 91 | | |
102 | 92 | | |
103 | 93 | | |
104 | | - | |
| 94 | + | |
| 95 | + | |
105 | 96 | | |
106 | 97 | | |
107 | 98 | | |
| |||
316 | 307 | | |
317 | 308 | | |
318 | 309 | | |
319 | | - | |
320 | | - | |
321 | | - | |
322 | | - | |
323 | | - | |
| 310 | + | |
| 311 | + | |
324 | 312 | | |
325 | 313 | | |
326 | | - | |
| 314 | + | |
327 | 315 | | |
328 | 316 | | |
329 | 317 | | |
330 | 318 | | |
331 | 319 | | |
332 | 320 | | |
333 | | - | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
334 | 325 | | |
335 | 326 | | |
336 | 327 | | |
| |||
340 | 331 | | |
341 | 332 | | |
342 | 333 | | |
| 334 | + | |
343 | 335 | | |
344 | | - | |
345 | 336 | | |
346 | | - | |
347 | | - | |
348 | | - | |
| 337 | + | |
349 | 338 | | |
350 | 339 | | |
351 | 340 | | |
352 | 341 | | |
353 | 342 | | |
354 | 343 | | |
355 | | - | |
| 344 | + | |
356 | 345 | | |
357 | 346 | | |
358 | 347 | | |
359 | 348 | | |
360 | 349 | | |
361 | 350 | | |
362 | | - | |
| 351 | + | |
| 352 | + | |
363 | 353 | | |
364 | 354 | | |
365 | 355 | | |
| |||
369 | 359 | | |
370 | 360 | | |
371 | 361 | | |
| 362 | + | |
372 | 363 | | |
373 | | - | |
374 | 364 | | |
375 | | - | |
376 | | - | |
377 | | - | |
| 365 | + | |
378 | 366 | | |
379 | 367 | | |
380 | 368 | | |
381 | 369 | | |
382 | 370 | | |
383 | 371 | | |
384 | | - | |
| 372 | + | |
385 | 373 | | |
386 | 374 | | |
387 | 375 | | |
388 | 376 | | |
389 | 377 | | |
390 | 378 | | |
391 | | - | |
| 379 | + | |
| 380 | + | |
392 | 381 | | |
393 | 382 | | |
394 | 383 | | |
0 commit comments