-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathMocks.html
498 lines (498 loc) · 26.1 KB
/
Mocks.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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
Module: RSpec::Mocks
— Documentation by YARD 0.9.37
</title>
<link rel="stylesheet" href="/documentation/3.13/rspec-mocks/css/style.css" type="text/css" />
<link rel="stylesheet" href="/documentation/3.13/rspec-mocks/css/common.css" type="text/css" />
<script type="text/javascript">
pathId = "RSpec::Mocks";
relpath = '../';
</script>
<script type="text/javascript" charset="utf-8" src="/documentation/3.13/rspec-mocks/js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="/documentation/3.13/rspec-mocks/js/app.js"></script>
</head>
<body>
<div class="nav_wrap">
<iframe id="nav" src="../class_list.html?1"></iframe>
<div id="resizer"></div>
</div>
<div id="main" tabindex="-1">
<div id="header">
<div id="menu">
<a href="../_index.html">Index (M)</a> »
<span class='title'><span class='object_link'><a href="../RSpec.html" title="RSpec (module)">RSpec</a></span></span>
»
<span class="title">Mocks</span>
</div>
<div id="search">
<a class="full_list_link" id="class_list_link"
href="../class_list.html">
<svg width="24" height="24">
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
</svg>
</a>
</div>
<div class="clear"></div>
</div>
<div id="content"><h1>Module: RSpec::Mocks
</h1>
<div class="box_info">
<dl>
<dt>Defined in:</dt>
<dd>lib/rspec/mocks.rb<span class="defines">,<br />
lib/rspec/mocks/proxy.rb,<br /> lib/rspec/mocks/space.rb,<br /> lib/rspec/mocks/syntax.rb,<br /> lib/rspec/mocks/targets.rb,<br /> lib/rspec/mocks/version.rb,<br /> lib/rspec/mocks/order_group.rb,<br /> lib/rspec/mocks/test_double.rb,<br /> lib/rspec/mocks/mutate_const.rb,<br /> lib/rspec/mocks/configuration.rb,<br /> lib/rspec/mocks/message_chain.rb,<br /> lib/rspec/mocks/method_double.rb,<br /> lib/rspec/mocks/error_generator.rb,<br /> lib/rspec/mocks/example_methods.rb,<br /> lib/rspec/mocks/verifying_proxy.rb,<br /> lib/rspec/mocks/matchers/receive.rb,<br /> lib/rspec/mocks/method_reference.rb,<br /> lib/rspec/mocks/object_reference.rb,<br /> lib/rspec/mocks/verifying_double.rb,<br /> lib/rspec/mocks/argument_matchers.rb,<br /> lib/rspec/mocks/marshal_extension.rb,<br /> lib/rspec/mocks/any_instance/chain.rb,<br /> lib/rspec/mocks/any_instance/proxy.rb,<br /> lib/rspec/mocks/message_expectation.rb,<br /> lib/rspec/mocks/minitest_integration.rb,<br /> lib/rspec/mocks/minitest_integration.rb,<br /> lib/rspec/mocks/any_instance/recorder.rb,<br /> lib/rspec/mocks/argument_list_matcher.rb,<br /> lib/rspec/mocks/matchers/have_received.rb,<br /> lib/rspec/mocks/any_instance/stub_chain.rb,<br /> lib/rspec/mocks/instance_method_stasher.rb,<br /> lib/rspec/mocks/matchers/receive_messages.rb,<br /> lib/rspec/mocks/any_instance/message_chains.rb,<br /> lib/rspec/mocks/any_instance/error_generator.rb,<br /> lib/rspec/mocks/any_instance/stub_chain_chain.rb,<br /> lib/rspec/mocks/verifying_message_expectation.rb,<br /> lib/rspec/mocks/any_instance/expectation_chain.rb,<br /> lib/rspec/mocks/matchers/receive_message_chain.rb,<br /> lib/rspec/mocks/any_instance/expect_chain_chain.rb,<br /> lib/rspec/mocks/matchers/expectation_customization.rb</span>
</dd>
</dl>
</div>
<h2>Overview</h2><div class="docstring">
<div class="discussion">
<p>Contains top-level utility methods. While this contains a few
public methods, these are not generally meant to be called from
a test or example. They exist primarily for integration with
test frameworks (such as rspec-core).</p>
</div>
</div>
<div class="tags">
</div><h2>Defined Under Namespace</h2>
<p class="children">
<strong class="modules">Modules:</strong> <span class='object_link'><a href="Mocks/ArgumentMatchers.html" title="RSpec::Mocks::ArgumentMatchers (module)">ArgumentMatchers</a></span>, <span class='object_link'><a href="Mocks/ExampleMethods.html" title="RSpec::Mocks::ExampleMethods (module)">ExampleMethods</a></span>, <span class='object_link'><a href="Mocks/Matchers.html" title="RSpec::Mocks::Matchers (module)">Matchers</a></span>, <span class='object_link'><a href="Mocks/Syntax.html" title="RSpec::Mocks::Syntax (module)">Syntax</a></span>, <span class='object_link'><a href="Mocks/TestDouble.html" title="RSpec::Mocks::TestDouble (module)">TestDouble</a></span>, <span class='object_link'><a href="Mocks/Version.html" title="RSpec::Mocks::Version (module)">Version</a></span>
<strong class="classes">Classes:</strong> <span class='object_link'><a href="Mocks/ArgumentListMatcher.html" title="RSpec::Mocks::ArgumentListMatcher (class)">ArgumentListMatcher</a></span>, <span class='object_link'><a href="Mocks/Configuration.html" title="RSpec::Mocks::Configuration (class)">Configuration</a></span>, <span class='object_link'><a href="Mocks/Constant.html" title="RSpec::Mocks::Constant (class)">Constant</a></span>, <span class='object_link'><a href="Mocks/ConstantMutator.html" title="RSpec::Mocks::ConstantMutator (class)">ConstantMutator</a></span>, <span class='object_link'><a href="Mocks/DirectObjectReference.html" title="RSpec::Mocks::DirectObjectReference (class)">DirectObjectReference</a></span>, <span class='object_link'><a href="Mocks/Double.html" title="RSpec::Mocks::Double (class)">Double</a></span>, <span class='object_link'><a href="Mocks/MessageExpectation.html" title="RSpec::Mocks::MessageExpectation (class)">MessageExpectation</a></span>, <span class='object_link'><a href="Mocks/NamedObjectReference.html" title="RSpec::Mocks::NamedObjectReference (class)">NamedObjectReference</a></span>, <span class='object_link'><a href="Mocks/VerifyingMessageExpectation.html" title="RSpec::Mocks::VerifyingMessageExpectation (class)">VerifyingMessageExpectation</a></span>
</p>
<h2>
Constant Summary
<small><a href="#" class="constants_summary_toggle">collapse</a></small>
</h2>
<dl class="constants">
<dt id="MockExpectationError-constant" class="">MockExpectationError =
<div class="docstring">
<div class="discussion">
<p>Raised when a message expectation is not satisfied.</p>
</div>
</div>
<div class="tags">
</div>
</dt>
<dd><pre class="code"><span class='op'>::</span><span class='const'>Minitest</span><span class='op'>::</span><span class='const'>Assertion</span></pre></dd>
<dt id="ExpiredTestDoubleError-constant" class="">ExpiredTestDoubleError =
<div class="docstring">
<div class="discussion">
<p>Raised when a test double is used after it has been torn
down (typically at the end of an rspec-core example).</p>
</div>
</div>
<div class="tags">
</div>
</dt>
<dd><pre class="code"><span class='const'><span class='object_link'><a href="../Class.html" title="Class (class)">Class</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='const'><span class='object_link'><a href="#MockExpectationError-constant" title="RSpec::Mocks::MockExpectationError (constant)">MockExpectationError</a></span></span><span class='rparen'>)</span></pre></dd>
<dt id="OutsideOfExampleError-constant" class="">OutsideOfExampleError =
<div class="docstring">
<div class="discussion">
<p>Raised when doubles or partial doubles are used outside of the per-test lifecycle.</p>
</div>
</div>
<div class="tags">
</div>
</dt>
<dd><pre class="code"><span class='const'><span class='object_link'><a href="../Class.html" title="Class (class)">Class</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='const'>StandardError</span><span class='rparen'>)</span></pre></dd>
<dt id="MockExpectationAlreadyInvokedError-constant" class="">MockExpectationAlreadyInvokedError =
<div class="docstring">
<div class="discussion">
<p>Raised when an expectation customization method (e.g. <code>with</code>,
<code>and_return</code>) is called on a message expectation which has already been
invoked.</p>
</div>
</div>
<div class="tags">
</div>
</dt>
<dd><pre class="code"><span class='const'><span class='object_link'><a href="../Class.html" title="Class (class)">Class</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='const'>Exception</span><span class='rparen'>)</span></pre></dd>
<dt id="CannotSupportArgMutationsError-constant" class="deprecated">CannotSupportArgMutationsError =
<div class="docstring">
<div class="discussion">
<div class="note deprecated"><strong>Deprecated.</strong> <div class='inline'><p>We no longer raise this error but the constant remains until
RSpec 4 for SemVer reasons.</p>
</div></div>
<p>Raised for situations that RSpec cannot support due to mutations made
externally on arguments that RSpec is holding onto to use for later
comparisons.</p>
</div>
</div>
<div class="tags">
</div>
</dt>
<dd><pre class="code"><span class='const'><span class='object_link'><a href="../Class.html" title="Class (class)">Class</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='const'>StandardError</span><span class='rparen'>)</span></pre></dd>
</dl>
<h2>
Class Method Summary
<small><a href="#" class="summary_toggle">collapse</a></small>
</h2>
<ul class="summary">
<li class="public ">
<span class="summary_signature">
<a href="#allow_message-class_method" title="allow_message (class method)">.<strong>allow_message</strong>(subject, message, opts = {}) { ... } ⇒ Object </a>
</span>
<span class="summary_desc"><div class='inline'><p>Adds an allowance (stub) on <code>subject</code>.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#configuration-class_method" title="configuration (class method)">.<strong>configuration</strong> ⇒ Object </a>
</span>
<span class="summary_desc"><div class='inline'><p>Mocks specific configuration, as distinct from <code>RSpec.configuration</code> which is core RSpec configuration.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#expect_message-class_method" title="expect_message (class method)">.<strong>expect_message</strong>(subject, message, opts = {}) { ... } ⇒ Object </a>
</span>
<span class="summary_desc"><div class='inline'><p>Sets a message expectation on <code>subject</code>.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#setup-class_method" title="setup (class method)">.<strong>setup</strong> ⇒ Object </a>
</span>
<span class="summary_desc"><div class='inline'><p>Performs per-test/example setup.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#teardown-class_method" title="teardown (class method)">.<strong>teardown</strong> ⇒ Object </a>
</span>
<span class="summary_desc"><div class='inline'><p>Cleans up all test double state (including any methods that were redefined on partial doubles).</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#verify-class_method" title="verify (class method)">.<strong>verify</strong> ⇒ Object </a>
</span>
<span class="summary_desc"><div class='inline'><p>Verifies any message expectations that were set during the test or example.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#with_temporary_scope-class_method" title="with_temporary_scope (class method)">.<strong>with_temporary_scope</strong> ⇒ Object </a>
</span>
<span class="summary_desc"><div class='inline'><p>Call the passed block and verify mocks after it has executed.</p>
</div></span>
</li>
</ul>
<div id="class_method_details" class="method_details_list">
<h2>Class Method Details</h2>
<div class="method_details first">
<h3 class="signature first" id="allow_message-class_method">
.<strong>allow_message</strong>(subject, message, opts = {}) { ... } ⇒ <tt>Object</tt>
</h3><div class="docstring">
<div class="discussion">
<p>Adds an allowance (stub) on <code>subject</code></p>
</div>
</div>
<div class="tags">
<div class="examples">
<h4 class="tag_title">Examples:</h4>
<h5 class="example_title"><div class='inline'><p>Defines the implementation of <code>foo</code> on <code>bar</code>, using the passed block</p>
</div></h5>
<pre class="example code"><code><span class='id identifier rubyid_x'>x</span> <span class='op'>=</span> <span class='int'>0</span>
<span class='const'><span class='object_link'><a href="../RSpec.html" title="RSpec (module)">RSpec</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="" title="RSpec::Mocks (module)">Mocks</a></span></span><span class='period'>.</span><span class='id identifier rubyid_allow_message'>allow_message</span><span class='lparen'>(</span><span class='id identifier rubyid_bar'>bar</span><span class='comma'>,</span> <span class='symbol'>:foo</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='id identifier rubyid_x'>x</span> <span class='op'>+=</span> <span class='int'>1</span> <span class='rbrace'>}</span></code></pre>
</div>
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>subject</span>
<span class='type'></span>
—
<div class='inline'><p>the subject to which the message will be added</p>
</div>
</li>
<li>
<span class='name'>message</span>
<span class='type'></span>
—
<div class='inline'><p>a symbol, representing the message that will be
added.</p>
</div>
</li>
<li>
<span class='name'>opts</span>
<span class='type'></span>
<em class="default">(defaults to: <tt>{}</tt>)</em>
—
<div class='inline'><p>a hash of options, :expected_from is used to set the
original call site</p>
</div>
</li>
</ul>
<p class="tag_title">Yields:</p>
<ul class="yield">
<li>
<span class='type'></span>
<div class='inline'><p>an optional implementation for the allowance</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
69
70
71</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/rspec/mocks.rb', line 69</span>
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_allow_message'>allow_message</span><span class='lparen'>(</span><span class='id identifier rubyid_subject'>subject</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span><span class='comma'>,</span> <span class='id identifier rubyid_opts'>opts</span><span class='op'>=</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
<span class='id identifier rubyid_space'>space</span><span class='period'>.</span><span class='id identifier rubyid_proxy_for'>proxy_for</span><span class='lparen'>(</span><span class='id identifier rubyid_subject'>subject</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_add_stub'>add_stub</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='comma'>,</span> <span class='id identifier rubyid_opts'>opts</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="configuration-class_method">
.<strong>configuration</strong> ⇒ <tt>Object</tt>
</h3><div class="docstring">
<div class="discussion">
<p>Mocks specific configuration, as distinct from <code>RSpec.configuration</code>
which is core RSpec configuration.</p>
</div>
</div>
<div class="tags">
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
206
207
208</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/rspec/mocks/configuration.rb', line 206</span>
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_configuration'>configuration</span>
<span class='ivar'>@configuration</span> <span class='op'>||=</span> <span class='const'><span class='object_link'><a href="Mocks/Configuration.html" title="RSpec::Mocks::Configuration (class)">Configuration</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="Mocks/Configuration.html#initialize-instance_method" title="RSpec::Mocks::Configuration#initialize (method)">new</a></span></span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="expect_message-class_method">
.<strong>expect_message</strong>(subject, message, opts = {}) { ... } ⇒ <tt>Object</tt>
</h3><div class="docstring">
<div class="discussion">
<p>Sets a message expectation on <code>subject</code>.</p>
</div>
</div>
<div class="tags">
<div class="examples">
<h4 class="tag_title">Examples:</h4>
<h5 class="example_title"><div class='inline'><p>Expect the message <code>foo</code> to receive <code>bar</code>, then call it</p>
</div></h5>
<pre class="example code"><code><span class='const'><span class='object_link'><a href="../RSpec.html" title="RSpec (module)">RSpec</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="" title="RSpec::Mocks (module)">Mocks</a></span></span><span class='period'>.</span><span class='id identifier rubyid_expect_message'>expect_message</span><span class='lparen'>(</span><span class='id identifier rubyid_bar'>bar</span><span class='comma'>,</span> <span class='symbol'>:foo</span><span class='rparen'>)</span>
<span class='id identifier rubyid_bar'>bar</span><span class='period'>.</span><span class='id identifier rubyid_foo'>foo</span></code></pre>
</div>
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>subject</span>
<span class='type'></span>
—
<div class='inline'><p>the subject on which the message will be expected</p>
</div>
</li>
<li>
<span class='name'>message</span>
<span class='type'></span>
—
<div class='inline'><p>a symbol, representing the message that will be
expected.</p>
</div>
</li>
<li>
<span class='name'>opts</span>
<span class='type'></span>
<em class="default">(defaults to: <tt>{}</tt>)</em>
—
<div class='inline'><p>a hash of options, :expected_from is used to set the
original call site</p>
</div>
</li>
</ul>
<p class="tag_title">Yields:</p>
<ul class="yield">
<li>
<span class='type'></span>
<div class='inline'><p>an optional implementation for the expectation</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
84
85
86</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/rspec/mocks.rb', line 84</span>
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_expect_message'>expect_message</span><span class='lparen'>(</span><span class='id identifier rubyid_subject'>subject</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span><span class='comma'>,</span> <span class='id identifier rubyid_opts'>opts</span><span class='op'>=</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
<span class='id identifier rubyid_space'>space</span><span class='period'>.</span><span class='id identifier rubyid_proxy_for'>proxy_for</span><span class='lparen'>(</span><span class='id identifier rubyid_subject'>subject</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_add_message_expectation'>add_message_expectation</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='comma'>,</span> <span class='id identifier rubyid_opts'>opts</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="setup-class_method">
.<strong>setup</strong> ⇒ <tt>Object</tt>
</h3><div class="docstring">
<div class="discussion">
<p>Performs per-test/example setup. This should be called before
an test or example begins.</p>
</div>
</div>
<div class="tags">
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
38
39
40</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/rspec/mocks.rb', line 38</span>
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_setup'>setup</span>
<span class='ivar'>@space_stack</span> <span class='op'><<</span> <span class='lparen'>(</span><span class='ivar'>@space</span> <span class='op'>=</span> <span class='id identifier rubyid_space'>space</span><span class='period'>.</span><span class='id identifier rubyid_new_scope'>new_scope</span><span class='rparen'>)</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="teardown-class_method">
.<strong>teardown</strong> ⇒ <tt>Object</tt>
</h3><div class="docstring">
<div class="discussion">
<p>Cleans up all test double state (including any methods that were
redefined on partial doubles). This <em>must</em> be called after
each example, even if an error was raised during the example.</p>
</div>
</div>
<div class="tags">
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
51
52
53
54
55</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/rspec/mocks.rb', line 51</span>
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_teardown'>teardown</span>
<span class='id identifier rubyid_space'>space</span><span class='period'>.</span><span class='id identifier rubyid_reset_all'>reset_all</span>
<span class='ivar'>@space_stack</span><span class='period'>.</span><span class='id identifier rubyid_pop'>pop</span>
<span class='ivar'>@space</span> <span class='op'>=</span> <span class='ivar'>@space_stack</span><span class='period'>.</span><span class='id identifier rubyid_last'>last</span> <span class='op'>||</span> <span class='ivar'>@root_space</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="verify-class_method">
.<strong>verify</strong> ⇒ <tt>Object</tt>
</h3><div class="docstring">
<div class="discussion">
<p>Verifies any message expectations that were set during the
test or example. This should be called at the end of an example.</p>
</div>
</div>
<div class="tags">
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
44
45
46</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/rspec/mocks.rb', line 44</span>
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_verify'>verify</span>
<span class='id identifier rubyid_space'>space</span><span class='period'>.</span><span class='id identifier rubyid_verify_all'>verify_all</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="with_temporary_scope-class_method">
.<strong>with_temporary_scope</strong> ⇒ <tt>Object</tt>
</h3><div class="docstring">
<div class="discussion">
<p>Call the passed block and verify mocks after it has executed. This allows
mock usage in arbitrary places, such as a <code>before(:all)</code> hook.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>Object</tt>)</span>
—
<div class='inline'><p>the return value from the block</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
92
93
94
95
96
97
98
99
100
101
102</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/rspec/mocks.rb', line 92</span>
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_with_temporary_scope'>with_temporary_scope</span>
<span class='id identifier rubyid_setup'>setup</span>
<span class='kw'>begin</span>
<span class='id identifier rubyid_result'>result</span> <span class='op'>=</span> <span class='kw'>yield</span>
<span class='id identifier rubyid_verify'>verify</span>
<span class='id identifier rubyid_result'>result</span>
<span class='kw'>ensure</span>
<span class='id identifier rubyid_teardown'>teardown</span>
<span class='kw'>end</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
</div>
</div>
<div id="footer">
Generated on Wed Sep 4 15:23:12 2024 by
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.37 (ruby-3.2.2).
</div>
</div>
</body>
</html>