Skip to content

Commit

Permalink
環境変数をモックする処理をstubを使って書き換える
Browse files Browse the repository at this point in the history
  • Loading branch information
ogawa-tomo committed Nov 7, 2023
1 parent 5ba8640 commit f546eb4
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions test/supports/mock_env_helper.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
# frozen_string_literal: true

module MockEnvHelper
def mock_env(partial_env_hash)
old = ENV.to_hash
ENV.update partial_env_hash
begin
yield
ensure
ENV.replace old
end
def mock_env(hash_for_mock, &block)
env_hash = ENV.to_hash.merge(hash_for_mock)
ENV.stub(:[], ->(key) { env_hash[key] }, &block)
end
end

0 comments on commit f546eb4

Please sign in to comment.