allow(Rails.application.config).to receive(:config_name).and_return('myvalue')
TODO: doesn't work in a certain situation:
For testing code that depends on environment variables
describe 'wrapping the environment' do
it 'stubs the environment in the block' do
actual_env = nil
wrap_env('TEST_VAR' => 'changed') do
actual_env = ENV['TEST_VAR']
end
expect(ENV['TEST_VAR']).to eq 'original'
expect(actual_env).to eq 'changed'
end
end
references:
Option 2
before :each do
allow(ENV).to receive(:[]).with('myvariable').and_return('some_value')
allow(ENV).to receive(:[]).and_call_original
end