Testing Environment Variable Auto-Restoration in dotenv
This test suite validates the environment variable auto-restoration functionality in the dotenv gem. It ensures that environment variables are properly reset between test runs to maintain test isolation and prevent state leakage.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
bkeepers/dotenv
test/autorestore_test.rb
require "active_support" # Rails 6.1 fails if this is not loaded
require "active_support/test_case"
require "minitest/autorun"
require "dotenv"
require "dotenv/autorestore"
class AutorestoreTest < ActiveSupport::TestCase
test "restores ENV between tests, part 1" do
assert_nil ENV["DOTENV"], "ENV was not restored between tests"
ENV["DOTENV"] = "1"
end
test "restores ENV between tests, part 2" do
assert_nil ENV["DOTENV"], "ENV was not restored between tests"
ENV["DOTENV"] = "2"
end
end