Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/artemeff/mox_env
https://github.com/artemeff/mox_env
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/artemeff/mox_env
- Owner: artemeff
- Created: 2019-03-20T07:19:00.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2021-06-10T08:15:03.000Z (over 3 years ago)
- Last Synced: 2024-09-22T10:34:42.936Z (3 months ago)
- Language: Elixir
- Size: 12.7 KB
- Stars: 7
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# MoxEnv [![Hex.pm](https://img.shields.io/hexpm/v/mox_env.svg)](https://hex.pm/packages/mox_env)
---
It's your application config but simply mocked with Mox.
---
## Usage
```elixir
# 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)
enddef 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:
```elixir
iex> MyApp.test_key
:test_valueiex> MyApp.ConfigMock.put_env(:test_key, :new_value)
:new_value
```And import some handy helpers into your test cases:
```elixir
defmodule MyApp.ConnCase do
use ExUnit.CaseTemplate# ...
using do
import Mox
import MyApp.ConfigMock, only: [put_env: 2, put_env: 3, allow_env: 1, allow_env: 2]setup [:set_mox_from_context, :verify_on_exit!]
end# ...
end
```---
### 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