-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature request - support stubbing with *multiple* hardcoded values #11
Comments
Hi @beluchin Interesting idea, I can see the value in being able to supply a sequence of responses to a stub but perhaps it would be better to default to nil when the sequence of responses has been exhausted: (testing "multiple hardcoded values"
(let [f (spy.core/stub 42 24)]
(is (= 42 (f))
(is (= 24 (f))
(is (nil? (f))))) Another option is to throw an exception once the list of responses is exhausted instead of returning nil, or for this to be a different You can also achieve the same thing by using (let [responses (atom [42 24])
responder (fn []
(let [response (first @responses)]
(swap! responses rest)
response))
f (spy/spy responder)]
(is (= 42 (f)))
(is (= 24 (f)))
(is (nil? (f)))) ps. If you want to modify Thank you for the positive comments and for using spy! |
such behavior would be inconsistent with the existing semantics of
Agree. However, I see a gain in readability afforded by the |
The reason I'm unsure is that it adds behaviour to I think there is room in this library for a namespace providing helper functions for common patterns (such as returning a value on nth call, throwing an exception on nth call...) but I need to spend some time thinking about first. |
In that light, I see two clear concepts here related to wrapping an original function: mocks and spies. They both allow interaction verifications and: I don't see what a notion of stubs adds to that picture. From the above follows that mocks need to be provided the function to replace the original function's implementation with. In that case the library of helpers would make sense. |
Hello - great little library!
I was wondering whether you would be open to enhancing
spy.core/stub
to support multiple hardcoded values. For example:If so, I could give it a shot and submit a pull request for you.
Interested?
The text was updated successfully, but these errors were encountered: