.env not being loaded in test environment in Rails with rspec

If you have test specific environemnt config, You can use Dotenv.overload to overwrite other env config. Just add the following to your spec_helper.rb or rails_helper.rb.

require "dotenv"
Dotenv.overload ".env.test" 
Dotenv.overload ".env.test.local"

This is a late answer, but for anyone who may find it helpful, add this to spec_helper.rb

require 'dotenv'
Dotenv.load('.env')

Also, Dotenv.load can accept a list, for example:

Dotenv.load(
  '.env.local',
  '.env.test',
  '.env'
)