Repatch - Everything you need for mocking and patching

Thanks for creating Repatch!
I think this is the best of all the mocking libraries with the least restrictions, and it should deserve a lot more recognition from the community.

Patching DateTime module for time travelling in timestamps

Do you have a helper module / small library that you use for this which you can share?
I needed time travel testing in literally every project at some point and I hate to reinvent it every time.

With Repatch I’m currently just doing this, but it’s probably too simple for most situations:

    {:ok, time} = Agent.start_link(fn -> ~N[1990-01-01 00:00:00] end)
    Repatch.patch(NaiveDateTime, :utc_now, fn ->
      Agent.get(time, fn t -> t end)
    end)
    # ...
    Agent.update(time, fn _ -> ~N[2010-01-01 00:00:00] end)
3 Likes