freerange / mocha

A mocking and stubbing library for Ruby
https://mocha.jamesmead.org
Other
1.23k stars 158 forks source link

Since #648 `has_entry` no longer matches by exact value #654

Closed ElvinEfendi closed 4 months ago

ElvinEfendi commented 4 months ago

Since https://github.com/freerange/mocha/pull/648, has_entry's behaviour changed:

require "bundler/setup"
require "minitest/autorun"
require "mocha/minitest"
require "mocha/mock"

class FooTest < Minitest::Test
  def setup
    @mock = mock("foo")
  end

  def test_mocha_mocking_kw_args_with_has_entry
    @mock.expects(:bar).with(has_entry(:a, k: "v"))

    @mock.bar(a: { k: "v", extra: "extra" })
  end
end

In the versions before the linked PR the test above would fail because { k: "v", extra: "extra" } is different than the expected {k: "v"}. But after that PR the test above succeeds.

floehopper commented 4 months ago

@ElvinEfendi Thanks for reporting this - sorry for the slow response - I've been away on leave. I'll take a look as soon as I can.

floehopper commented 4 months ago

@ElvinEfendi

I've had an initial look at this and I agree that it is an accidental regression caused by #648.

Many thanks for supplying a test that reproduces the problem.

I've attempted a quick fix in #655.

If you get a chance, could you try out the code in the fix-has-entry-with-keyword-args-regression branch and see if it fixes your problem...?

floehopper commented 4 months ago

@ElvinEfendi I've just released the fix in v2.4.1. I hope it solves your problem!