Uses the Cat Facts API to illustrate different approaches to creating a Mox style testing seam. See the accompanying blog post here
CatFacts.CatFactsApi
is a behaviour and testing seam for extracting Cat Facts from Cat Facts API. It is implemented by CatFacts.RealCatFactsApi
and mocked by MockCatFactsApi
.
Various versions can be seen with the following tags.
initial_standard_moxing
- the private functionCatFacts.CatFactsApi.cat_facts_api/0
reads application config to return the implementation. This is the normal way of doing things.accidental_behaviour_tag_deletion
- a version in which I "accidentally" forgot to add@behaviour CatFacts.CatFactsApi
toCatFacts.RealCatFactsApi
. An ommission which will cause problems later.rename_but_omit_implementation
-CatFacts.CatFactsApi.get_cat_facts/0
has been renamed toCatFacts.fetch_fun_feline_facts/0
. Thet tests are passing but I "forgot" to rename the function inCatFacts.RealCatFactsApi
.alternate_implementation_injection
- inject the mock or real implementaton usingalias
. Still broken but compilation anddialyzer
now gives warnings.final_working
- all working fine again, with the new function name (and the@behaviour
restored).