vendredi 5 juin 2015

Spock - objects equality, excluding fields

I need to make an assertion on the following groovy object (which is Java map actually?):

_id: should be excluded in tests,
a: value,
b: value,
nested: [
    [
        _id: shoud be excluded,
        c: value,
        d: value
    ],
    [
        _id: shoud be excluded,
        c: value,
        d: value
    ]

]

Within my unit test, I don't have access to ids (they're generated automatically). What's more, I don't event care about the ids and only want to make assertions on the other fields.

Basically, what I would like to do is to use a wildcard (_) operator for id fields, just like on mock interactions. (i.e. 1 * mock.fancyMethod(_ as Something))

Is there any shortcut on this in Spock or do I have to write my own Hamcrest matcher or something?

Aucun commentaire:

Enregistrer un commentaire