Approach for numerous edge cases, HTTP GET, exvcr

That article actually re-convinced me to use mock and not to roll my own mock server. :003:

I have already used all of them: exvcr, mock, mox and bypass. For testing code that relies on underlying HTTP client libraries I liked mock the most with bypass a close second.

mox is amazing for a lot of testing but it doesn’t help me mock the underlying HTTP client library. I’ll use mox when I write higher level code that tests working with my API client itself e.g. I will make it return {:error, :too_many_retries} and see if the higher-level code reacts properly to that.

exvcr I tried to use just today but it was too opaque for me and even though the docs / GitHub page are rich on details I was unable to achieve a simple scenario – namely have two use_cassette blocks one inside the other (as I was testing pagination and wanted two different requests mocked, and yes I used its query parameter distinction parameter). Plus it wasn’t obvious how to use recorded (custom) cassettes. I simply gave up after 10 minutes and reached for mock which took the same amount of time and worked right away with zero surprises (NOTE: I only used mock twice before and the last time was more than a year ago).


Not to incline future readers too much in any particular direction as libraries evolve and get better (though some don’t) but so far mock was the best for testing code that relies on a lower level library (by mocking the said lower-level library seamlessly) and mox for testing everything in your own code where you have full control.