So not so long ago I started learning Elixir (coming from python myself). To ease it up, I started a small project for myself(link). And I am trying to cover the module with tests.
I need an extremely easy thing - mock a function in my module in the tests. So I’ve decided to follow this article
To be more specific:
- I need to mock this function
- This function is used in function
get_config_from_fileand i want to test this function.
- I define a mock of this module with mox: link
- I try to use this mock in a test: link
- But when I try to call a function
get_config_from_filefrom this mock, I get an error:
1) test config from file (Spacebrew.Config.Test) test/configuration_test.exs:8 ** (Mox.UnexpectedCallError) no expectation defined for Spacebrew.ConfigMock.get_config_from_file/1 in process #PID<0.193.0> code: assert Spacebrew.ConfigMock.get_config_from_file( stacktrace: (mox) lib/mox.ex:551: Mox.__dispatch__/4 test/configuration_test.exs:15: (test)
I understand that it says I should write an expect for the function i call. But why? I need it to be an original function from the module and only a
paths function to be mocked.
I understand that I am wrong conceptually, I just don’t understand where and when :
Please help, as I am getting frustrated