-
-
Notifications
You must be signed in to change notification settings - Fork 159
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
with(...) { ... }
should match both given args and block, or reject both
#606
Comments
Well spotted and thanks for reporting - I'm amazed someone hasn't come across that before! I agree with that option A would be better / less surprising. Either way, Mocha will need to display a deprecation warning before the behaviour is changed. Your question has also made me wonder whether calling |
Yeah, I considered that this would be a potentially breaking change. I figured a deprecation + config option to opt-in would be the way to go, regardless of
🤔 I'm not sure I follow what you mean here? Do you mean that |
Sorry I missed a crucial bit in that sentence - it should've read:
e.g. Having written it out more explicitly, perhaps it's unlikely that someone would do it, but it is technically possible. A bit of a hazard with a chain-able API, I guess. |
This is accidental and possibly undesirable behaviour, but it seems like an improvement to at least document the current behaviour. Clarifies potentially confusing behaviour which resulted in the opening of #606.
This is accidental and possibly undesirable behaviour, but it seems like an improvement to at least document the current behaviour. Clarifies potentially confusing behaviour which resulted in the opening of #606.
Context
Consider the following code
Currently, only the block matcher will be checked, and
instance_of(Foo)
will be ignored.This is because specifying
expected_parameters
and amatching_block
are silently mutually exclusive. We can see this by following the code toParametersMatcher#match?
mocha/lib/mocha/expectation.rb
Lines 269 to 272 in f7e1763
mocha/lib/mocha/parameters_matcher.rb
Lines 5 to 18 in f7e1763
match?
checks if a block was provided, and if so matches against that. It only matches against theexpected_parameters
if no block was given.This means it is possible to write the following passing test:
Proposal
Match against the parameter matchers and the block. Something like:
Raise if passed both expected parameters and a block are given
Opinion
My gut feeling is🅰️ would be better.
The text was updated successfully, but these errors were encountered: