-
Notifications
You must be signed in to change notification settings - Fork 470
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
Mocking in given block is ignored when mocked in setup method #962
Comments
Thanks @huehnerlady +1 |
@robfletcher @leonard84 could you maybe have a look at this as you were looking at the similar issue this one was created from? |
Is there the possibility to get some answer here? It is open for 2 months now... |
@leonard84 @Vampire @MartyIX can please someone take a statement to my issue? It is open since middle of January and nobody answered which is really disappointing! |
@huehnerlady I'm not affiliated with Spock in any way. I have just contributed a few patches. You can try https://gitter.im/spockframework/spock though :) |
@MartyIX sorry I just took the people that contributed in the last few months, but thanks I will try that :) |
Same for me, it is pretty rude to randomly ping contributors. If at all, ping team members. But actually, this is an open source project where people contribute their sparse spare time, so you cannot always expect timely answers. You could fix the behaviour and send a patch though. ;-) |
@Vampire I am really sorry, I did not think of that. I did try to address the issue as recommended by MartyIX. but the patch is a good idea as well, thanks |
@huehnerlady sorry for the late answer. We are working on spock-2.0 at the moment, so please wait for contributions until that branch is merged to master, otherwise it will create unnecessary effort. Regarding your issue, as I said in #321 there is a current working way to override the setup behavior, so I see the priority not so high. Furthermore, the semantics are unclear. From a user endpoint I could read two things happening for
|
the problem is as described in the other issue that it is confusing the way it is at the moment, as you have to override things in the To me the behaviour is clear as you do not want to add functionality but override existing functionality, so it would be the second approach. Keep in mind that this is how junit works as well. When will the 2.0 branch be merged into master? Many thanks |
JUnit does not provide any mocking functionality that I know of. Did you mean Mockito?
Let me quote Blizzard here, |
By default Spock uses a match first algorithm to determine the defined return value of a method. So whenever there are multiple defined return values, it will pick the first (that is not exhausted). This change enables a user to change this to a match last algorithm. So Spock will pick the last defined return value (that is not exhausted). This enables easy overriding of default return values. As requested in issue spockframework#26, spockframework#251, spockframework#321 and spockframework#962.
Btw. the "when it's done" happened already. :-) |
The Interactions now allow to override other interactions, if these are the same and do not specify a cardinality. This fixes spockframework#962
I have opened the PR #1762 to try to fix this issue, with my expectation of the API. If I write
I want these three invocations.
I do not care, give me that last declaration in this order setup => given=>when => then. This would fix the issue here, but preserve most of the original behavior of Spock. This can possibly be a breaking change, when someone relies on the existing strange behavior, but I think this can be neglected. None of the existing spock tests in this repo broke. |
The Interactions now allow to override other interactions, if these are the same and do not specify a cardinality. This fixes spockframework#962
Issue description
Currently you can declare a certain mocked behaviour in the setup method, which will then be used for every test in the class. If you want to override that behaviour you HAVE to put it in the then block. This is very confusing to people as it is not the natural flow they would describe the test
How to reproduce
groovy example of a test
Tests in words:
In this case the second test will fail
You would have to write something like
In words:
To me the first wording of the test is a natural flow in comparison to the second version.
So my proposal is to add the given block to override the declarations of the setup-Method.
It is Important though, that the then-Block should still always win as you need to verify how often methods are called as well.
The text was updated successfully, but these errors were encountered: