I'm using Ecto.UUID.generate
to create a random token on a user model.
In my ExUnit test, I want to test the controller that calls the creation route, however because the token is always random, I can't deterministically test the result.
Ideally, I want to be able to stub the Ecto.UUID.generate
in my test so it always creates the same UUID so I can test the response correctly.
Thanks :)
There are mocking solutions in Elixir and Erlang but they are not used a lot. If you are further interested, here is an article: http://blog.29steps.co.uk/post/105715556278/testing-api-web-calls-in-elixir-using-meck
Honestly, I would just avoid the mock. If you have an API, test the returned ID is an UUID (you can see if Ecto.UUID.dump(uuid)
returns {:ok, something}
). If it is a browser/html app, it is likely you care about the UUID even less.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With