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 calling Mimic.allow before expectations have been defined #84

Open
michaelst opened this issue Oct 2, 2024 · 0 comments
Open

Comments

@michaelst
Copy link
Contributor

Similar to Hammox it would be nice to allow processes to use a mock before expectations have been defined.

In this case I have a genserver that takes a opt for allow_fun which will run a provided function in the genserver process on init

def init(opts) do
  if fun = opts[:allow_fun], do: fun.(self())

  {:ok, []}
end

In the test I then pass the allow_fun

allow_fun = fn pid ->
  Ecto.Adapters.SQL.Sandbox.allow(Auth.Repo, self, pid)
  Mimic.allow(Repo, self, pid)
end

key_server = start_supervised!({Auth.Signing.Guardian.KeyServer, allow_fun: allow_fun})

However, with this setup I have to put the expects before starting the genserver, which prevents me from locating them next to the code that will trigger the expects.

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