... | ... | @@ -3,6 +3,8 @@ |
|
|
- **Stubs**: provide canned answers to calls made during the test, usually not responding at all to anything outside what's programmed in for the test;
|
|
|
- **Mocks**: are pre-programmed with expectations which form a specification of the calls they are expected to receive. They can throw an exception if they receive a call they don't expect and are checked during verification to ensure they got all the calls they were expecting.
|
|
|
|
|
|
(source: [http://martinfowler.com/bliki/TestDouble.html](http://martinfowler.com/bliki/TestDouble.html))
|
|
|
|
|
|
# Stub examples
|
|
|
|
|
|
Bellow you will find an example of stub created using Minitest's stub framework. In this example we are using a stub to simulate the behaviour of the **sku_list** method. The original implementation of this method connects to a remote database and returns a huge list (1000+ items) of skus available in the store. For the purpose of this particular test case we do not intend to test the connection with the remote database. We also do not need a huge list of skus, only a few will do. By stubbing this method, we will avoid issues with the remote database and the test will run much faster.
|
... | ... | |