Replies: 1 comment 2 replies
-
OK, I see that 8 years ago Peter already called this "a feature, not a workaround", cf. #26 (comment). The sheer number of issues you quoted above and questions on StackOverflow or elsewhere shows however, that this is one of the most counter-intuitive parts of Spock, whereas intuitivity is usually Spock's strong suit. I think that having to know the default behaviour as documented is OK for an advanced use case like this. But a way to explicitly override stubbing and/or interactions would definitely be a plus. I have seen the open PRs and am not sure if they are universal solutions, but I have not analysed them in detail either. I am feeling it is kind of a weak proposition on my part to say "it is not nice the way it is" without suggesting something better in more concrete terms
My feedback simply is: If something could be done here in order to improve the situation, it might be worth for the Spock team to spend some time thinking about this issue and designing a better solution. |
Beta Was this translation helpful? Give feedback.
-
Continuation of this conversation on Stackoverflow.
You normally use it for combined mocking assertions with stubbing, and currently it is the only way to do this. There are some attempts to change this, but they all have other drawbacks. So, if you have a mock use
_ * mock.method() >> value
if you only have a stub you have to leave the interaction count out and just dostub.method() >> value
in the then block.I wouldn't call overriding an interaction an anti-pattern per se. There are certainly cases where it is the smaller code smell. For example, you have a large spec in which 10+ features all require the same stubbing and then you want to test one error use-case where you have to change the interaction to something else. You could move the stubbing from the
setup
to its own method and call that one in all 10+ feature'sgiven
blocks, or you leave it in the setup and override the interaction in that one exceptional feature.The solutions proposed - as an alternative to the
then
-block interactions - so far was to invert the order in which Spock would match interactions, from match first to match last.Here is a list of related issues #26, #251, #321, #962, #1219, and #1308
Beta Was this translation helpful? Give feedback.
All reactions