1

我正在使用带有黄瓜的录像机。我想要求 VCR 忽略对“api.stripe.com”的所有请求,不要处理它们。让请求通过真正的 Stripe API 服务器。但只有那些。我希望其余的请求由 VCR 处理。所以,我有以下 VCR 设置:

require 'vcr'

VCR.configure do |c|
  c.cassette_library_dir = 'vcr_cassettes'
  c.hook_into :webmock
  c.ignore_localhost = true
  c.default_cassette_options = { :record => :new_episodes }
  c.configure_rspec_metadata!
  c.ignore_hosts 'api.stripe.com'
end

当我运行我的测试时,所有访问其他外部服务的测试都失败了。例如:

#<VCR::Errors::UnhandledHTTPRequestError: 

================================================================================
An HTTP request has been made that VCR does not know how to handle:
POST https://www.googleapis.com/urlshortener/v1/url?key=<my_key>

There is currently no cassette in use. There are a few ways
you can configure VCR to handle this request:

  * If you're surprised VCR is raising this error
    and want insight about how VCR attempted to handle the request,
    you can use the debug_logger configuration option to log more         
    details [1].
  * If you want VCR to record this request and play it back during 
    future test
    runs, you should wrap your test (or this portion of your test) in   
    a `VCR.use_cassette` block [2].
  * If you only want VCR to handle requests made while a cassette is 
    in use,
    configure `allow_http_connections_when_no_cassette = true`. VCR 
    will
    ignore this request since it is made when there is no cassette     
    [3].
   * If you want VCR to ignore this request (and others like it), you  
     can
     set an `ignore_request` callback [4].

所以,真的,我不知道这里发生了什么。有什么帮助吗?

4

1 回答 1

0

有点晚了,但也许您没有在VCR.use_cassette块内或没有vcr元数据的情况下发出请求。如果这不是解决方案,请分享一个测试示例。

于 2021-10-17T19:51:57.577 回答