O-o
O-o

Reputation: 130

Is there a way to call a module via its path or something?

I have a mock module where I'd like to pass through certain function calls to the original, but the mock module hides the original. Can I call the original by path somehow, or is there a way around this?

Upvotes: 2

Views: 175

Answers (1)

Roberto Aloi
Roberto Aloi

Reputation: 30985

You can use Meck, a mocking library for Erlang, to achieve this:

With meck you can easily mock modules in Erlang. Since meck is intended to be used in testing, you can also perform some basic validations on the mocked modules, such as making sure no function is called in a way it should not.

meck automatically renames existing modules in case they are loaded when you want to mock them, and restores them upon unloading of the mocked module. It is also possible to call the original functions from a mocked module using meck:passthrough/1 from inside an expectation.

Upvotes: 5

Related Questions