Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To make a Groovy Spock test compare invocation parameters using equals instead of ==, you can use the .equals() method instead of the == operator when specifying the expected invocation parameters. Here is an example code snippet:

def "Test some method with expected parameters"() {
    given:
    def objectUnderTest = new ObjectUnderTest()

    when:
    def result = objectUnderTest.someMethod("param1", "param2")

    then:
    1 * objectUnderTest.someMethod("param1".equals(_), "param2".equals(_)) >> "expectedResult"
}

In this example, the _ symbol is used as a wildcard for any value passed in as an argument to the someMethod method. The .equals() method is then called on the expected parameters to perform the comparison using the equals method instead of the == operator.