Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add more data to assertion message?

Spock has great assertion support. But I've got one problem - I wanna add more context data (for example url of the checked page) to assertion info.
I've tried assert a == b, [context] but in this case Spock doesn't print a and b values

like image 328
fedor.belov Avatar asked Nov 12 '13 08:11

fedor.belov


3 Answers

You can either rely on the default condition output, or define a custom message as already explained in another answer (e.g. assert a == b : "my message involving $url"). Besides you can customize the method name:

@Unroll
def "log in to #theUrl"() {
    ...
    where:
    theUrl = ...
}

You would typically use this if you wanted to repeat the same test for different URLs, but you can also use it for a single URL.

like image 188
Peter Niederwieser Avatar answered Nov 15 '22 22:11

Peter Niederwieser


Why just not do add a and b into the list after colon?

assert a == b, [a, b, context]

I know this is kind of redundant and message won't be formatted in nice Spock way, but still you can format it with GString in the way suitable for your need.

like image 23
topr Avatar answered Nov 16 '22 00:11

topr


I don't believe you can. Not sure what your test looks like, but maybe the @Unroll annotation could help here?

like image 1
tim_yates Avatar answered Nov 15 '22 22:11

tim_yates