简体   繁体   English

如何在rspec中测试此第三方API集成?

[英]How do I test this third party API integration in rspec?

My project is a rails app that extends some third party API. 我的项目是一个Rails应用程序,它扩展了一些第三方API。 A lot of the requests rely on third party API calls. 许多请求都依赖于第三方API调用。 How should I test these cases in rspec? 我应该如何在rspec中测试这些情况? Should I use VCR and actually just hit the third party (then mock future requests)? 我应该使用VCR并实际上只是打了第三方(然后嘲笑将来的请求)吗? Or should I just download the payload into a fixture manually and stub requests with webmock and find a way to bypass the oauth process? 还是应该手动将有效负载下载到固定装置中,并使用webmock存根请求并找到一种绕过oauth流程的方法? Are the better solutions? 有更好的解决方案吗?

Note that it uses OAuth, but I don't use omniauth. 请注意,它使用OAuth,但我不使用omniauth。

Sometimes the API limits me to fetching N records at a time, so I have to paginate them. 有时,API限制我一次只能获取N条记录,因此我必须对它们进行分页。 There could be instances where I'm making 25 requests just to get the data I need, but this is mostly for the sync rake tasks. 在某些情况下,我仅要获取所需数据就发出25个请求,但这主要用于同步rake任务。

There is no need to download a payload manually, as this is exactly what VCR does for you. 无需手动下载有效负载,因为这正是VCR为您所做的。 VCR creates a yaml fixture, that it uses for all future requests. VCR创建一个Yaml固定装置,用于将来的所有请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM