Spock - extracting interactions to method
Asked Answered
W

1

13

The spock documentation points out that you can extract assertions of then block to other method and add assert keyword before each assertion.

I would also like to extract interactions to helper method. I tried wrapping interactions with interaction closure block but that did not work.

Is it possible? If it is how to achieve it?

Wessels answered 15/6, 2016 at 9:7 Comment(1)
It's rather not possible. Can you prepare a SSCCE?Insolvent
W
27

Turns out you can. You have to wrap helper method call with interaction:

then:
    interaction {
         helperMethod()
    }

and then you can put interactions in a helper method like that:

def helperMethod() {
    1 * someObj.getInt() >> 2
}

I did it other way around (wrapped helper method body in interaction), that's why it did not work

Wessels answered 15/6, 2016 at 13:52 Comment(1)
You should accept your own answer since it's correct :)Thapsus

© 2022 - 2024 — McMap. All rights reserved.