Skip to content

Commit d216188

Browse files
author
Guilherme Souza
committed
Add 'Usage in tests' section to README
1 parent cdb7f0f commit d216188

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,37 @@ let value = cache.retrieve(at: .myKey)
6262
```swift
6363
cache.remove(at: .myKey)
6464
```
65+
66+
### Usage in tests
67+
68+
This library provides some helpers for easy usage on tests such as:
69+
70+
#### Noop
71+
72+
An implementation of `Cache` that does nothing when called.
73+
74+
```swift
75+
let cache = Cache.noop
76+
```
77+
78+
79+
#### Failing
80+
81+
An implementation of `Cache` that fails with an `XCTFail` call.
82+
83+
```swift
84+
var setEntryCalled = false
85+
86+
let cache = Cache.failing
87+
.override(
88+
setEntry: { entry, key in
89+
setEntryCalled = true
90+
}
91+
)
92+
93+
cache.set("string value", at: .myKey)
94+
95+
XCTAssertTrue(setEntryCalled)
96+
```
97+
98+
At the code snipped above all calls to a method that wasn't overriden will terminate with a `XCTFail`.

0 commit comments

Comments
 (0)