我需要 VCR 跳过 https://api.github.com/users/lapaty/starred调用真正的外部 API,同时继续模拟类似于 https://api.github.com/repos/lgs/elasticrepo 的类似路径
到目前为止,我尝试了以下方法,但没有成功:
VCR.configure do |c|
...
c.ignore_hosts 'api.github.com/users/lapaty/starred'
end
和
VCR.configure do |c|
...
c.ignore_request do |request|
URI(request.uri).uri == 'https://api.github.com/users/lapaty/starred'
end
end
最佳答案
c.ignore_hosts 'api.github.com/users/lapaty/starred'
永远不会工作,因为 api.github.com/users/lapaty/starred
是不是主机。
对于您尝试的第二件事,URI(request.uri).uri
部分是不必要的——您将字符串解析为 uri,然后从中获取字符串表示形式(它应该只给你 request.uri
)。我认为这应该有效:
VCR.configure do |c|
c.ignore_request do |request|
request.uri == 'https://api.github.com/users/lapaty/starred'
end
end
如果它不起作用,那么它表明 URI 字符串并不完全像您认为的那样 "https://api.github.com/users/lapaty/starred"
。您可以在 ignore_request
block 中添加一些 puts
日志记录以查看正在发出的请求,或者您可以使用 debug_logger选项以详细了解 VCR 正在做什么以及为什么这样做。
关于ruby - 让 VCR 跳过 URI :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16901323/