jjh42 / mock

Mocking library for Elixir language
MIT License
639 stars 81 forks source link

Problems with Elixir 1.14.5 #139

Closed carlows closed 1 year ago

carlows commented 1 year ago

Context

I've upgraded my Elixir app to Elixir 1.14.5, and my current mock version is {:mock, "~> 0.3.8"}.

After the upgrade, all of my tests relying on this library are failing with this compilation error:

== Compilation error in file test/placement_service_web/mutations/services/test.exs ==
** (FunctionClauseError) no function clause matching in Mock.assert_called/1
    (mock 0.3.8) expanding macro: Mock.assert_called/1
    test/placement_service_web/mutations/services/test.exs:63: PlacementServiceWeb.Mutations.Services.Test."test update_status call CommandRouter with expected params and initiator"/1
    (elixir 1.14.5) expanding macro: Kernel.|>/2
    test/placement_service_web/mutations/services/test.exs:63: PlacementServiceWeb.Mutations.Services.Test."test update_status call CommandRouter with expected params and initiator"/1
    (mock 0.3.8) expanding macro: Mock.with_mocks/2
    test/placement_service_web/mutations/services/test.exs:54: PlacementServiceWeb.Mutations.Services.Test."test update_status call CommandRouter with expected params and initiator"/1
    (mock 0.3.8) expanding macro: Mock.with_mock/3
    test/placement_service_web/mutations/services/test.exs:54: PlacementServiceWeb.Mutations.Services.Test."test update_status call CommandRouter with expected params and initiator"/1

I'm importing Mock in my test cases, and this is how a test case mock looks like:

import Mock

...

with_mock CommandRouter, route: fn _event -> {:ok, match} end do
        subject.(mutation, initiator_header)

        %{
          match_id: match.id
        }
        |> CommandRouter.route()
        |> assert_called()
end

What could be the reason it stopped working? 🤔

carlows commented 1 year ago
Mock.assert_called(CommandRouter.route(%{
          match_id: match.id
}))

Using it this way solved the issue, I'm not really sure what's the problem though.