Created
August 2, 2019 16:39
-
-
Save brentd/6bdb940f8b16b761aae868ce8d9dc060 to your computer and use it in GitHub Desktop.
Webmock stubbing helper
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
# Quick way to log both stubbing instructions and the response of a real request. | |
# Useful for stubbing real requests without having to resort to VCR. | |
WebMock.allow_net_connect! | |
WebMock.after_request do |request_signature, response| | |
puts "\nA real HTTP request was made." | |
puts WebMock::RequestSignatureSnippet.new(request_signature).stubbing_instructions | |
puts "----- RESPONSE HEADERS -----" | |
pp response.headers | |
puts "----- RESPONSE BODY -----" | |
if response.headers["Content-Type"] =~ /json/ | |
puts JSON.pretty_generate(JSON.parse(response.body)) | |
else | |
puts response.body | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment