Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a shared vcr spec helper for access to secrets #23292

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions spec/shared/cassette_secrets_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module Spec
module Shared
module CassetteSecretsHelper
def default_vcr_secrets_path
Pathname.new(Dir.pwd).join("config/secrets.defaults.yml").tap do |path|
raise "Default vcr cassette secrets not found: #{path}! Create this file with placeholder secrets to be used in cassettes to avoid leaking actual secrets." unless path.exist?
end
end

def vcr_secrets_path
Pathname.new(Dir.pwd).join("config/secrets.yml")
end

def load_vcr_secrets(pathname)
if pathname.exist?
YAML.load_file(pathname)
else
{}
end
end

def default_vcr_secrets
@@default_vcr_secrets ||= load_vcr_secrets(default_vcr_secrets_path)
end

def vcr_secrets
@@vcr_secrets ||= load_vcr_secrets(vcr_secrets_path)
end

def default_vcr_secret_by_key_path(*args)
default_vcr_secrets.dig(*args)
end

def vcr_secret_by_key_path(*args)
vcr_secrets.dig(*args) || default_vcr_secret_by_key_path(*args)
end
end
end
end
Loading