Test an API endpoint with Minitest
In Ruby is extremely important to test everything, why? Because it’s an interpreted language and is dynamically typed, so errors will pop up at runtime (it could be production ☠️).
Apart from code errors if we change the response of an endpoint it’s very probable that we will break the client apps. So remember! At least 1 test for each endpoint.
And why Minitest? It’s fast, simple and you already know Ruby 💎
Now imagine we have a simple endpoint at /api/v1/cars
to return the cars available in our database. Let’s see how to do it with a simple integration test:
For the dummy data on your tests, you can use Rails fixtures or FactoryBot.