-
-
Notifications
You must be signed in to change notification settings - Fork 395
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
Inverted include matcher never returns for infinite enumerables #1097
Comments
From a theoretical point of view you cannot, an infinite enumerable may at some point generate that value. The RSpec matchers have no idea of ordering.
This is for deep matching I believe, a fix might be interesting that works for all scenarios. It might be possible to fix the "infinite range" issue but I'm still unsure how deep matching would be affected by changing this behaviour |
Thanks for the quick reply @JonRowe I guess from my point of view, I'd always expect rspec to agree with the return value of the include? method, but any time an enumerable defines it's own (possibly optimised, possibly flawed) version of include?, there's a chance that rspec will disagree (as you said due to deep matching). I wonder if there's a clean way for rspec to distinguish between enumerables that have overridden include? vs those that inherit the default implementation from Enumerable... |
I guess there's also two different intents here. I'm specifically testing the implementation of the include? method, but other developers will be testing that the output of some other method "includes" a particular value, and whether that's determined using include? or any? or some other way is not important |
Its not the implementation of
in addition to checking nested values in arrays and hashes. Hence the use of Usually this works ok but evidently the new infinite enumerables behave a bit differently. Unless we can find a way to make
Its possible for this edge case we could detect things that require fuzzy matching and issue this warning, otherwise just use include, but I'm unsure if the extra complication is worth it. |
I don't think so |
@iainbeeston You may use
It's possible to define |
Subject of the issue
I would like to write a spec where I assert that a value should not be included in an enumerable that is lazy and infinite. For example:
However, the rspec include matcher goes into an infinite loop and never returns for these specs, despite the fact that
(1..).include?(0)
does returnfalse
immediately (forfibonaccci_sequence
it would depend on your implementation).Your environment
Steps to reproduce
I've created a simple test case on github here, which reproduces the issue using an infinite range. It's run on travis here
Expected behavior
If
include?
returns false, the expectation should fail.Actual behavior
It goes into an infinite loop and the expectation never completes.
It looks like this is because the matcher calls
any?
afterinclude?
and that does never return.The text was updated successfully, but these errors were encountered: