{"action":"created","issue":{"url":"https://api.github.com/repos/spockframework/spock/issues/702","repository_url":"https://api.github.com/repos/spockframework/spock","labels_url":"https://api.github.com/repos/spockframework/spock/issues/702/labels{/name}","comments_url":"https://api.github.com/repos/spockframework/spock/issues/702/comments","events_url":"https://api.github.com/repos/spockframework/spock/issues/702/events","html_url":"https://github.com/spockframework/spock/issues/702","id":212406452,"number":702,"title":"Verification causes mock to behave in an unexpected way","user":{"login":"behrangsa","id":18451,"avatar_url":"https://avatars3.githubusercontent.com/u/18451?v=3","gravatar_id":"","url":"https://api.github.com/users/behrangsa","html_url":"https://github.com/behrangsa","followers_url":"https://api.github.com/users/behrangsa/followers","following_url":"https://api.github.com/users/behrangsa/following{/other_user}","gists_url":"https://api.github.com/users/behrangsa/gists{/gist_id}","starred_url":"https://api.github.com/users/behrangsa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/behrangsa/subscriptions","organizations_url":"https://api.github.com/users/behrangsa/orgs","repos_url":"https://api.github.com/users/behrangsa/repos","events_url":"https://api.github.com/users/behrangsa/events{/privacy}","received_events_url":"https://api.github.com/users/behrangsa/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-03-07T11:34:35Z","updated_at":"2017-03-07T12:03:05Z","closed_at":null,"body":"# Adding a mock verification interaction statement changes the mock's behavior\r\n\r\nWithout mock interaction verification, this test is passing:\r\n\r\n```java\r\n    def \"it should mock get\"() {\r\n        given:\r\n        def httpClient = Mock(HttpClient)\r\n\r\n        and:\r\n        httpClient.get({ it.contains(\"/book\") }) >> null\r\n        httpClient.get({ it.contains(\"/text-book\") }) >> \"text-book\"\r\n\r\n        when:\r\n        def result1 = httpClient.get(\"/book\")\r\n        def result2 = httpClient.get(\"/text-book\")\r\n\r\n        then:\r\n        result1 == null\r\n        result2 == \"text-book\"\r\n    }\r\n```\r\n\r\nHowever adding a verification statement to the end of the test, causes `result2` to become `null`, rather than the expect value of `\"text-book'`:\r\n\r\n```\r\n        and:\r\n        2 * httpClient.get(_)\r\n```\r\n\r\n\r\n# How to reproduce\r\n\r\n* Clone https://github.com/behrangsa/why-spock\r\n* Run the `org.behrang.why.spock.RestServiceTest#it should mock get\"` test (passes)\r\n* Run the `org.behrang.why.spock.RestServiceTest#it should mock and verify get\"` test (fails but should pass)\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/spockframework/spock/issues/comments/284703127","html_url":"https://github.com/spockframework/spock/issues/702#issuecomment-284703127","issue_url":"https://api.github.com/repos/spockframework/spock/issues/702","id":284703127,"user":{"login":"behrangsa","id":18451,"avatar_url":"https://avatars3.githubusercontent.com/u/18451?v=3","gravatar_id":"","url":"https://api.github.com/users/behrangsa","html_url":"https://github.com/behrangsa","followers_url":"https://api.github.com/users/behrangsa/followers","following_url":"https://api.github.com/users/behrangsa/following{/other_user}","gists_url":"https://api.github.com/users/behrangsa/gists{/gist_id}","starred_url":"https://api.github.com/users/behrangsa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/behrangsa/subscriptions","organizations_url":"https://api.github.com/users/behrangsa/orgs","repos_url":"https://api.github.com/users/behrangsa/repos","events_url":"https://api.github.com/users/behrangsa/events{/privacy}","received_events_url":"https://api.github.com/users/behrangsa/received_events","type":"User","site_admin":false},"created_at":"2017-03-07T12:03:05Z","updated_at":"2017-03-07T12:03:05Z","body":"Even re-arranging the blocks and using `setup` and `interaction` the test still fails:\r\n\r\n```java\r\n    def \"it should mock and verify get\"() {\r\n        setup:\r\n        def httpClient = Mock(HttpClient) {\r\n            get({ it.contains(\"/book\") }) >> null\r\n            get({ it.contains(\"/text-book\") }) >> \"text-book\"\r\n        }\r\n\r\n        when:\r\n        def result1 = httpClient.get(\"/book\")\r\n        def result2 = httpClient.get(\"/text-book\")\r\n\r\n        then:\r\n        interaction {\r\n            2 * httpClient.get(_)\r\n        }\r\n\r\n        and:\r\n        result1 == null\r\n        result2 == \"text-book\"\r\n    }\r\n```"}}
{"actor":{"display_login":"behrangsa"}}