Skip to content

devality/mox_env

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MoxEnv Hex.pm


It's your application config but simply mocked with Mox.


Usage

# myapp/lib/myapp/config.ex
defmodule MyApp.Config do
  def get(key, default \\ nil) do
    Application.get_env(:my_app, key, default)
  end
end

# myapp/test/support/config_mock.ex
defmodule MyApp.ConfigMock do
  use MoxEnv, config: MyApp.Config
end

# myapp/lib/myapp.ex
defmodule MyApp do
  @config Application.get_env(:my_app, :config_module, MyApp.Config)

  def test_key do
    @config.get(:test_key)
  end

  def test_key_default do
    @config.get(:test_key_default, :default_value)
  end
end

# config/test.exs
config :my_app, config_module: MyApp.ConfigMock

With that configuration you can simply mock your config in tests, like Mox:

iex> MyApp.test_key
:test_value

iex> MyApp.ConfigMock.put_env(:test_key, :new_value)
:new_value

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Elixir 100.0%