Forgus / spock

Automatically exported from code.google.com/p/spock
0 stars 0 forks source link

Better output for interaction failures #265

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Here is an example to illustrate:

import spock.lang.Specification

class Foo
{
    Collaborator collaborator

    Foo(Collaborator collaborator)
    {
        this.collaborator = collaborator
    }

    void test(int param)
    {
        collaborator.process(param)
    }
}

interface Collaborator
{
    int process(int x)
}

class Test extends Specification
{
    def "demonstrate interaction failure output"()
    {
        setup:
        Collaborator collaborator = Mock()
        Foo foo = new Foo(collaborator)

        when:
        foo.test(value1)

        then:
        1 * collaborator.process(getExpectedValue(value2))

        where:
        value1 | value2
        1      | 1
        2      | 5
        3      | 3
    }

    int getExpectedValue(int n)
    {
        return n
    }
}

This produces the following output:

Too few invocations for:

1 * collaborator.process(getExpectedValue(value2))   (0 invocations)

    at org.spockframework.mock.InteractionScope.verifyInteractions(InteractionScope.java:66)
    at org.spockframework.mock.MockController.leaveScope(MockController.java:36)
    at Test.demonstrate interaction failure output(SpockEnhancementDemoScript.groovy:33)

There are three things I need to know that this isn't telling me:
1) Which row of the data table caused the failure?
2) What was the actual value from getExpectedValue()?
3) Was Collaborator.process() invoked at all?  How many times?  With what 
argument values?

Original issue reported on code.google.com by tchamber...@gmail.com on 30 Aug 2012 at 11:02

GoogleCodeExporter commented 8 years ago
1. is provided by @Unroll (see 
http://docs.spockframework.org/en/latest/data_driven_testing.html#reporting-of-f
ailures). As for 2. and 3, try 0.7-SNAPSHOT.

Original comment by pnied...@gmail.com on 30 Aug 2012 at 11:05

GoogleCodeExporter commented 8 years ago

Original comment by pnied...@gmail.com on 9 Sep 2012 at 3:02