Closed josesei closed 3 months ago
workaround is to use block matcher
@floehopper just in case
module ParameterMatchers
# @private
class PositionalOrKeywordHash < Base
def matches?(available_parameters)
parameter, is_last_parameter = extract_parameter(available_parameters)
# return false unless HasEntries.new(@value).matches?([parameter]) <---- commenting this line makes the tests pass
Possibly you need that for something else, but I'd love to get that fixed
@josesei Thanks for reporting this. I had independently come to the same conclusion as you as to where the problem lies. I've managed to write a couple of failing unit tests in #660 which reproduce the issue. That line of code is needed to handle nested matchers with keyword arguments (see test below), but clearly the implentation isn't quite right. My head is pretty scrambled right now, but I'll try to get it fixed as soon as I can.
sounds good, thx!
@josesei ~Quick question - were these tests working with earlier versions of Mocha (e.g. v2.2.0)?~
Actually - ignore that!
@josesei I've got some tidying up to do and some double-checking I haven't broken anything else, but I think the changes in the fix-regression-in-matching-hash-parameter
branch should fix your problem. If you get the chance, I'd really appreciate it if you could see if it does fix the problem.
yep, it does work now! appreciate the effort!
it worked for me for ruby 2.6 and rails 5, mocha version mocha (1.13.0)
I guess it has to do with the keyword params compat thingy, but I'm sure you have it
@josesei Thanks for testing. The problem was something I accidentally introduced in v2.3.0 (specifically https://github.com/freerange/mocha/commit/f94e250414335d822ec8d0a1331cb25cf90bf837) as a fix for #647 where a Hash
parameter passed into Expectation#with
was implicitly wrapped in a call to #has_entries
. The latter does not require an exact match - only the specified entries have to match. The fix is to ensure that all entries match and that there are no extra entries. I hope to release the fix later today.
Makes sense, thanks for the insights and all your work!
This fix has been released in v2.4.3.
How to reproduce:
minitest (5.24.1) mocha (2.4.2) rails (6.1.7.8)
Ruby 3.3.0
Failure:
Minitest::Assertion: unexpected invocation: MyKlass.method_accepting_hash({}) unsatisfied expectations:
test/support/mocha_error_test.rb:31:in `block in'