Chapter 1: Introduction
This guide book will walk you through using all the features and functionality of
Patch to make great unit tests.
Patch is founded on One Big Idea
Patched functions should always return the mock value they are given.
This is how patched functions behave in
Patch. Every function is a valid target for patching and once patched the function will always return the mock value given. If you ever feel lost, remember this One Big Idea.
Throughout this guide book we are going to use some common terminology, let's define them.
Patch is used as both a verb and a noun. To "patch" a function is to replace it with an alternative implementation. The alternative implementation is the noun form of "patch" sometimes called the "patched function."
patch(Example, :example, :patched)
Example.examplehas been "patched" with a "patch" that always returns the value
The value returned by a "patch" is referred to as the "mock value". There are a number of types of "mock values" that will be covered in detail in this guide book.
Calls that happen before the module has been patched are unobserved, the test author can not assert or refute anything about the calls to a module before it has been patched.