Rails: How to stub the env in Rails 7+

Posted . Visible to the public.

Rails 7.1 added Show archive.org snapshot a new method Rails.env.local?. If you want to stub the Rails env correctly, use ActiveSupport::EnvironmentInquirer like this:

# check if the value of stubbed_env is valid
allow(Rails).to receive(:env).and_return(ActiveSupport::EnvironmentInquirer.new(stubbed_env.to_s))
Julian
License
Source code in this card is licensed under the MIT License.
Posted by Julian to makandra dev (2024-10-08 11:48)