These are chat archives for bkeepers/dotenv

22nd
Apr 2016
Diego Algorta
@oboxodo
Apr 22 2016 15:32
Hi there. We have a rails 4.2.6 app and we're using dotenv-rails with no problem. Now we're starting to split some code into gems/engines as components as suggested by the cbra.info approach. We now have an engine which depends on some ENV variables to be loaded in order to properly run the tests. Where would be the best place to require/load dotenv from the engine?
Brandon Keepers
@bkeepers
Apr 22 2016 15:36
Hey @oboxodo. As long as dotenv-rails is loaded first in your Gemfile, it should initialize the environment before the other components
I think Rails loads extensions in the order they are defined.
Diego Algorta
@oboxodo
Apr 22 2016 15:37
you mean in the engine's Gemfile? (as opposed to the main app which depends on the engine)
Brandon Keepers
@bkeepers
Apr 22 2016 15:37
I mean in the main app
if dotenv-rails is declared before the engine, you should be golden
Diego Algorta
@oboxodo
Apr 22 2016 15:38
the engine's Gemfile just loads the engine's gemspec, and we have dotenv-rails added there as a development dependency
yeah yeah. That is working
Brandon Keepers
@bkeepers
Apr 22 2016 15:38
ok, maybe I’m not understanding something. Are you runnig into a problem?
Diego Algorta
@oboxodo
Apr 22 2016 15:38
the engine has access to the loaded env files when being used from the main app
but..
my problem is to run the isolated engine's tests
independent from the main app.
I need the engine to load it's own, smaller and engine specific, .env (or .env.test) file
Brandon Keepers
@bkeepers
Apr 22 2016 15:39
Ah, then you can just call Dotenv.load(“path/to/env”) in your test bootstrap code
Diego Algorta
@oboxodo
Apr 22 2016 15:39
so when I run the engine (not the main app) tests/specs, the env vars get loaded.
ok. that's what I wanted to know.
because I was thinking about adding the load call into the engine's main lib file... but that would get triggered independently of the environment, and I hate adding if Rails.env.test? and that kind of stuff.
will try that approach.
thanks!
Brandon Keepers
@bkeepers
Apr 22 2016 16:02
you can also call Dotenv.overload(“file”) in tests to overwrite whatever the previous value was