Open
Description
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:
- I have a gem which is only loaded in the development environment
- I have an environment variable in
.env.development
which is only set in the development environment - I have a Rails initializer which references that development-only gem only when that environment variable is set
- 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
- make that gem available in the test environment too
- always export
RAILS_ENV=test
before runningbin/rails parallel:create
- change the conditional to check something like
if defined?(JWT)
instead ofif 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
Labels
No labels