Elixir allows me to create fast, scalable applications and be productive like never before. Almost every time I think I need a tool, I discover a simple and easy way to do the same thing with just vanilla Elixir.

For example, coming from the Ruby world, I instinctively want to reach for a gem to get things done. When testing I almost always reach for mock5, which allows me to easily mock APIs with Sinatra’s elegant DSL. In the Elixir world, such tooling doesn’t exist yet – but I don’t think it’s even necessary.

Let’s imagine we are writing a tool that reaches out to Github’s api and gives us information about users. Here is what the request and response might look like:

Now that we know what the response looks like, we can write a test. Our test is going to assert on a function get/1. (This test is fictitious and doesn’t really do anything; it's just an exercise to show how easy it is to mock an API.)

Now that we have a failing test, I am going to make an abstraction around the Github API. This is going to be a base that can be used with other modules. You will see shortly that this will be the piece we replace during tests.

Now if we run the tests, they pass. Which is great, except that we're actually hitting the live Github API. This will slow our tests down, and we're dealing with production data. Luckily, Elixir and mix have our back. Uncomment the following from your config/config.exs: