Skip to content

Instantly share code, notes, and snippets.

@marshall-lee
Created November 16, 2017 12:43
Show Gist options
  • Save marshall-lee/96e5beaf0748f3cfef1818719be9c3f8 to your computer and use it in GitHub Desktop.
Save marshall-lee/96e5beaf0748f3cfef1818719be9c3f8 to your computer and use it in GitHub Desktop.
# decompress gzip-ed VCR fixtures
require 'zlib'
require 'psych'
Dir.glob('spec/fixtures/vcr_cassettes/**/*.yml').each do |filename|
data = Psych.load_file(filename)
changed = false
data['http_interactions'].each do |interaction|
response = interaction['response']
headers = response['headers']
next unless headers['Content-Encoding'] == ['gzip']
body = response['body']
gz = Zlib::GzipReader.new(StringIO.new(body['string']))
string = gz.read
gz.close
body['encoding'] = 'UTF-8'
body['string'] = string
headers.delete 'Content-Encoding'
changed = true
end
if changed
puts "writing #{filename}."
File.write(filename, Psych.dump(data))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment