title: How to load environment variables to ruby app spec using Rspec and .env
body: <p>I'm currently working on writing tests for a Ruby class. The class makes use of environment variables.</p>
  
  <p>When I run the <code>spec</code> with <code>rspec spec/box_api.rb</code> I get the following error:</p>
  
  <pre><code>Failures:
  
    1) BoxApi#client success Create Boxr::Client object
       Failure/Error: subject { BoxApi.new }
  
       KeyError:
         key not found: "BOX_USER_ID"
       # ./src/clients/box_api.rb:8:in `fetch'
       # ./src/clients/box_api.rb:8:in `initialize'
       # ./spec/box_api.rb:14:in `block (4 levels) in &lt;top (required)&gt;'
  </code></pre>
  
  <p>It's not reading the environment variable.</p>
  
  <p>I tried creating the <code>.env.test.local</code> file within spec folder without success. I'm using <code>dotenv</code> gem:</p>
  
  <pre><code># Manage environment with .env file
  gem 'dotenv', '~&gt; 2.1.1'
  </code></pre>
  
  <p>How can I go about using the environment variables in test?</p>