{"action":"created","issue":{"url":"https://api.github.com/repos/stretchr/testify/issues/350","repository_url":"https://api.github.com/repos/stretchr/testify","labels_url":"https://api.github.com/repos/stretchr/testify/issues/350/labels{/name}","comments_url":"https://api.github.com/repos/stretchr/testify/issues/350/comments","events_url":"https://api.github.com/repos/stretchr/testify/issues/350/events","html_url":"https://github.com/stretchr/testify/issues/350","id":177239638,"number":350,"title":"Allow dynamic returns based on arguments","user":{"login":"alexandrevicenzi","id":2637672,"avatar_url":"https://avatars.githubusercontent.com/u/2637672?v=3","gravatar_id":"","url":"https://api.github.com/users/alexandrevicenzi","html_url":"https://github.com/alexandrevicenzi","followers_url":"https://api.github.com/users/alexandrevicenzi/followers","following_url":"https://api.github.com/users/alexandrevicenzi/following{/other_user}","gists_url":"https://api.github.com/users/alexandrevicenzi/gists{/gist_id}","starred_url":"https://api.github.com/users/alexandrevicenzi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexandrevicenzi/subscriptions","organizations_url":"https://api.github.com/users/alexandrevicenzi/orgs","repos_url":"https://api.github.com/users/alexandrevicenzi/repos","events_url":"https://api.github.com/users/alexandrevicenzi/events{/privacy}","received_events_url":"https://api.github.com/users/alexandrevicenzi/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/stretchr/testify/labels/input%20needed","name":"input needed","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2016-09-15T17:39:49Z","updated_at":"2016-10-05T19:17:46Z","closed_at":null,"body":"[C# Moq](https://github.com/Moq/moq4/wiki/Quickstart) allows to return data based on call arguments.\r\n\r\n`testify/mock` don't. It's possible to do using `Run`, but it's a big mess of code.\r\n\r\nIt would be great to have something like this:\r\n\r\n```go\r\nmyMock.On(\"Load\", mock.AnythingOfType(\"string\")).ReturnFn(func (token string) (*MyObj, error) {\r\n    if isValid(token) {\r\n        return someStuff(), nil\r\n    } else {\r\n        return nil, errors.New(\"Oh!\")\r\n    }\r\n})\r\n```\r\n\r\nI can send a PR if someone like this idea."},"comment":{"url":"https://api.github.com/repos/stretchr/testify/issues/comments/251771619","html_url":"https://github.com/stretchr/testify/issues/350#issuecomment-251771619","issue_url":"https://api.github.com/repos/stretchr/testify/issues/350","id":251771619,"user":{"login":"ernesto-jimenez","id":1005,"avatar_url":"https://avatars.githubusercontent.com/u/1005?v=3","gravatar_id":"","url":"https://api.github.com/users/ernesto-jimenez","html_url":"https://github.com/ernesto-jimenez","followers_url":"https://api.github.com/users/ernesto-jimenez/followers","following_url":"https://api.github.com/users/ernesto-jimenez/following{/other_user}","gists_url":"https://api.github.com/users/ernesto-jimenez/gists{/gist_id}","starred_url":"https://api.github.com/users/ernesto-jimenez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ernesto-jimenez/subscriptions","organizations_url":"https://api.github.com/users/ernesto-jimenez/orgs","repos_url":"https://api.github.com/users/ernesto-jimenez/repos","events_url":"https://api.github.com/users/ernesto-jimenez/events{/privacy}","received_events_url":"https://api.github.com/users/ernesto-jimenez/received_events","type":"User","site_admin":false},"created_at":"2016-10-05T19:17:46Z","updated_at":"2016-10-05T19:17:46Z","body":"if you want different behaviors you can have different structs, or you could have the struct take a function:\r\n\r\n```\r\ntype yourCustomStruct struct {\r\n    yourMock\r\n    loadFn func(string) (*MyObj, error)\r\n}\r\n\r\nfunc (s *yourCustomStruct) Load(token string) (*MyObj, error) {\r\n    s.yourMock.Called(token) // <- this is assuming you want to do myMock.On(\"Load\", ...) and then assert it has been called\r\n    return s.loadFn(token)\r\n}\r\n```"}}
{"actor":{"display_login":"ernesto-jimenez"}}