Can Spock Spy For A Real Object?

I want to call the Spring bean spy method. I checked docs - Spock can only create a spy with a constructor. Can Spock wrap an existing object with a spy?

+4
source share
1 answer

It seems that this cannot be done because the API does not support it. Check out the API . The following code snippet works 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)
    }
}
+3
source

All Articles