Improve stub_env handling of unset keys raise error on fetch
What does this MR do and why?
In real usage if you call ENV.fetch('NON_EXISTENT_KEY')
it will raise
a KeyError
. But our previously implementation of of stub_env
with
nil
is causing it to return nil
rather than raising an error. This
can cause us to write tests that don't match the actual production
behaviour. We might forget to rescue the exception in a certain place or
we also may not be able to write a test case for the expected behaviour.
irb(main):001> ENV.fetch('NON_EXISTENT_KEY')
(irb):1:in `fetch': key not found: "NON_EXISTENT_KEY" (KeyError)
irb(main):002> ENV['NON_EXISTENT_KEY'] = nil
=> nil
irb(main):003> ENV.fetch('NON_EXISTENT_KEY')
(irb):3:in `fetch': key not found: "NON_EXISTENT_KEY" (KeyError)
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Screenshots or screen recordings
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
Before | After |
---|---|
How to set up and validate locally
Numbered steps to set up and validate the change are strongly suggested.