Posted over 3 years ago. Visible to the public.

Consuming external APIs from Ruby [1d]

Exercise 1: XML

On the Movie DB index, show a random actor who was born today:

Exercise 2: JSON

Automatically retrieve the year of a movie for any new movie entered into MovieDB, using the API. For the UI this means that there is no longer a "Year" field when creating a movie. It is automatically fetched and stored before the movie is created. When editing a movie there is a "Year" field that can be changed.


Write an RSpec test for the JSON-Exercise. Write multiple variants of this test, each using a different approach:

  1. Just call the real API from the example
  2. Use plain RSpec mocks ("stubs") to replace the HTTP request to the API with scripted behavior. Can you minimize the number of lines of code that now no longer run during tests?
  3. Mock out the network request to the API using Webmock
  4. Mock out the network request to the API using VCR. What happens when you change the movie title in the test?

Talk to your mentor about the pros and cons of each approach.

Owner of this card:

Henning Koch
Last edit:
4 months ago
by Johanna Hartmann
Posted by Henning Koch to makandra Curriculum
This website uses cookies to improve usability and analyze traffic.
Accept or learn more