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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -