Before HTTP Request Hook
log all requests using a before_http_request hook
include_http_adapter_for("<http_lib>")
if ARGV.include?('--with-server')
$server = start_sinatra_app do
get('/') { "Hello World" }
end
end
require 'vcr'
VCR.configure do |c|
<configuration>
c.cassette_library_dir = 'cassettes'
c.before_http_request(:real?) do |request|
File.open(ARGV.first, 'w') do |f|
f.write("before real request: #{request.method} #{request.uri}")
end
end
end
VCR.use_cassette('hook_example') do
port = $server ? $server.port : 0
make_http_request(:get, "http://localhost:#{port}/")
endExamples
Last updated