Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable passing the caller module attributes to with_mocks macro #117

Open
bmarkons opened this issue Apr 9, 2020 · 1 comment
Open

Enable passing the caller module attributes to with_mocks macro #117

bmarkons opened this issue Apr 9, 2020 · 1 comment

Comments

@bmarkons
Copy link

bmarkons commented Apr 9, 2020

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

@Olshansk
Copy link
Collaborator

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants