Skip to content

Cannot specify interactions in both setup/given and then. #251

@robfletcher

Description

@robfletcher

Originally reported on Google Code with ID 129

What steps will reproduce the problem? If possible, provide source code and
stack trace.

package com.mayabansi.webapp.service.spock

import spock.lang.Specification

class OrderProcessServiceSpec extends Specification {

    def "Mock and give cardinality in setup: ONLY works"() {
        given:
            List<Integer> l = Mock()
            1 * l.get(0) >>  2;

        when:
            int i = l.get(0);

        then:
            i == 2
    }

    def "Mock and give cardinality in then: ONLY works"() {
        given:
            List<Integer> l = Mock()

        when:
            int i = l.get(0);

        then:
            1 * l.get(0) >>  2;
            i == 2
    }


    def "Mock, stub in given and check cardinality in interactions does not work"()
{
        given:
            List<Integer> l = Mock()
            l.get(0) >>  2;

        when:
            int i = l.get(0);

        then:
            1 * l.get(_)
            i == 2
    }
}

Stack trace:

Condition not satisfied:

i == 2
| |
| false
null

at com.mayabansi.webapp.service.spock.OrderProcessServiceSpec.Mocking and checking
interactions does not work(OrderProcessServiceSpec.groovy:56)


Process finished with exit code 255

What version of Spock and Groovy are you using?

<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>0.4-groovy-1.6</version>
<scope>test</scope>

Please provide any additional information below. You can also assign
labels.

Linux Mint
Java > 1.6
Groovy > 1.6 (based on Maven I believe)
Spock > 0.4 (based on Maven I believe)
IntelliJ Idea X IU-96.802


Reported by ravi.hasija on 2010-09-28 00:02:55


- _Attachment: [OrderProcessServiceSpec.groovy](https://storage.googleapis.com/google-code-attachments/spock/issue-129/comment-0/OrderProcessServiceSpec.groovy)_

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions