spockframework / spockframework/spock

Allow to resuse value from previosu cell in data table

Open
#1,047 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
3.6k
Forks
483
PR merge metrics
No merged PRs in 30d

Description

I would like to suggest a new feature for data tables. data tables already allow to refer to variables to the left in the same row. I thought it would be great if it was also possible to reference value from same cell but from previous row. I managed to roll out my own solution for this by means of data pipes:

@Unroll("max(#a,#b)==#c")
  def 'Trick'( def a, def b, def c) {
    expect:
    Math.max(a, b) == c
    where:
    [a, b, c] << Spock.dataTable(
      [
        [5, 1, 5],
        [_, 2, _],
        [_, 3, _],
        [_, 4, _],
        [_, 5, _],
        [5, 6, 6]
      ]
    )
  }

and the dataTable function goes like this:

static List dataTable( List data ) {
        for( int i=0;i<data.size();++i ) {
            List row = data[i];
            for( int j=0;j<row.size();++j ) {
                if( row[j] instanceof Wildcard) {
                    row[j]=data[i-1][j]
                }
            }
        }
        data;
    }

It should be clear from the dataTable what is meant as the result.

I think that Spock AST transformation could easily perform the work for me
Table of the form:

where:
 a | b | c
 5 | 1 | 5
 _ | 2 | _
 _ | 3 | _ 
 _ | 4 | _ 
 _ | 5 | _ 
 _ | 6 | 6

could easily be transformed to

where:
 a | b | c
 5 | 1 | 5
 5 | 2 | 5
 5 | 3 | 5 
 5 | 4 | 5 
 5 | 5 | 5 
 5 | 6 | 6

and the processed like any other dataTable

The reason for this feature would be that i'm working with long nested lists as values in table cells and i would like not to repeat my self

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No file or test is named. Start by tracing Spock's data table handling and AST transformation entry points; the desired result is for an underscore cell to reuse the value from the same column in the previous row before the table is processed normally.

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
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.