Extend the top interaction scope to cleanup methods#2366
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (61)
✅ Files skipped from review due to trivial changes (12)
🚧 Files skipped from review as they are similar to previous changes (37)
📝 WalkthroughWalkthroughGlobal interactions declared outside ChangesGlobal Interactions Now Active Through Cleanup Methods
Sequence DiagramsequenceDiagram
participant SpecRewriter
participant FeatureMethod
participant MockController
SpecRewriter->>FeatureMethod: emit verifyLastScope() at exit
FeatureMethod->>MockController: verifyLastScope()
MockController->>MockController: rethrow prior interaction error / assert single scope / verify interactions
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Greptile SummaryThis PR fixes issue #616 by keeping the global (base) interaction scope alive through the
Confidence Score: 4/5The change is safe to merge; the core logic is correct and the scope-lifetime fix is well-reasoned. The mechanism — keeping the base InteractionScope alive via verifyLastScope() instead of removing it with leaveScope() — is correctly implemented. The defensive copy in TooFewInvocationsError protects against post-verification list mutations, and the Assert guard in verifyLastScope() is unreachable in all normal execution paths. The only gaps are a minor style nit, a documentation ambiguity around cleanup: blocks, and missing test coverage for the upper-cardinality breaking change called out in the release notes. MockController.java and GlobalInteractionsInCleanup.groovy deserve a second look — the former for the minor style nit, the latter for the missing upper-cardinality test case. Important Files Changed
Sequence DiagramsequenceDiagram
participant Runner as Spock Runner
participant Feature as Feature Method
participant MC as MockController
participant Scope as InteractionScope (base)
participant Cleanup as cleanup() Fixture Method
Runner->>MC: "new MockController() — addFirst(InteractionScope)"
Runner->>Feature: "setup() adds interactions via addInteraction()"
activate Scope
Runner->>Feature: "execute feature body (given/when/then/expect)"
Note over Feature,Scope: Stubs active during feature body
Feature->>MC: "verifyLastScope() [NEW — replaces leaveScope()]"
MC->>Scope: "verifyInteractions() — lower cardinality check"
Note over MC,Scope: Scope NOT removed — stays in deque
Feature-->>Runner: "return (scope still live)"
Runner->>Cleanup: "cleanup() fixture method executes"
Cleanup->>MC: "handle(invocation)"
MC->>Scope: "match(invocation) — stub response returned"
Note over Scope: Upper cardinality still enforced (breaking change)
Cleanup-->>Runner: done
deactivate Scope
Reviews (1): Last reviewed commit: "Extend the top interaction scope to clea..." | Re-trigger Greptile |
2a205d2 to
46eccf5
Compare
46eccf5 to
14b9ff9
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2366 +/- ##
=========================================
Coverage 82.17% 82.18%
- Complexity 4831 4832 +1
=========================================
Files 473 473
Lines 15051 15057 +6
Branches 1912 1912
=========================================
+ Hits 12368 12374 +6
Misses 1991 1991
Partials 692 692
🚀 New features to boost your workflow:
|
✅ All tests passed ✅🏷️ Commit: 14b9ff9 Learn more about TestLens at testlens.app. |

Fixes #616