-
Notifications
You must be signed in to change notification settings - Fork 21
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
HasValue
calls Scalar::value
twice on mismatch
#239
Comments
@andreoss indeed, that's a well known problem but quite hard to fix because of the way Matcher interface is designed: because it had two methods that can be called by assertion in case of mismatch, it's creating many problems like the one you highlight. The problem happens when testing inputs for example, they are sometimes read twice. It's expecting a lot from the object manipulated in those methods and that they behave the same every time they are called... I suspect sometimes that it was made with datastructures in mind and not objects. I think that because of this, even if we find a way for value to be called only once here, there will still be problems because the behaviour of the marcher will anyway be called multiple time. So either we decide to do Matcher as the main interface for assertion or we decide it's the responsibility of the test to take care of providing objects to the matchers that behave in a consistent manner. WDYT? |
@victornoel We could reimplement
|
@andreoss even though this would help solve the problem, I think the best would be to find an architectural solution that will prevent us from making mistakes. I'm a bit worried of using state in the matchers with caching and so on, also, this would solve the problem for one matcher, but not all of them, so we will have to be careful and write a lot of tests just to ensure things work as expected while a nice architectural solution should give us the same result by construction :) So we have two choices:
I would be ok to go with the second solution :) |
@victornoel The other way to archive this is to change |
@andreoss I don't think the problem is with the assertion itself: the root of the problem is that There are 3 solutions from my point of view:
The second can be quite tricky and IMHO dangerous because the behaviour of the Do you see other solutions? Or do you think I'm missing something that would make your proposals more adequate? |
https://github.com/llorllale/cactoos-matchers/blob/master/src/main/java/org/llorllale/cactoos/matchers/HasValue.java#L53
HasValue
should callvalue
only once.The text was updated successfully, but these errors were encountered: