Skip to content

Instantly share code, notes, and snippets.

@jtrim
Created August 28, 2015 21:22
Show Gist options
  • Select an option

  • Save jtrim/2501f587537d37eede26 to your computer and use it in GitHub Desktop.

Select an option

Save jtrim/2501f587537d37eede26 to your computer and use it in GitHub Desktop.
VCR.configure do |config|
config.cassette_library_dir = "test/fixtures/cassettes"
config.hook_into :webmock
config.default_cassette_options = {
record: :once
}
config.before_record do |i|
if i.response.headers["Content-Type"].any? { |h| h =~ /json/ }
# Try to pretty format json body, rescue and proceed if it's not possible
i.response.body.replace JSON.pretty_generate(JSON.parse(i.response.body)) rescue nil
end
i.response.body.force_encoding('UTF-8') # prevent recording as binary for readability
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment