Rspect API test

8 views
Skip to first unread message

Daynthan Kabilan

unread,
Sep 21, 2018, 8:03:42 AM9/21/18
to rubyonra...@googlegroups.com
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


Walter Lee Davis

unread,
Sep 21, 2018, 8:32:51 AM9/21/18
to rubyonra...@googlegroups.com
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

>
>
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CADKeJyQfjN6WoE1GeBdVR%3DTqTGMS5uOxRYzKRF35eTzUAwdQfQ%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

Daynthan Kabilan

unread,
Sep 23, 2018, 2:37:19 AM9/23/18
to rubyonra...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages