Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spock - extracting interactions to method

Tags:

java

groovy

spock

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?

like image 922
user3364192 Avatar asked Jun 15 '16 09:06

user3364192


1 Answers

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

like image 133
user3364192 Avatar answered Oct 19 '22 10:10

user3364192