Search code examples
ruby-on-railsrubyrspecvcr

Can I log the unhandled VCR request body?


I'm using the VCR gem to mock HTTP queries. I've recorded cassettes, but then I had to change some stuff around, and now I'm getting an error:

An HTTP request has been made that VCR does not know how to handle:
  POST http://api.endpoint.here/path.json

Now, because it's a POST request, the VCR is configured to match those on body as well as path. Can I log or dump the body of the unhandled request so I can tweak the cassettes accordingly? Thank you.


Solution

  • Won't callback achieve what you need?

    VCR.configure do |c|
      c.after_http_request do |request, response|
        if request.method == :post
          puts "POST Request:#{request.uri}"
          puts "#{request.to_hash}" # or request.body
        end
      end
      c.allow_http_connections_when_no_cassette = true
    end