-
Notifications
You must be signed in to change notification settings - Fork 104
/
mockfile.html
352 lines (338 loc) · 17.7 KB
/
mockfile.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
<!DOCTYPE html>
<html lang="en">
<head>
<title>Mockfile Reference</title>
<link rel="stylesheet" type="text/css" href="css/jazzy.css" />
<link rel="stylesheet" type="text/css" href="css/highlight.css" />
<meta charset='utf-8'>
<script src="js/jquery.min.js" defer></script>
<script src="js/jazzy.js" defer></script>
<script src="js/lunr.min.js" defer></script>
<script src="js/typeahead.jquery.js" defer></script>
<script src="js/jazzy.search.js" defer></script>
</head>
<body>
<a title="Mockfile Reference"></a>
<header>
<div class="content-wrapper">
<p><a href="index.html">SwiftyMocky 4.2.0 Docs</a> (86% documented)</p>
<p class="header-right"><a href="https://github.com/MakeAWishFoundation/SwiftyMocky"><img src="img/gh.png" alt="GitHub"/>View on GitHub</a></p>
<div class="header-right">
<form role="search" action="search.json">
<input type="text" placeholder="Search documentation" data-typeahead>
</form>
</div>
</div>
</header>
<div class="content-wrapper">
<p id="breadcrumbs">
<a href="index.html">SwiftyMocky Reference</a>
<img id="carat" src="img/carat.png" alt=""/>
Mockfile Reference
</p>
</div>
<div class="content-wrapper">
<nav class="sidebar">
<ul class="nav-groups">
<li class="nav-group-name">
<a href="Main%20Guides.html">Main Guides</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="overview.html">Overview</a>
</li>
<li class="nav-group-task">
<a href="installation.html">Installation</a>
</li>
<li class="nav-group-task">
<a href="setup-in-project.html">Setup in project</a>
</li>
<li class="nav-group-task">
<a href="mockfile.html">Mockfile</a>
</li>
<li class="nav-group-task">
<a href="command-line-interface.html">Command Line Interface</a>
</li>
<li class="nav-group-task">
<a href="supported-features.html">Supported features</a>
</li>
<li class="nav-group-task">
<a href="prototyping.html">Prototyping</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="Additional%20Guides.html">Additional Guides</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="matcher-support-for-not-equatable.html">Matcher support for not Equatable</a>
</li>
<li class="nav-group-task">
<a href="handling-generics.html">Handling Generics</a>
</li>
<li class="nav-group-task">
<a href="examples.html">Examples</a>
</li>
<li class="nav-group-task">
<a href="legacy.html">Legacy</a>
</li>
<li class="nav-group-task">
<a href="add-xcode-generate-action.html">Add XCode generate action</a>
</li>
<li class="nav-group-task">
<a href="known-issues.html">Known issues</a>
</li>
<li class="nav-group-task">
<a href="changelog.html">CHANGELOG</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="Global%20methods.html">Global methods</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="Global%20methods.html#/s:11SwiftyMocky5Givenyyx_ABQzAA14StubbingPolicyOtAA4MockRzlF">Given(_:_:_:)</a>
</li>
<li class="nav-group-task">
<a href="Global%20methods.html#/s:11SwiftyMocky5Givenyyxm_06StaticC0QzAA14StubbingPolicyOtAA0D4MockRzlF">Given(_:_:_:)</a>
</li>
<li class="nav-group-task">
<a href="Global%20methods.html#/s:11SwiftyMocky7Performyyx_ABQztAA4MockRzlF">Perform(_:_:)</a>
</li>
<li class="nav-group-task">
<a href="Global%20methods.html#/s:11SwiftyMocky7Performyyxm_06StaticC0QztAA0D4MockRzlF">Perform(_:_:)</a>
</li>
<li class="nav-group-task">
<a href="Global%20methods.html#/s:11SwiftyMocky6Verify__4file4lineyx_ABQzs12StaticStringVSutAA4MockRzlF">Verify(_:_:file:line:)</a>
</li>
<li class="nav-group-task">
<a href="Global%20methods.html#/s:11SwiftyMocky6Verify__4file4lineyxm_06StaticC0Qzs0F6StringVSutAA0F4MockRzlF">Verify(_:_:file:line:)</a>
</li>
<li class="nav-group-task">
<a href="Global%20methods.html#/s:11SwiftyMocky6Verify___4file4lineyx_AA5CountOABQzs12StaticStringVSutAA4MockRzlF">Verify(_:_:_:file:line:)</a>
</li>
<li class="nav-group-task">
<a href="Global%20methods.html#/s:11SwiftyMocky6Verify___4file4lineyxm_AA5CountO06StaticC0Qzs0G6StringVSutAA0G4MockRzlF">Verify(_:_:_:file:line:)</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="Configuration.html">Configuration</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="Enums/StubbingPolicy.html">StubbingPolicy</a>
</li>
<li class="nav-group-task">
<a href="Enums/SequencingPolicy.html">SequencingPolicy</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="Types.html">Types</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="Protocols/Mock.html">Mock</a>
</li>
<li class="nav-group-task">
<a href="Protocols/StaticMock.html">StaticMock</a>
</li>
<li class="nav-group-task">
<a href="Enums/Parameter.html">Parameter</a>
</li>
<li class="nav-group-task">
<a href="Classes/Matcher.html">Matcher</a>
</li>
<li class="nav-group-task">
<a href="Classes/Matcher/ComparisonResult.html">– ComparisonResult</a>
</li>
<li class="nav-group-task">
<a href="Classes/Matcher/ParameterComparisonResult.html">– ParameterComparisonResult</a>
</li>
<li class="nav-group-task">
<a href="Protocols/Countable.html">Countable</a>
</li>
<li class="nav-group-task">
<a href="Enums/Count.html">Count</a>
</li>
<li class="nav-group-task">
<a href="Structs/Stubber.html">Stubber</a>
</li>
<li class="nav-group-task">
<a href="Structs/StubberThrows.html">StubberThrows</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="Generics.html">Generics</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="Structs/GenericAttribute.html">GenericAttribute</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="Helpers.html">Helpers</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="Helpers.html#/s:11SwiftyMocky20XCTAssertThrowsError_2of_4file4lineyxyKXK_q_mSSyXKs12StaticStringVSuts0E0R_r0_lF">XCTAssertThrowsError(_:of:_:file:line:)</a>
</li>
<li class="nav-group-task">
<a href="Helpers.html#/s:11SwiftyMocky20XCTAssertThrowsError_5error_4file4lineyxyKXK_q_SSyXKs12StaticStringVSutSQR_s0E0R_r0_lF">XCTAssertThrowsError(_:error:_:file:line:)</a>
</li>
<li class="nav-group-task">
<a href="Classes/MockyAssertion.html">MockyAssertion</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="Internal.html">Internal</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="Classes/SwiftyMockyTestObserver.html">SwiftyMockyTestObserver</a>
</li>
<li class="nav-group-task">
<a href="Classes/SwiftyMockyTestObserver.html">SwiftyMockyTestObserver</a>
</li>
<li class="nav-group-task">
<a href="Structs/FatalErrorUtil.html">FatalErrorUtil</a>
</li>
<li class="nav-group-task">
<a href="Protocols/OptionalType.html">OptionalType</a>
</li>
<li class="nav-group-task">
<a href="Protocols/WithSequencingPolicy.html">WithSequencingPolicy</a>
</li>
<li class="nav-group-task">
<a href="Protocols/WithStaticSequencingPolicy.html">WithStaticSequencingPolicy</a>
</li>
<li class="nav-group-task">
<a href="Protocols/WithStubbingPolicy.html">WithStubbingPolicy</a>
</li>
<li class="nav-group-task">
<a href="Extensions/Int.html">Int</a>
</li>
<li class="nav-group-task">
<a href="Extensions/Optional.html">Optional</a>
</li>
<li class="nav-group-task">
<a href="Extensions/UInt.html">UInt</a>
</li>
<li class="nav-group-task">
<a href="Enums/MockError.html">MockError</a>
</li>
<li class="nav-group-task">
<a href="Enums/StubProduct.html">StubProduct</a>
</li>
<li class="nav-group-task">
<a href="Classes/StubbedMethod.html">StubbedMethod</a>
</li>
<li class="nav-group-task">
<a href="Internal.html#/s:11SwiftyMocky7Failureys5NeverOSSF">Failure(_:)</a>
</li>
<li class="nav-group-task">
<a href="Internal.html#/s:11SwiftyMocky0B6Assert__4file4lineySbyXK_SSyXKs12StaticStringVSutF">MockyAssert(_:_:file:line:)</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="Other%20Guides.html">Other Guides</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="contents.html">Contents</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="Other%20Classes.html">Other Classes</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="Classes/ArgumentCaptor.html">ArgumentCaptor</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="Other%20Enums.html">Other Enumerations</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="Enums/MockScope.html">MockScope</a>
</li>
<li class="nav-group-task">
<a href="Enums/Utils.html">Utils</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="Other%20Protocols.html">Other Protocols</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="Protocols/TypeErasedValue.html">TypeErasedValue</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="Other%20Structs.html">Other Structures</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="Structs/TypeErasedAttribute.html">TypeErasedAttribute</a>
</li>
</ul>
</li>
</ul>
</nav>
<article class="main-content">
<section>
<section class="section">
<h1 id='strong-mockfile-strong-format' class='heading'><strong>Mockfile</strong> format</h1>
<p>Mockfile is a YAML configuration, allowing to define what gets mocked. It simplifies including and excluding sources, as well as defining what should be imported or <code>@testable</code> imported.</p>
<p>It also ties generated <strong>Mock</strong> configuration with a specific target, allowing to lint it agains most common issues.</p>
<p>Every generated file have its own section, following pattern below:</p>
<pre class="highlight yaml"><code><span class="na">sourceryCommand</span><span class="pi">:</span> <span class="s">null</span> <span class="c1"># 1. (optional)</span>
<span class="na">sourceryTemplate</span><span class="pi">:</span> <span class="s">null</span> <span class="c1"># 1. (optional)</span>
<span class="na">mock1</span><span class="pi">:</span> <span class="c1"># 2.</span>
<span class="na">sources</span><span class="pi">:</span> <span class="c1"># 2.1.</span>
<span class="na">include</span><span class="pi">:</span> <span class="c1"># 2.1.1</span>
<span class="pi">-</span> <span class="s">./MyApp</span>
<span class="na">exclude</span><span class="pi">:</span> <span class="pi">[]</span> <span class="c1"># 2.1.2 (optional)</span>
<span class="na">output</span><span class="pi">:</span> <span class="c1"># 2.2</span>
<span class="s">./MyAppUnitTests/Mocks/Mock.generated.swift</span>
<span class="na">targets</span><span class="pi">:</span> <span class="c1"># 2.3 (optional)</span>
<span class="pi">-</span> <span class="s">MyAppUnitTests</span>
<span class="na">testable</span><span class="pi">:</span> <span class="pi">[]</span> <span class="c1"># 2.4 (optional)</span>
<span class="na">import</span><span class="pi">:</span> <span class="pi">[]</span> <span class="c1"># 2.5 (optional)</span>
<span class="na">prototype</span><span class="pi">:</span> <span class="s">false</span> <span class="c1"># 2.6 (optional)</span>
<span class="na">sourcery</span><span class="pi">:</span> <span class="c1"># 2.7 (optional)</span>
<span class="pi">-</span> <span class="s">./path/to/custom/sourcery.yml</span> <span class="c1"># (optional)</span>
<span class="na">mock2</span><span class="pi">:</span> <span class="c1"># 2.</span>
<span class="s">...</span>
</code></pre>
<ol>
<li><code>sourceryCommand</code> is by default <code>nil</code>. You can use it to select custom Sourcery version/command/binary, instead of using default one bundled with SwiftyMocky CLI via <code>mint</code>. <code>sourceryTemplate</code> is custpom template location to use instead of default one. Default template would be derived from Pods,Carthage,SPM directory. If not found, CLI would use bundled template.</li>
<li><strong>Distinctive name</strong> of your mock configuration. You can define as much <strong>configurations</strong> as you want. Each of them represents one generated file. That allows to have a separate mocks for a separate targets (you usually need that if you have more than one test target)
<ol>
<li><code>sources</code> defines what files/directories would be scanned for <code>AutoMockable</code> types.
<ol>
<li><code>include</code> list of included files/directories relative to project root</li>
<li><code>exclude</code> list of excluded files/directories relative to project root</li>
</ol></li>
<li><code>output</code> location and name of generated mocks file. If no name specified “Mock.generated.swift” would be used</li>
<li><code>targets</code> list of targets names. It should match the test targets that are using generated mocks file. Used to determine if your setup is correct.</li>
<li><code>testable</code> list of testable modules imports. By default, if you generate mocks for <code>YourApp</code>, it should contain <code>YourApp</code>. Would be placed at the top of the generated file.</li>
<li><code>import</code> list of modules imports. Would be placed at the top of the generated file.</li>
<li><code>prototype</code> default is <code>false</code>. Set <code>true</code> if you are going to use Carthage <code>SwiftyPrototype</code> library</li>
<li><code>sourcery</code> list of paths to additional Sourcery configurations, if you want to execute them alongside the mock generation.</li>
</ol></li>
</ol>
<blockquote>
<p><strong>Note 1:</strong> Calling <code>swiftymocky setup</code> will launch an interactive tool helping you to create and prefill the <strong>Mockfile</strong>. You can also use <code>swiftymocky init</code> if you want a placeholder you can fill manually.</p>
<p><strong>Note 2:</strong> To evaluate your <strong>Mockfile</strong> setup, as well as other things, run <code>swiftmocky doctor</code>.</p>
<p><strong>Note 3:</strong> You can use <code>swiftymocky autoimport</code> to prefill <code>testable</code> and <code>import</code> in your configurations.</p>
</blockquote>
</section>
</section>
<section id="footer">
<p>Copyright © 2017 MakeAWishFoundation. All rights reserved.</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external noopener">jazzy ♪♫ v0.14.2</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external noopener">Realm</a> project.</p>
</section>
</article>
</div>
</body>
</html>