Search code examples
ruby-on-railstestingrspecenvironment-variablesrspec-rails

How do I get an ENV variable set for rspec?


I'm using foreman to start up my rails development server. It's nice that I can put all of my environment variables in the .env file. Is there a way to do something similar for my test environment?

I want to set an API key that I will use with the vcr gem, but I don't want to add the API to version control. Any suggestions besides setting the environment variable manually when I start up my tests script?


Solution

  • You can use the dotenv gem --- it'll work the same as foreman and load from a .env file. (and a .env.test file for your test environments)

    https://github.com/bkeepers/dotenv