In the Spock specification, any string is expected: or , and then: will be evaluated and approved as boolean , unless it has a signature with a return type of void .
I noticed that for methods declared as void , there is something strange for any class that inherits from Navigator (for example, Page or Module classes).
Say we have an example like this:
class NavigationSpec extends GebSpec { def 'Collections page has a right header'() { when: to CollectionsPage then: hasHeaderText('Collections') } }
The hasHeaderText() method is defined in the CollectionsPage class as follows:
class CollectionsPage extends Page { static url = 'movies/collections' void hasHeaderText(String expectedText) { assert true } }
For the purpose, I simply state true there, so it should never fail. Although the error fails with the error:
Condition not satisfied: hasHeaderText('Collections') | null
How and why is the result of calling the void method evaluated as null ?
I know how to fix it. This is enough to declare the return type of the method as boolean and return true . This is ugly, though, like all other statements, otherwise unnecessary return true should be added as:
boolean hasHeaderText(String expectedText) { assert header.text() == expectedText return true }
It causes only noise. Is there a way to prevent Geb from returning null methods from void ?
Of course, I know that this particular case may look like this:
boolean hasHeaderText(String expectedText) { header.text() == expectedText` }
This does not explain the strangeness of the lost return type of the void type, not to mention the fact that we are losing a meaningful error message with this approach.