Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Spock spy for real object?

I wanna spy method calls of Spring bean. I checked docs - Spock can create spy only by constructor. Can Spock wrap already existing object by spy?

like image 572
fedor.belov Avatar asked Oct 20 '22 17:10

fedor.belov


1 Answers

It seems that it can't be done because of the fact that API doesn't support it. Have a look at API. The following piece of code runs with errors:

@Grab('org.spockframework:spock-core:0.7-groovy-2.0')
@Grab('cglib:cglib-nodep:3.1')

import spock.lang.*

class Test extends Specification {
    def 'test'() {
        given:    
        def o = new Object()
        def s = Spy(o)
    }
}
like image 80
Opal Avatar answered Oct 23 '22 00:10

Opal