Skip to content

Support arrays and maps in verifyEach - #2398

Draft
leonard84 wants to merge 4 commits into
spockframework:masterfrom
leonard84:verifyEach-supports-arrays
Draft

Support arrays and maps in verifyEach#2398
leonard84 wants to merge 4 commits into
spockframework:masterfrom
leonard84:verifyEach-supports-arrays

Conversation

@leonard84

Copy link
Copy Markdown
Member

Extends verifyEach beyond Iterable so it can also assert on object arrays and Maps.

Changes

  • Arrays: verifyEach now accepts object arrays, not only Iterable.
  • Maps: verifyEach accepts a Map, iterating its entries with Groovy's key/value destructuring, mirroring the Map.each idiom. The closure can use zero to three parameters:
    • no parameters: the current Map.Entry is the delegate, so key/value are referenced directly
    • one parameter: the entry
    • two parameters: the key and the value
    • an optional trailing parameter: the iteration index
  • Up-front validation: the closure parameter count is now validated before iteration, throwing a clear InvalidSpecException for an unsupported count (0 to 2 for iterables/arrays) instead of failing with a less obvious error mid-iteration.

Docs & tests

  • Primer section and release notes updated (including a Breaking Changes entry for the stricter parameter validation).
  • New smoke tests in VerifyEachBlocks.groovy and a primer doc spec + snapshot.

🤖 Generated with Claude Code

Add verifyEach(U[], ...) overloads that delegate to the existing
Iterable versions via Arrays.asList, so object arrays can be used
directly without wrapping them in a list first.
Add verifyEach(Map<K, V>, ...) overloads that iterate the map's
entries. Following Groovy's Map.each idiom, the closure can use zero
to three parameters: none (the entry is the delegate, exposing key
and value), the entry, key and value, or key, value and index.
Reject an unsupported number of closure parameters (0 to 2 for
iterables and arrays, 0 to 3 for maps) with a clear InvalidSpecException
before iterating, instead of collecting a confusing per-item failure for
each element. A zero-parameter closure asserts against the delegate (the
item, or the map entry exposing key and value).
@coderabbitai

coderabbitai Bot commented Jul 24, 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 Plus

Run ID: 36a946c2-d182-48ef-bef7-36a8a83aa6ff

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.

@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.07843% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.39%. Comparing base (9cf773d) to head (514f39d).

Files with missing lines Patch % Lines
...k-core/src/main/java/spock/lang/Specification.java 85.71% 1 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2398      +/-   ##
============================================
+ Coverage     82.28%   82.39%   +0.10%     
- Complexity     4884     4903      +19     
============================================
  Files           474      474              
  Lines         15267    15314      +47     
  Branches       1964     1968       +4     
============================================
+ Hits          12563    12618      +55     
+ Misses         2004     1999       -5     
+ Partials        700      697       -3     
Files with missing lines Coverage Δ
.../java/org/spockframework/runtime/SpockRuntime.java 85.60% <100.00%> (+2.12%) ⬆️
...k-core/src/main/java/spock/lang/Specification.java 80.64% <85.71%> (+1.47%) ⬆️

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@leonard84
leonard84 force-pushed the verifyEach-supports-arrays branch from 3ee054e to 3ce070a Compare July 24, 2026 16:20
Add verifyEach overloads accepting java.util.stream.Stream (with and
without a namer), adapting the single-use stream to an Iterable that is
iterated exactly once.
@leonard84
leonard84 force-pushed the verifyEach-supports-arrays branch from 3ce070a to a7ef128 Compare July 24, 2026 16:21
@testlens-app

testlens-app Bot commented Jul 24, 2026

Copy link
Copy Markdown

🔎 No tests executed 🔎

🏷️ Commit: a7ef128
▶️ Tests: 0 executed
⚪️ Checks: 7/7 completed


Learn more about TestLens at testlens.app.

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