Ryan Daigle

Mocks and Explicit Contracts in Practice with an Elixir Slackbot

I gave a brief talk at the Triangle |> Elixir group last week where I discussed my experience putting into practice Josè Valim’s advice on how to properly mock components that integrate with a remote service. While the concepts are not Elixir-specific, I used a Phonenix Slackbot project as an example, which you can see here.

The summary is - I think it worked out really well! There is no silver bullet when it comes to testing an integration to a remote service - at some point you have to test that the actual calls are being sent and processed correctly. However, this pattern isolates that process to a single, well-defined, and interchangeable component and using tags to explicitly invoke or ignore the remote tests works really well in practice.

If you want to view how the remote component was modeled, see the Search modules here and the defining Behavior here.