Skip to content

Attach SpecificationAttachable fixtures with @AutoAttach#2378

Draft
leonard84 wants to merge 1 commit into
external-mock-interactions-3-self-type-traitsfrom
external-mock-interactions-4-auto-attach
Draft

Attach SpecificationAttachable fixtures with @AutoAttach#2378
leonard84 wants to merge 1 commit into
external-mock-interactions-3-self-type-traitsfrom
external-mock-interactions-4-auto-attach

Conversation

@leonard84

Copy link
Copy Markdown
Member

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.

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.
@coderabbitai

coderabbitai Bot commented Jun 13, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6bb53c3e-cb19-481b-a2ac-1367b41250b0

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

leonard84 commented Jun 13, 2026

Copy link
Copy Markdown
Member Author

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.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@codecov

codecov Bot commented Jun 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.51%. Comparing base (02937a1) to head (0998c5c).

Additional details and impacted files

Impacted file tree graph

@@                               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           
Files with missing lines Coverage Δ
...ockframework/mock/runtime/GroovyMockMetaClass.java 92.85% <ø> (ø)
...va/org/spockframework/mock/runtime/MockObject.java 84.84% <ø> (ø)
.../src/main/java/spock/mock/AutoAttachExtension.java 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@testlens-app

testlens-app Bot commented Jun 13, 2026

Copy link
Copy Markdown

🚨 TestLens detected 1 failed test 🚨

Here is what you can do:

  1. Inspect the test failures carefully.
  2. If you are convinced that some of the tests are flaky, you can mute them below.
  3. Finally, trigger a rerun by checking the rerun checkbox.

Test Summary

Check Project/Task Test Runs
Verify Branches and PRs / Build and Verify (2.5, 8, windows-latest) :spock-specs:test BlockingVariablesSpec > variable may be null

🏷️ Commit: 0998c5c
▶️ Tests: 95928 executed
⚪️ Checks: 33/33 completed

Test Failures

BlockingVariablesSpec > variable may be null (:spock-specs:test in Verify Branches and PRs / Build and Verify (2.5, 8, windows-latest))
BlockingVariable.get() timed out after 1.00 seconds
	at spock.util.concurrent.BlockingVariable.get(BlockingVariable.java:114)
	at spock.util.concurrent.BlockingVariablesImpl.get(BlockingVariablesImpl.java:35)
	at spock.util.concurrent.BlockingVariables.getProperty(BlockingVariables.groovy:110)
	at spock.util.concurrent.BlockingVariablesSpec.variable may be null(BlockingVariablesSpec.groovy:106)

Muted Tests

Select tests to mute in this pull request:

  • BlockingVariablesSpec > variable may be null

Reuse successful test results:

  • ♻️ Only rerun the tests that failed or were muted before

Click the checkbox to trigger a rerun:

  • Rerun jobs

Learn more about TestLens at testlens.app.

@leonard84 leonard84 self-assigned this Jun 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant