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

Feature request: support for on_exit style teardown with setup_with_mocks #131

Open
Bastes opened this issue Aug 10, 2021 · 0 comments
Open

Comments

@Bastes
Copy link

Bastes commented Aug 10, 2021

Hi :) awesome lib you've got there...

...but there's something that could make it awesome-er!

See, the setup_with_mocks macro is great, but it does not let us execute an on_exit instruction during the mocking, but after it, which in turn makes it awkward to do something like that:

setup_with_mocks([
  {MyModule, [:passthrough], [:index, fn -> "fake_index" end]}
]) do
  on_exit(fn -> IO.inspect(MyModule.index(), label: "expects fake_index")
end

The use case I've come across is my app works with Elasticsearch, and we've dockerized an ES instance that's shared by both the dev and test instances. In order to not destroy the dev index(es) every time the tests run, yet really test real requests, we want to insert data before each test, mocking the index name so we don't use the same as the dev, then destroy the index aterwards.

So, we're just going to destroy the index before the tests run for now (plus it allows us to insure our instance is clean before each tests) but maybe we're not the only ones that need to tear down stuff from time to time, so here's that ;)

If I find how to do it, I'll be sure to post a PR.

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

1 participant