Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use instance variable in where section of Spock Test

Tags:

spock

Spock only allows static variables to be accessed from where block.

Is there any workaround using which Instance variables can be used inside the where block ?

like image 709
Biraj B Choudhury Avatar asked Mar 28 '14 07:03

Biraj B Choudhury


1 Answers

You can annotate instance variables with @Shared, see Spock manual, chapter "Sharing of Objects between Iterations".

Attention: Shared instance variables will retain their values in between iterations and be shared between methods. If you do not want this, do not use the approach. But as I understand you, you initialise variable values using tables or so in the where block anyway, so it should be okay.

like image 150
kriegaex Avatar answered Nov 23 '22 22:11

kriegaex