Code Monkey home page Code Monkey logo

Comments (10)

josesei avatar josesei commented on August 26, 2024 1

@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

from mocha.

josesei avatar josesei commented on August 26, 2024 1

sounds good, thx!

from mocha.

floehopper avatar floehopper commented on August 26, 2024 1

@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.

from mocha.

josesei avatar josesei commented on August 26, 2024 1

Makes sense, thanks for the insights and all your work!

from mocha.

josesei avatar josesei commented on August 26, 2024

workaround is to use block matcher

from mocha.

floehopper avatar floehopper commented on August 26, 2024

@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.

def test_should_match_keyword_args_with_matchers_using_keyword_args
matcher = Hash.ruby2_keywords_hash({ key_1: is_a(String), key_2: is_a(Integer) }).to_matcher(top_level: true) # rubocop:disable Style/BracesAroundHashParameters
assert matcher.matches?([Hash.ruby2_keywords_hash({ key_1: 'foo', key_2: 2 })]) # rubocop:disable Style/BracesAroundHashParameters
end

from mocha.

floehopper avatar floehopper commented on August 26, 2024

@josesei Quick question - were these tests working with earlier versions of Mocha (e.g. v2.2.0)?

Actually - ignore that!

from mocha.

josesei avatar josesei commented on August 26, 2024

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

from mocha.

floehopper avatar floehopper commented on August 26, 2024

@josesei Thanks for testing. The problem was something I accidentally introduced in v2.3.0 (specifically f94e250) 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.

from mocha.

floehopper avatar floehopper commented on August 26, 2024

This fix has been released in v2.4.3.

from mocha.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.