Search code examples
assertgeb

For Geb's given when then, is there a way to ignore an assertion in 'then'


Situation

For my test, I have a step that asserts the return value of a method. The method takes a boolean value as a parameter (among other things). I could create a new column with that boolean value, however _variableB happens to mirror the boolean value I want.

Problem

When I run this step, Geb asserts on _variableB == 'some text' itself, rather than just using it as a parameter.

then:
    MethodA(something, something, _variableB == 'some text')

where:
    _variableA | _variableB

Question

Is there a way of ignoring/disabling this assertion?

Edit: inserted received error

Received error

Condition not satisfied:

Validator.waitForxxxxxxOnValidate(_xxxxxxType, xxxxxData.xxxxxxIdHex, _receivers == 'partner2')
|                     |                            |                |            |             |          |
|                     null                         xxxxxx-xxx      |            |             partner1       false
class xx.xxxx.partner2.helpers.xxxxxxValidator                    |            |                        1 difference (75% similarity)
                                                                    |            |                        partner(1)
                                                                    |            |                        partner(2)

Solution

  • First of all, Geb does not assert anything because it's not a testing framework, it's a browser automation framework. You seem to be using Spock, which is a testing framework and which performs implicit assertions based on given/when/then code labels.

    Secondly, your assumption that _receivers == 'partner2' is asserted is incorrect. All that happens is that when the implicit assertion on the call to Validator.waitForxxxxxxOnValidate() fails (because it returns null as per the failure you included) Spock is printing partial values of the asserted expression to make it easier for you to understand why the assertion failed. It just shows you that the value of _receivers is "partner1" and that because it's not equal to "partner2" false is passed as the last argument of the call to Validator.waitForxxxxxxOnValidate()