I am trying to use the Mocking Library named Mox in my Elixir project, but even tho following the official documentation: https://hexdocs.pm/mox/Mox.html
I can't define a new behavior for my module functions. It gives me the following error when trying to run the test:
** (ArgumentError) module Myapp.MyModule is not a behaviour, please pass a behaviour to :for (mox) lib/mox.ex:210: Mox.validate_behaviour!/1 (mox) lib/mox.ex:198: Mox.defmock/2 (elixir) lib/code.ex:376: Code.require_file/2 (elixir) lib/enum.ex:678: Enum."-each/2-lists^foreach/1-0-"/2 (elixir) lib/enum.ex:678: Enum.each/2
Here's what I've tried so far:
test_helper.exs:
ExUnit.start()
Mox.defmock(Myapp.MockMyModule, for: Myapp.MyModule)
MyModuleTest.exs
defmodule MyModuleTest do
use ExUnit.Case
import Mox
setup :verify_on_exit!
test "Test status processor in transit with mocked result" do
Myapp.MyModule
|> expect (:put_calculated_eta, fn body, shipment_id, authorization_key -> {:ok, "bla", 200} end)
map = #Some data that fits the function interface
assert {:ok, "bla", 200} == Myapp.MyModule.update_shipment_eta(map)
end
end
What I think is the most weird is that in the documentation it does expect modules to be passed for mocking, but in the error it request for behaviours (which I guess should be functions, which I already tried without success... can anyone tell me why my module cannot be mocked please?
Just for clarification, this mocking is for a response of an external api.
Please let me know if I haven't provided enough info.