error messages when interaction closure is used

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

error messages when interaction closure is used

Brett Borchardt
When I use the interaction closure to define custom interactions, everything works fine. However, when there are errors, the message printed is not very user friendly. For example, in the following test (this is contrived, but I have some real scenarios where I want to drive interactions based on a where block):

    def "use variables in interaction"() {
        given:
        def runnable = Mock(Runnable)
        def executor = new Executor() {
            @Override
            void execute(Runnable command) {
                command.run()
            }
        }
        def numInvocations = 2
        def methodToInvoke = 'run'

        when:
        executor.execute(runnable)

        then:
        interaction {
            numInvocations * runnable."$methodToInvoke"()
        }
    }

Spock correctly figures out that I only called run once and not twice and fails the test. Here's the message that is printed:

    Too few invocations for:
 
    numInvocations * runnable."$methodToInvoke"()   (1 invocation)

Am I doing something that's frowned upon here? If not, is the format of the error message intentional or is there a way to get it to print the actual invocation that's expected?

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: error messages when interaction closure is used

Leonard Brünings
No, afaik it is not possible to see the actual expected invocation. Feel free to open a feature request in the issue tracker.

For your data driven problem you could put the expected method and the count in the @Unroll description, if your test
is simple enough.

cheers
Leonard


On Wednesday, June 10, 2015 at 1:31:39 AM UTC+2, Brett Borchardt wrote:
When I use the interaction closure to define custom interactions, everything works fine. However, when there are errors, the message printed is not very user friendly. For example, in the following test (this is contrived, but I have some real scenarios where I want to drive interactions based on a where block):

    def "use variables in interaction"() {
        given:
        def runnable = Mock(Runnable)
        def executor = new Executor() {
            @Override
            void execute(Runnable command) {
                command.run()
            }
        }
        def numInvocations = 2
        def methodToInvoke = 'run'

        when:
        executor.execute(runnable)

        then:
        interaction {
            numInvocations * runnable."$methodToInvoke"()
        }
    }

Spock correctly figures out that I only called run once and not twice and fails the test. Here's the message that is printed:

    Too few invocations for:
 
    numInvocations * runnable."$methodToInvoke"()   (1 invocation)

Am I doing something that's frowned upon here? If not, is the format of the error message intentional or is there a way to get it to print the actual invocation that's expected?

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.
Loading...