After HTTP Request Hook
log all requests and responses using after_http_request hook
include_http_adapter_for("<http_lib>")
$server = start_sinatra_app do
get('/foo') { "Hello World (foo)" }
get('/bar') { "Hello World (bar)" }
end
require 'vcr'
VCR.configure do |c|
<configuration>
c.cassette_library_dir = 'cassettes'
c.ignore_localhost = true
c.after_http_request(:ignored?, lambda { |req| req.uri =~ /foo/ }) do |request, response|
uri = request.uri.sub(/:\d+/, ":7777")
puts "Response for #{request.method} #{uri}: #{response.body}"
end
end
make_http_request(:get, "http://localhost:#{$server.port}/foo")
make_http_request(:get, "http://localhost:#{$server.port}/bar")Examples
Last updated