Rspect API test

Hi,

Anyone please give me some idea about how to write test case with API endpoints.

I have used multiple API in my application. Currently i need to write the testcase to the API. So needs to be some request test specs (using rspec, preferrably) for all of the major ruby API endpoints.

Thanks for advance

Hi,

Anyone please give me some idea about how to write test case with API endpoints.

I have used multiple API in my application. Currently i need to write the testcase to the API. So needs to be some request test specs (using rspec, preferrably) for all of the major ruby API endpoints.

Thanks for advance

We use VCR to wrap around the API. https://github.com/vcr/vcr It's pretty straightforward. You put a VCR block around the part of your test that requests the external resource, and then you just make a normal request inside your test. The first time it runs, VCR will write out a "cassette" for that request, which is just a serialized version of the HTTP traffic response. The next time it runs, you will hit the cassette, not the network. Saves a bunch of time when you are done fiddling with the API tests and have moved on to other parts of your app. If you ever worry about your tests getting away from reality, you can just delete the cassettes and run the test again to refresh them with a newer version.

Walter

Thankyou