You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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?
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:
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
The text was updated successfully, but these errors were encountered: