Search code examples
rubyvcr

Show ruby VCR stats after running tests?


Is there a way of knowing how many requests are happening when you run your tests and could be cached by VCR.

Is there a way of knowing how many of those are getting read from the VCR cache?

Thanks


Solution

  • Take a look at After Http Request Hook:

    VCR.configure do |c|
      c.cassette_library_dir = 'cassettes'
      c.ignore_localhost = true
      c.after_http_request(:ignored?, lambda { |req| req.uri =~ /foo/ }) do |request, response|
        puts "Response for #{request.method} #{request.uri}: #{response.body}"
      end
    end
    

    Or you can enable debug logging:

    VCR.configure do |c|
      c.hook_into :webmock
      c.cassette_library_dir = 'cassettes'
      c.debug_logger = File.open(ARGV.first, 'w')
    end