jjh42 / mock

Mocking library for Elixir language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Enable passing the caller module attributes to with_mocks macro

bmarkons opened this issue · comments

Hi :)

We have been using mock library in all of our elixir tests and it's been great. However we wanted to make our tests more elegant and readable by extracting all of our mocks to the module attributes and passing them as such the following way:

@file_exists_mock {File, [:passthrough], [exists?: fn _, _ -> true end]}

test "..." do
  with_mock(@file_exists_mock) do
    ...
  end
end

The code above throws compilation error. This stackoverflow post seems to answer the reason why it fails. It seems that module attributes needs to be expanded:

https://stackoverflow.com/questions/54000082/pass-module-attribute-as-an-argument-to-macros

We hope to overcome this with putting the mocks in the private functions but making with_mocks accept module attributes would be cool.

Thanks for making this library.

Cheers

I'm not sure if this would work, but what if we add an option called expand_input, and you would call Macro.expand inside with_mock if it's set to true?