Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Continuous third party APIs monitoring & testing on Rails

We would like to setup automated jobs (via Jenkins) to alert if the third party API is down or they deployed an incompatible APIs.

I am talking about to test against the real HTTP APIs and not a mock, but as we already have mock written using rspec, I am not sure if we should duplicate the effort by writing two independent testes.

Anyone have this experience in this before? (I am not limited to Ruby/Rspec if other tools can help)

like image 677
Howard Avatar asked Jan 12 '13 10:01

Howard


2 Answers

Have you had a look at VCR? Using it, you can "record your test suite's HTTP interactions and replay them during future test runs for fast, deterministic, accurate tests". I've used it with RSpec when testing expected responses from external APIs, and think it's great. I'd encourage you to check out the StackOverflow questions tagged with vcr if it's something you think may work for you.

Not sure of its Jenkins integration, but when I was using VCR, I automated some regular tasks where I needed to hit the APIs with Whenever ("Cron jobs in Ruby"). Not really continuous, but somewhat automated.

like image 195
Paul Fioravanti Avatar answered Oct 17 '22 19:10

Paul Fioravanti


When I was in this situation a few months ago I did the following:

  1. Mock the API and write tests against the mocked data (you already have that)
  2. Write one more test that gets data from the real API and asserts that it is (still) in the same form and contains the same kind of data that we expect

I did it like this since it was impossible for me to guess/know what content will be provided by the live API.

like image 38
severin Avatar answered Oct 17 '22 19:10

severin