Last active
July 26, 2023 14:48
-
-
Save henrik/8f4a9fc07e42a3a410a1049af2631bd9 to your computer and use it in GitHub Desktop.
Stub ENVs in RSpec.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def stub_env(key, value) | |
is_set_up_flag = "__stub_env_is_set_up" | |
unless ENV[is_set_up_flag] | |
allow(ENV).to receive(:[]).and_call_original | |
allow(ENV).to receive(:fetch).and_call_original | |
allow(ENV).to receive(:[]).with(is_set_up_flag).and_return(true) | |
end | |
allow(ENV).to receive(:fetch).with(key).and_return(value) | |
allow(ENV).to receive(:[]).with(key).and_return(value) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment