How to change the environment variable of rails in testing
As a simpler variation on several answers above, this is working for me:
allow(Rails).to receive(:env).and_return('production')
Or, for as I'm doing in shared_examples, pass that in a variable:
allow(Rails).to receive(:env).and_return(target_env)
I suspect this falls short of the ...StringInquirer...
solution as your app uses additional methods to inspect the environment (e.g. env.production?
, but if you code just asks for Rails.env
, this is a lot more readable. YMMV.