How to make Stub using Stub(class, closure) using Spock

212 Views Asked by At

I want to write spock test using Stub I have a class Site with two methods

    getText()
    getTitle()

So I write

MyTestClass{

Site site

def "test()"{
    site = Stub(Site){
                getText()<<"text"
                getTitle()<<"title"}
...
}
}

And the error

groovy.lang.MissingMethodException: No signature of method: 
com.example.MyTestClass.getText() is applicable for argument types: () values: []

Why Spock thinks that the getText() is part of MyTestClass, but not from Site?

1

There are 1 best solutions below

1
On BEST ANSWER

Turn the arrows the other way, e.g. getText() >> "text" :)