spockframework / spockframework/spock
Multiple "when" block for single "then" block
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 3.6k
- Forks
- 483
- PR merge metrics
- No merged PRs in 30d
Description
Is your feature request related to a problem?
I have a lot of situations and I can't find my problem solution in documentation.
The problem is:
I have a lot of tests where I expect the same errors and data with similar, or the same given data. In these situations I have everywhere the same given and then blocks for each when block (when is ussualy invoking one method). In these situations I have a lot of boilerplate in test code which is not readable.
Describe the solution you'd like
I tried to use where block and give Clousure, or Runnable, then invoke it in when block, but iI got "Groovyc: Header of data table may only contain variable names"
The best in use will be multiple when: labels for every tested method
In documentation I found only multiple when: then:, but multiple when: for the same then: is needed.
Do you have some idea?
Describe alternatives you've considered
No response
Additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Begin with Spock's documentation and implementation of data-driven features, especially multiple when:/then: blocks, and reproduce the reported Groovyc error from the attempted where closure or Runnable approach. Done means the desired syntax or limitation is clearly established, with tests covering multiple when labels sharing one then block if the feature is supported.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy
- Domain
- testing
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100