Attach SpecificationAttachable fixtures with @AutoAttach#2378
Conversation
Extend `@AutoAttach` so an annotated field whose value implements `SpecificationAttachable` receives the running spec automatically: the extension calls `attach(spec)` during `setup` and `detach()` during `cleanup`. This lets a `MockInteractionSupport` fixture obtain its owning spec without constructor wiring. `SpecificationAttachable` is promoted from the internal `org.spockframework.mock.runtime` package to `spock.mock`, since users now implement it. The old interface remains as a deprecated alias extending the new one, so existing implementors keep satisfying `instanceof` checks against the new type; all internal implementors now reference the new location. `AutoAttachExtension` checks `MockUtil.isMock` before the `SpecificationAttachable` check: a mock proxy implements all interfaces of the mocked type, so a mock of a type that implements `SpecificationAttachable` must be attached as a mock instead of having the `attach` call swallowed by its own interceptor. A field that is neither gets a clear error. Adds a behaviour spec for the attachable-fixture path (including the mock-of-an-attachable-type ordering case) and updates the invalid-usage spec for the new error message; documents the pattern in the MockInteractionSupport section.
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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 |
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## external-mock-interactions-3-self-type-traits #2378 +/- ##
================================================================================
Coverage 82.51% 82.51%
+ Complexity 4940 4937 -3
================================================================================
Files 481 481
Lines 15478 15484 +6
Branches 1999 2002 +3
================================================================================
+ Hits 12771 12777 +6
Misses 1998 1998
Partials 709 709
🚀 New features to boost your workflow:
|
🚨 TestLens detected 1 failed test 🚨Here is what you can do:
Test Summary
🏷️ Commit: 0998c5c Test FailuresBlockingVariablesSpec > variable may be null (:spock-specs:test in Verify Branches and PRs / Build and Verify (2.5, 8, windows-latest))Muted TestsSelect tests to mute in this pull request:
Reuse successful test results:
Click the checkbox to trigger a rerun:
Learn more about TestLens at testlens.app. |

Extend
@AutoAttachso an annotated field whose value implementsSpecificationAttachablereceives the running spec automatically: theextension calls
attach(spec)duringsetupanddetach()duringcleanup.This lets a
MockInteractionSupportfixture obtain its owning spec withoutconstructor wiring.
SpecificationAttachableis promoted from the internalorg.spockframework.mock.runtimepackage tospock.mock, since users nowimplement it. The old interface remains as a deprecated alias extending the
new one, so existing implementors keep satisfying
instanceofchecks againstthe new type; all internal implementors now reference the new location.
AutoAttachExtensionchecksMockUtil.isMockbefore theSpecificationAttachablecheck: a mock proxy implements all interfaces of themocked type, so a mock of a type that implements
SpecificationAttachablemust be attached as a mock instead of having the
attachcall swallowed byits own interceptor. A field that is neither gets a clear error.
Adds a behaviour spec for the attachable-fixture path (including the
mock-of-an-attachable-type ordering case) and updates the invalid-usage spec
for the new error message; documents the pattern in the MockInteractionSupport
section.