Created
November 24, 2017 18:25
-
-
Save lucasmazza/801e607d42a78253a85bc3e1bb5e5f2d to your computer and use it in GitHub Desktop.
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
# Rewrite VCR Cassettes to move the URL:PASSWORD pair from | |
# the 'uri' to the 'Authorization' header. | |
# This is required when moving from WebMock 1 to 2+. | |
require 'yaml' | |
require 'uri' | |
require 'base64' | |
Dir["spec/fixtures/vcr_cassettes/*.yml"].each do |path| | |
cassette = YAML.load_file(path) | |
cassette['http_interactions'].each do |interaction| | |
request = interaction['request'] | |
uri = URI.parse(request['uri']) | |
next if uri.password.nil? && uri.user.nil? | |
credentials = Base64.encode64("#{uri.user}:#{uri.password}").chomp | |
uri.user = nil | |
uri.password = nil | |
unless request['headers'].key?('Authorization') | |
request['headers'].merge!('Authorization' => ["Basic #{credentials}"]) | |
end | |
request['uri'] = uri.to_s | |
end | |
File.open(path, 'w') { |io| io.write(cassette.to_yaml) } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment