@ConfineMetaClassChanges([StatisticsService])
StatisticsServiceIntegrationTest extends IntegrationSpec {
StatisticsService statisticsService
void "count login to private area"() {
setup:
def user = new User(statistics: new UserStatistics())
statisticsService.metaClass.getCurrentUser = { -> user }
when:
statisticsService.countLoginPA()
then:
user.statistics.logins == 1
}
}
http://spockframework.github.io/spock/javadoc/1.0/spock/util/mop/ConfineMetaClassChanges.html