rspec-wait
rspec-wait copied to clipboard
Do not use the same matcher instance on each wait iteration
Fixes: #20
Some notes on the rootcause and solution:
contain_exactly is one of those matchers that stores some intermediate computations internally. And hence we reuse this matcher object throughout the whole handle_matcher loop, it ignores the actual results and uses it's internal state computed on the first iteration.
The solution proposed is simply to clone initial matcher every iteration.
Please note that I have no idea is the solution is optimal, so any opinions welcome.
I have a feeling this is awesome and needed, but:
- I don't really understand what's happening in the tests. Can they be simplified or at least commented?
- I'm also confused as to why cloning the matcher doesn't copy the matcher's internal state as well? Is it because we only ever use cloned matchers, so they're cloned from an empty state?
- How did you decide between
cloneanddup?
Thank you for this contribution! 👏
Thank you very much for the immediate response.
- Yes they can! I completely forgot there is
Enumerator– a better way to have a simple object returning some predefined values on each call. I've updated the tests code. - Yes, exactly like this, we keep initial matcher as a sacred template and only use clones to do actual assertion.
- To be honest, it just felt like a safer choice, because
cloneseems a little more powerful andrspec-expectationclass system looks somewhat complicated. Anywaysdupworks just as well. I can change it if you feel like this is a better choice.
@laserlemon a kind reminder 😃