RSM
RSM

Reputation: 433

Create a combination on input in Spock test

In my Spock test this is my current where block

where:
        [A,B,C] << 
        [
            ["A1","B1","C1"],
            ["A1","B1","C2"],
        ]

I am trying to simplify this since my input for A and B is always same. I am trying to use combinations() but have been unsuccessful.

I want something like this which does same job as a code above.

where:
        [[A,B],[C]] <<                 // incorrect
        [
            [["A1","B1"],["C1","C2"]].combinations()  // incorrect
        ]   

Currently I get NPE

Upvotes: 2

Views: 2848

Answers (2)

jekewa
jekewa

Reputation: 279

You need something like this:

where:
    [A, B, C] << [
        ['a1', 'a2', 'a3'],
        ['b1', 'b3'],
        ['c1']
    ].combinations()

You didn't have enough arrays to match your targets, or you tried to incorrectly group your targets into sub-arrays.

Upvotes: 2

Peter Niederwieser
Peter Niederwieser

Reputation: 123950

Here is one solution:

where:
[A, B, C] << [[["A1","B1"]],["C1","C2"]].combinations()*.flatten()

Upvotes: 7

Related Questions