Fabrizio Fortino
Fabrizio Fortino

Reputation: 1616

spockframework: check expected result after every feature

I am using spockframework and geb for test automation. I would like to execute after every feature a simple check to be sure that no error dialogs are shown, I have added the following cleanup() method:

 def cleanup() {
    expect:
    $('.myErrrorDialogClass').isEmpty()
 }

The code is executed after every feature but it does not throw any error when the dialog is shown.

Upvotes: 1

Views: 288

Answers (1)

cjstehno
cjstehno

Reputation: 13994

Spock uses AST transforms to wire in the functionality for each test label (when, expect, etc); they may not run the transformations on the cleanup method. They are either not expecting or not encouraging assertions in cleanup, so that code may run but not actually assert anything.

You can get around this by using a standard Groovy assert call without the expect block.

Summarized from our comment discussion above - in case you want to accept it as an answer ;-)

Upvotes: 2

Related Questions