softodrom

softodrom

Change config compile env variables during ExUnit test

Hi,

I have some compile env and I want to change their values in some specific test cases and then change them back.
Is there any way of doing that? recompile/1 is not working as this function simply recompiles Elixir modules, without reloading configuration, recompiling dependencies, or restarting applications.
I think that I need to reload the configuration too.

Best regards.

Most Liked

LostKobrakai

LostKobrakai

For libraries you should avoid compile time config and even using the app env:
https://hexdocs.pm/elixir/library-guidelines.html#avoid-application-configuration

KristerV

KristerV

one option is to have separate config files, but then you would have to run with MIX_ENV=test_this mix test. does this solve it?

but what are you testing exactly? why are compile time variables changing?

i’m pretty sure you don’t need to test if compile time variables work, that’s elixir. you can trust elixir. you probably want to test what happens in your code with different values for that variable. in that case just hardcode the variable into the test. meaning ignore the env var and create a new one, then pass it into the function/process you’re testing.

if it turns out that your code uses the env var in the function you’re testing, well then make the value an argument in the function so the test can pass it in (which is usually a good idea in terms of good code anyway).

Hermanverschooten

Hermanverschooten

Why not create a validation function for the config, and test that?
Then maybe compilation could fail when something invalid is given.

Where Next?

Popular in Questions Top

srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
hpopp
To simplify some tasks at work, I wrote and published this package yesterday. It’s a simple macro that enables Access behaviour on struct...
New
Mooodi
Given a string, how can I get access to its character by index? Enum.at("my_string", 2) doesn't work. Or rather, not char, but a substr...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

Other popular topics Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
273 38985 115
New

We're in Beta

About us Mission Statement