diff --git a/spec/support/helpers/devise_helpers.rb b/spec/support/helpers/devise_helpers.rb
index 66874e10f38951287e0cb81e529b81ef66d615b7..d32bc2424c0427108d3f35934a651792ab037c64 100644
--- a/spec/support/helpers/devise_helpers.rb
+++ b/spec/support/helpers/devise_helpers.rb
@@ -8,8 +8,15 @@ def set_devise_mapping(context:)
   end
 
   def env_from_context(context)
+    # When we modify env_config, that is on the global
+    # Rails.application, and we need to stub it and allow it to be
+    # modified in-place, without polluting later tests.
     if context.respond_to?(:env_config)
-      context.env_config
+      context.env_config.deep_dup.tap do |env|
+        allow(context).to receive(:env_config).and_return(env)
+      end
+    # When we modify env, then the context is a request, or something
+    # else that only lives for a single spec.
     elsif context.respond_to?(:env)
       context.env
     end