#543·dotenv

Error in Customizing Rails section of README

Author: jbiglerCreated Mar 13, 2026Updated Mar 13, 2026

The customization suggested to include .env.local in the test environment uses unshift, but this will put env.local at the highest precedence.

ruby
# config/application.rb
Bundler.require(*Rails.groups)

# Load .env.local in test
Dotenv::Rails.files.unshift(".env.local") if ENV["RAILS_ENV"] == "test"

module YourApp
  class Application < Rails::Application
    # ...
  end
end

Instead, it should be inserted between .env.test.local and .env.test

Suggestion:

ruby
# Load .env.local in test
if ENV["RAILS_ENV"] == "test"
  files = Dotenv::Rails.files
  index = files.index(".env.test.local")&.succ || files.index(".env.test") || 0
  files.insert(index, ".env.local")
end