Skip to content

Interesting interaction with dotenv-rails #1014

Open
@maxjacobson

Description

@maxjacobson

Hello again!

We've recently adopted parallel_tests and we've just hit an interesting interaction between this library and dotenv-rails which I'd like to share.

I made an example repo which demonstrates the behavior: https://github.com/maxjacobson/parallel_tests_example_repo

I'll summarize here:

  1. I have a gem which is only loaded in the development environment
  2. I have an environment variable in .env.development which is only set in the development environment
  3. I have a Rails initializer which references that development-only gem only when that environment variable is set
  4. When I run bin/rails parallel:create, the command fails because the subprocesses are in a strange state: the Rails environment is test (so the gem is not available), but the environment variables from .env.development are loaded (and so we try to reference it anyway)

I think this behavior basically makes sense, given that the subprocess inherits the parent's environment. I can avoid this issue in a few different ways, such as

  1. make that gem available in the test environment too
  2. always export RAILS_ENV=test before running bin/rails parallel:create
  3. change the conditional to check something like if defined?(JWT) instead of if ENV["ENABLE_COOL_FEATURE"] == "true"

It would have been cool if this had "just worked" though. I'm not sure how to ensure that though... I figured I'd file the issue to share and see if you have any thoughts or guidance.

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions