-
-
Notifications
You must be signed in to change notification settings - Fork 103
Open
Description
Summary
PR #854 refactored some tests in spec/shakapacker/compiler_spec.rb to use explicit have_received/not_to have_received assertions instead of indirect call_count counter patterns. However, several tests still use the anti-pattern and should be refactored for consistency.
Remaining tests to refactor
The following tests still use call_count patterns:
- Line ~112: "handles hook with both stdout and stderr"
- Line ~168: "handles hook commands with spaces in paths using Shellwords"
- Line ~194: "supports hooks with additional arguments" (if exists)
- Line ~241: "passes configured environment variables to precompile_hook" (if exists)
- Line ~274: "merges hook environment variables with Rails.application.config_for" (if exists)
Why this matters
- Consistency: All tests should follow the same pattern
- Self-documenting: Explicit assertions make test intent clearer
- Robustness: Tests won't break if unrelated implementation details change
- Better failure messages: "expected not to receive X" vs "expected 1, got 2"
Additional considerations
Mock setup patterns
The codebase now has two patterns:
- Tests that need to differentiate calls: Use conditional blocks
- Tests where hooks aren't called: Use simple
and_return
This is reasonable but worth documenting.
Skip test assertion
The "skips precompile_hook when SHAKAPACKER_SKIP_PRECOMPILE_HOOK=true" test uses:
expect(Open3).not_to have_received(:capture3).with(anything, hook_command, anything)
expect(Open3).to have_received(:capture3).onceThis could theoretically pass if the hook was called with different arguments. Consider making the mock setup more explicit.
Related
- PR Improve test assertions using explicit have_received checks #854: Initial refactoring of call_count patterns
- See
CLAUDE.mdtesting guidelines for the preferred pattern
🤖 Generated with Claude Code
coderabbitai
Metadata
Metadata
Assignees
Labels
No labels