Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do load .env.local in Rails' test environment #417

Closed
wants to merge 4 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Oct 26, 2020

This basically reverts #280.

The above-mentioned PR says:

When using .env.local for tests, the tests are not transparent and can't be executed for example on a CI server. As the documentation says, the .env.local is here for local overwrites. They should not overwrite a test specific variable. Tests should be run on every machine in every environment and shouldn't require any specification of environment variables.

While that description matches the expected behavior of Dotenv, the implementation goes too far (1) and even contradicts other bits of Dotenv's current behavior (2).

About (1), a quote from the Github user named jakedouglas:

Tests should be run on every machine in every environment and shouldn't require any specification of environment variables.

At least one very common example of this idea not holding water is that most Rails applications require a database, and the URL of that database may vary between different developer machines, and between developer machines and a CI service. Given this PR, if a developer happens to have a database setup that doesn't match the application's defaults (common), they need to specify the database URL in both .env.local and .env.test.local in order to do local development comprehensively.

About (2), anything that .env.local could do to the test environment variables before it became ignored for that environment can now be done with .env.test.local, often at the cost of tediously duplicating variables from the currently-ignored .env.local. This contradicts the behavior intended by PR #280 and consistency would dictate that .env.test.local be removed altogether. Only then the test variables would truly be guaranteed to always stay the same as far as Dotenv is concerned.

Since (1) shows that local development might require local test variables for legitimate reasons, removing .env.test.local is not a valid option and it would make sense to instead restore loading .env.local for the test environment.

Erwan Thomas added 2 commits October 26, 2020 14:08
This basically reverts bkeepers#280.

The above-mentioned PR says:

> When using .env.local for tests, the tests are not transparent and
> can't be executed for example on a CI server.
> As the documentation says, the .env.local is here for local
> overwrites. They should not overwrite a test specific variable. Tests
> should be run on every machine in every environment and shouldn't
> require any specification of environment variables.

While that description matches the expected behavior of Dotenv, the
implementation goes too far (1) and even contradicts other bits of Dotenv's
current behavior (2).

About (1), a [quote][jakedouglas-comment] from the Github user named jakedouglas:

>> Tests should be run on every machine in every environment and
>> shouldn't require any specification of environment variables.
>
> At least one very common example of this idea not holding water is
> that most Rails applications require a database, and the URL of that
> database may vary between different developer machines, and between
> developer machines and a CI service. Given this PR, if a developer
> happens to have a database setup that doesn't match the
> application's defaults (common), they need to specify the database
> URL in both .env.local and .env.test.local in order to do local
> development comprehensively.

About (2), anything that .env.local could do to the test environment
variables before it became ignored for that environment can now be done
with .env.test.local, often at the cost of tediously duplicating
variables from the currently-ignored .env.local. This contradicts the
behavior intended by PR bkeepers#280 and consistency would dictate that
.env.test.local be removed altogether. Only then the test variables
would truly be guaranteed to always stay the same as far as Dotenv is
concerned.

Since (1) shows that local development might require local test
variables for legitimate reasons, removing .env.test.local is not a
valid option and it would make sense to instead restore loading
.env.local for the test environment.

[jakedouglas-comment]: bkeepers#280 (comment)
@stale
Copy link

stale bot commented Dec 25, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Dec 25, 2020
@stale stale bot removed the wontfix label Jun 18, 2021
@dembskoi
Copy link

Hey @bkeepers, could you please take a look at this request?
It looks very relevant.
Thank you

@douglaspetrin
Copy link

douglaspetrin commented Oct 27, 2023

Yeah, a little annoying it. Just found it and created another "workaround" file .env.test.local which now is working. dotenv (2.7.6)

@bkeepers
Copy link
Owner

In Dotenv 3.0, it will be easy for people to customize the files they want loaded. See Customizing Rails.

@bkeepers bkeepers closed this Jan 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants