mockery v1.4.0 Mockery.Heritage
This module contains macros useful for mocking given function with same value in multiple tests.
Usage
Create helper module.
defmodule FakeService do
use Mockery.Heritage,
module: MyApp.Service
end
This module can be passed to Mockery.of/2
:by option.
By default it creates proxy to original module.
Let’s add global mock.
defmodule FakeService do
use Mockery.Heritage,
module MyApp.Service
mock [fun: 2], do: "mocked value"
end
Now you don’t have to call Mockery.mock/3
in multiple tests.
For more information about global mock macro see mock/2
Link to this section Summary
Functions
Macro used to create global mocks inside Heritage helper
Link to this section Functions
Macro used to create global mocks inside Heritage helper.
Mocks can be created with value:
mock [fun: 2], do: "mocked_value"
or function:
mock [fun: 2] do
fn(_, arg2) -> arg2 end
end
Keep in mind that function inside mock must have same arity as original one.
This:
mock [fun: 2] do
&to_string/1
end
will raise an error.