Rspect API test

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Rspect API test

daynthan kabilan
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


--
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 [hidden email].
To post to this group, send email to [hidden email].
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.
Reply | Threaded
Open this post in threaded view
|

Re: Rspect API test

Walter Lee Davis

> On Sep 21, 2018, at 8:03 AM, Daynthan Kabilan <[hidden email]> wrote:
>
> 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

>
>
>
> --
> 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 [hidden email].
> To post to this group, send email to [hidden email].
> 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.

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/10175416-F15A-4AFC-82E2-0E4E85A7605C%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Rspect API test

daynthan kabilan
Thankyou 

On Fri, Sep 21, 2018 at 6:02 PM Walter Lee Davis <[hidden email]> wrote:

> On Sep 21, 2018, at 8:03 AM, Daynthan Kabilan <[hidden email]> wrote:
>
> 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

>
>
>
> --
> 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 [hidden email].
> To post to this group, send email to [hidden email].
> 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.

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/10175416-F15A-4AFC-82E2-0E4E85A7605C%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CADKeJyQ%2BV7%2B0T%2BDAbveBj_tf2giTb7ueesyas_Ry5MHeUk8K5A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.