lib/matchers/map.ex

defmodule Matcher.MapEmbeds do
  defstruct [:expected]

  defimpl Matcher.Protocol do
    def match(%{expected: expected}, actual, context) do
      Matcher.Utils.Maps.compare_maps(expected, actual, context, allow_unexpected?: true)
    end
  end
end

defmodule Matcher.MapEquals do
  defstruct [:expected]

  defimpl Matcher.Protocol do
    def match(%{expected: expected}, actual, context) do
      Matcher.Utils.Maps.compare_maps(expected, actual, context, allow_unexpected?: false)
    end
  end
end

defimpl Matcher.Protocol, for: Map do
  def match(expected, actual, context) do
    Matcher.match(%Matcher.MapEmbeds{expected: expected}, actual, context)
  end
end