testing - Define a constant module in elixir -
i create changeable boundary module. ideally result other module behaviour set @ compile time or in configuration files. think looking define in erlang
say have systemclock module , dummyclock tuple module. ideally clock module 1 or other of 2 modules above chosen in config file.
in config/test.ex
define(clock, {dummyclock, 12345678})
later
clock.now # => 12345678
in config/prod.ex
define(clock, systemclock)
later
clock.now # => 32145687
i think easiest way configs , application.get_env/2
.
in config/test.exs
config :my_application, clock: dummyclock
in config/dev.exs
, config/prod.exs
config :my_application, clock: realclock
in code uses clock
defp clock, do: application.get_env(:my_application, :clock) def my_function(arg1, arg2) = clock.now # ... end
Comments
Post a Comment