Skip to content

Test issue: application environment not reseted between scenarios

In environment.feature, I added a new scenario:

  Scenario: No environment prefix configured but a variables filter list is provided
    Given I have created my own Weave module
    And I have not configured the environment prefix
    And I have configured the following variables in variables filter
    | key |
    | drug |
    | rock_n_roll |
    And the following environment variables exist
    | key               | value               |
    | drug              | coffee              |
    | rock_n_roll       | yes                 |
    | full_universe     | 42                  |
    When I run Weave's Environment loader
    Then my application should be configured

In environment.ex load_configuration/1 :

    IO.inspect(env_prefix)
    IO.inspect(variables_filter)
    IO.inspect "-------"

Which gives me, when running tests:

"WEAVE_"
nil
"-------"
.."WEAVE_"
nil
"-------"
."WEAVE_"
["drug", "rock_n_roll"]
"-------"
"WEAVE_"
["drug", "rock_n_roll"]
"-------"
"WEAVE_"
["drug", "rock_n_roll"]
"-------"

But nowhere do I set the env prefix at the same time as only. Problem was configuration wasn't reset between scenarios and adding this to the shared_steps.ex fix the problem:

defgiven ~r/^I have created my own Weave module$/, _vars, state do
    # Reset weave configuration
    for {key, _} <-  Application.get_all_env(:weave), do: Application.delete_env(:weave, key)
    # Reset example app configuration
    for {key, _} <-  Application.get_all_env(:example_app), do: Application.delete_env(:example_app, key)
    {:ok, state}
end
"WEAVE_"
nil
"-------"
..nil
nil
"-------"
.nil
["drug", "rock_n_roll"]
"-------"
"WEAVE_"
nil
"-------"
"WEAVE_"
nil
"-------"

I also reset the example app env, it could lead to false positive / negative

Edited by Benjamin Piouffle