mocha 1.7.0 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +4 -9
  3. data/README.md +17 -16
  4. data/RELEASE.md +10 -0
  5. data/Rakefile +6 -13
  6. data/bin/build-matrix +16 -2
  7. data/docs/CNAME +1 -0
  8. data/docs/Mocha.html +127 -0
  9. data/docs/Mocha/API.html +1056 -0
  10. data/docs/Mocha/ClassMethods.html +267 -0
  11. data/docs/Mocha/Configuration.html +626 -0
  12. data/docs/Mocha/Expectation.html +2709 -0
  13. data/docs/Mocha/ExpectationError.html +157 -0
  14. data/docs/Mocha/ExpectationErrorFactory.html +269 -0
  15. data/docs/Mocha/Hooks.html +385 -0
  16. data/docs/Mocha/Integration.html +125 -0
  17. data/docs/Mocha/Integration/MiniTest.html +123 -0
  18. data/docs/Mocha/Integration/MiniTest/Adapter.html +165 -0
  19. data/docs/Mocha/Integration/TestUnit.html +123 -0
  20. data/docs/Mocha/Integration/TestUnit/Adapter.html +165 -0
  21. data/docs/Mocha/Mock.html +1197 -0
  22. data/docs/Mocha/ObjectMethods.html +712 -0
  23. data/docs/Mocha/ParameterMatchers.html +3049 -0
  24. data/docs/Mocha/ParameterMatchers/AllOf.html +154 -0
  25. data/docs/Mocha/ParameterMatchers/AnyOf.html +154 -0
  26. data/docs/Mocha/ParameterMatchers/AnyParameters.html +153 -0
  27. data/docs/Mocha/ParameterMatchers/Anything.html +153 -0
  28. data/docs/Mocha/ParameterMatchers/Base.html +448 -0
  29. data/docs/Mocha/ParameterMatchers/Equals.html +154 -0
  30. data/docs/Mocha/ParameterMatchers/EquivalentUri.html +153 -0
  31. data/docs/Mocha/ParameterMatchers/HasEntries.html +154 -0
  32. data/docs/Mocha/ParameterMatchers/HasEntry.html +154 -0
  33. data/docs/Mocha/ParameterMatchers/HasKey.html +154 -0
  34. data/docs/Mocha/ParameterMatchers/HasValue.html +154 -0
  35. data/docs/Mocha/ParameterMatchers/Includes.html +154 -0
  36. data/docs/Mocha/ParameterMatchers/InstanceOf.html +154 -0
  37. data/docs/Mocha/ParameterMatchers/IsA.html +153 -0
  38. data/docs/Mocha/ParameterMatchers/KindOf.html +154 -0
  39. data/docs/Mocha/ParameterMatchers/Not.html +154 -0
  40. data/docs/Mocha/ParameterMatchers/Optionally.html +153 -0
  41. data/docs/Mocha/ParameterMatchers/RegexpMatches.html +154 -0
  42. data/docs/Mocha/ParameterMatchers/RespondsWith.html +154 -0
  43. data/docs/Mocha/ParameterMatchers/YamlEquivalent.html +154 -0
  44. data/docs/Mocha/Sequence.html +149 -0
  45. data/docs/Mocha/StateMachine.html +539 -0
  46. data/docs/Mocha/StateMachine/State.html +141 -0
  47. data/docs/Mocha/StateMachine/StatePredicate.html +141 -0
  48. data/docs/Mocha/StubbingError.html +150 -0
  49. data/docs/Mocha/UnexpectedInvocation.html +140 -0
  50. data/docs/_index.html +537 -0
  51. data/docs/class_list.html +51 -0
  52. data/docs/css/common.css +1 -0
  53. data/docs/css/full_list.css +58 -0
  54. data/docs/css/style.css +496 -0
  55. data/docs/file.COPYING.html +81 -0
  56. data/docs/file.MIT-LICENSE.html +85 -0
  57. data/docs/file.README.html +418 -0
  58. data/docs/file.RELEASE.html +875 -0
  59. data/docs/file_list.html +71 -0
  60. data/docs/frames.html +17 -0
  61. data/docs/index.html +418 -0
  62. data/docs/js/app.js +292 -0
  63. data/docs/js/full_list.js +216 -0
  64. data/docs/js/jquery.js +4 -0
  65. data/docs/method_list.html +571 -0
  66. data/docs/top-level-namespace.html +118 -0
  67. data/lib/mocha/inspect.rb +1 -1
  68. data/lib/mocha/version.rb +1 -1
  69. data/mocha.gemspec +2 -3
  70. data/test/unit/object_inspect_test.rb +10 -0
  71. data/yard-templates/default/layout/html/google_analytics.erb +6 -9
  72. metadata +68 -36
@@ -0,0 +1,2709 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>
7
+ Class: Mocha::Expectation
8
+
9
+ &mdash; Mocha 1.8.0
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="../css/style.css" type="text/css" charset="utf-8" />
14
+
15
+ <link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8" />
16
+
17
+ <script type="text/javascript" charset="utf-8">
18
+ pathId = "Mocha::Expectation";
19
+ relpath = '../';
20
+ </script>
21
+
22
+
23
+ <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
24
+
25
+ <script type="text/javascript" charset="utf-8" src="../js/app.js"></script>
26
+
27
+
28
+ </head>
29
+ <body>
30
+ <div class="nav_wrap">
31
+ <iframe id="nav" src="../class_list.html?1"></iframe>
32
+ <div id="resizer"></div>
33
+ </div>
34
+
35
+ <div id="main" tabindex="-1">
36
+ <div id="header">
37
+ <div id="menu">
38
+
39
+ <a href="../_index.html">Index (E)</a> &raquo;
40
+ <span class='title'><span class='object_link'><a href="../Mocha.html" title="Mocha (module)">Mocha</a></span></span>
41
+ &raquo;
42
+ <span class="title">Expectation</span>
43
+
44
+ </div>
45
+
46
+ <div id="search">
47
+
48
+ <a class="full_list_link" id="class_list_link"
49
+ href="../class_list.html">
50
+
51
+ <svg width="24" height="24">
52
+ <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
53
+ <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
54
+ <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
55
+ </svg>
56
+ </a>
57
+
58
+ </div>
59
+ <div class="clear"></div>
60
+ </div>
61
+
62
+ <div id="content"><h1>Class: Mocha::Expectation
63
+
64
+
65
+
66
+ </h1>
67
+ <div class="box_info">
68
+
69
+ <dl>
70
+ <dt>Inherits:</dt>
71
+ <dd>
72
+ <span class="inheritName"><span class='object_link'>Object</span></span>
73
+
74
+ <ul class="fullTree">
75
+ <li><span class='object_link'>Object</span></li>
76
+
77
+ <li class="next">Mocha::Expectation</li>
78
+
79
+ </ul>
80
+ <a href="#" class="inheritanceTree">show all</a>
81
+
82
+ </dd>
83
+ </dl>
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+ <dl>
96
+ <dt>Defined in:</dt>
97
+ <dd>lib/mocha/expectation.rb</dd>
98
+ </dl>
99
+
100
+ </div>
101
+
102
+ <h2>Overview</h2><div class="docstring">
103
+ <div class="discussion">
104
+
105
+ <p>Methods on expectations returned from <span class='object_link'><a href="Mock.html#expects-instance_method" title="Mocha::Mock#expects (method)">Mock#expects</a></span>, <span class='object_link'><a href="Mock.html#stubs-instance_method" title="Mocha::Mock#stubs (method)">Mock#stubs</a></span>,
106
+ <span class='object_link'><a href="ObjectMethods.html#expects-instance_method" title="Mocha::ObjectMethods#expects (method)">ObjectMethods#expects</a></span> and <span class='object_link'><a href="ObjectMethods.html#stubs-instance_method" title="Mocha::ObjectMethods#stubs (method)">ObjectMethods#stubs</a></span>.</p>
107
+
108
+
109
+ </div>
110
+ </div>
111
+ <div class="tags">
112
+
113
+
114
+ </div>
115
+
116
+
117
+
118
+
119
+
120
+
121
+
122
+ <h2>
123
+ Instance Method Summary
124
+ <small><a href="#" class="summary_toggle">collapse</a></small>
125
+ </h2>
126
+
127
+ <ul class="summary">
128
+
129
+ <li class="public ">
130
+ <span class="summary_signature">
131
+
132
+ <a href="#at_least-instance_method" title="#at_least (instance method)">#<strong>at_least</strong>(minimum_number_of_times) &#x21d2; Expectation </a>
133
+
134
+
135
+
136
+ </span>
137
+
138
+
139
+
140
+
141
+
142
+
143
+
144
+
145
+
146
+ <span class="summary_desc"><div class='inline'>
147
+ <p>Modifies expectation so that the expected method must be called at least a
148
+ <code>minimum_number_of_times</code>.</p>
149
+ </div></span>
150
+
151
+ </li>
152
+
153
+
154
+ <li class="public ">
155
+ <span class="summary_signature">
156
+
157
+ <a href="#at_least_once-instance_method" title="#at_least_once (instance method)">#<strong>at_least_once</strong> &#x21d2; Expectation </a>
158
+
159
+
160
+
161
+ </span>
162
+
163
+
164
+
165
+
166
+
167
+
168
+
169
+
170
+
171
+ <span class="summary_desc"><div class='inline'>
172
+ <p>Modifies expectation so that the expected method must be called at least
173
+ once.</p>
174
+ </div></span>
175
+
176
+ </li>
177
+
178
+
179
+ <li class="public ">
180
+ <span class="summary_signature">
181
+
182
+ <a href="#at_most-instance_method" title="#at_most (instance method)">#<strong>at_most</strong>(maximum_number_of_times) &#x21d2; Expectation </a>
183
+
184
+
185
+
186
+ </span>
187
+
188
+
189
+
190
+
191
+
192
+
193
+
194
+
195
+
196
+ <span class="summary_desc"><div class='inline'>
197
+ <p>Modifies expectation so that the expected method must be called at most a
198
+ <code>maximum_number_of_times</code>.</p>
199
+ </div></span>
200
+
201
+ </li>
202
+
203
+
204
+ <li class="public ">
205
+ <span class="summary_signature">
206
+
207
+ <a href="#at_most_once-instance_method" title="#at_most_once (instance method)">#<strong>at_most_once</strong> &#x21d2; Expectation </a>
208
+
209
+
210
+
211
+ </span>
212
+
213
+
214
+
215
+
216
+
217
+
218
+
219
+
220
+
221
+ <span class="summary_desc"><div class='inline'>
222
+ <p>Modifies expectation so that the expected method must be called at most
223
+ once.</p>
224
+ </div></span>
225
+
226
+ </li>
227
+
228
+
229
+ <li class="public ">
230
+ <span class="summary_signature">
231
+
232
+ <a href="#in_sequence-instance_method" title="#in_sequence (instance method)">#<strong>in_sequence</strong>(*sequences) &#x21d2; Expectation </a>
233
+
234
+
235
+
236
+ </span>
237
+
238
+
239
+
240
+
241
+
242
+
243
+
244
+
245
+
246
+ <span class="summary_desc"><div class='inline'>
247
+ <p>Constrains the expectation so that it must be invoked at the current point
248
+ in the <code>sequence</code>.</p>
249
+ </div></span>
250
+
251
+ </li>
252
+
253
+
254
+ <li class="public ">
255
+ <span class="summary_signature">
256
+
257
+ <a href="#multiple_yields-instance_method" title="#multiple_yields (instance method)">#<strong>multiple_yields</strong>(*parameter_groups) &#x21d2; Expectation </a>
258
+
259
+
260
+
261
+ </span>
262
+
263
+
264
+
265
+
266
+
267
+
268
+
269
+
270
+
271
+ <span class="summary_desc"><div class='inline'>
272
+ <p>Modifies expectation so that when the expected method is called, it yields
273
+ multiple times per invocation with the specified
274
+ <code>parameter_groups</code>.</p>
275
+ </div></span>
276
+
277
+ </li>
278
+
279
+
280
+ <li class="public ">
281
+ <span class="summary_signature">
282
+
283
+ <a href="#never-instance_method" title="#never (instance method)">#<strong>never</strong> &#x21d2; Expectation </a>
284
+
285
+
286
+
287
+ </span>
288
+
289
+
290
+
291
+
292
+
293
+
294
+
295
+
296
+
297
+ <span class="summary_desc"><div class='inline'>
298
+ <p>Modifies expectation so that the expected method must never be called.</p>
299
+ </div></span>
300
+
301
+ </li>
302
+
303
+
304
+ <li class="public ">
305
+ <span class="summary_signature">
306
+
307
+ <a href="#once-instance_method" title="#once (instance method)">#<strong>once</strong> &#x21d2; Expectation </a>
308
+
309
+
310
+
311
+ </span>
312
+
313
+
314
+
315
+
316
+
317
+
318
+
319
+
320
+
321
+ <span class="summary_desc"><div class='inline'>
322
+ <p>Modifies expectation so that the expected method must be called exactly
323
+ once.</p>
324
+ </div></span>
325
+
326
+ </li>
327
+
328
+
329
+ <li class="public ">
330
+ <span class="summary_signature">
331
+
332
+ <a href="#raises-instance_method" title="#raises (instance method)">#<strong>raises</strong>(exception = RuntimeError, message = nil) &#x21d2; Expectation </a>
333
+
334
+
335
+
336
+ </span>
337
+
338
+
339
+
340
+
341
+
342
+
343
+
344
+
345
+
346
+ <span class="summary_desc"><div class='inline'>
347
+ <p>Modifies expectation so that when the expected method is called, it raises
348
+ the specified <code>exception</code> with the specified
349
+ <code>message</code> i.e.</p>
350
+ </div></span>
351
+
352
+ </li>
353
+
354
+
355
+ <li class="public ">
356
+ <span class="summary_signature">
357
+
358
+ <a href="#returns-instance_method" title="#returns (instance method)">#<strong>returns</strong>(*values) &#x21d2; Expectation </a>
359
+
360
+
361
+
362
+ </span>
363
+
364
+
365
+
366
+
367
+
368
+
369
+
370
+
371
+
372
+ <span class="summary_desc"><div class='inline'>
373
+ <p>Modifies expectation so that when the expected method is called, it returns
374
+ the specified <code>value</code>.</p>
375
+ </div></span>
376
+
377
+ </li>
378
+
379
+
380
+ <li class="public ">
381
+ <span class="summary_signature">
382
+
383
+ <a href="#then-instance_method" title="#then (instance method)">#<strong>then</strong>(*parameters) &#x21d2; Expectation </a>
384
+
385
+
386
+
387
+ </span>
388
+
389
+
390
+
391
+
392
+
393
+
394
+
395
+
396
+
397
+ <span class="summary_desc"><div class='inline'>
398
+ <p>The same expectation, thereby allowing invocations of other <span class='object_link'><a href="" title="Mocha::Expectation (class)">Expectation</a></span>
399
+ methods to be chained.</p>
400
+ </div></span>
401
+
402
+ </li>
403
+
404
+
405
+ <li class="public ">
406
+ <span class="summary_signature">
407
+
408
+ <a href="#throws-instance_method" title="#throws (instance method)">#<strong>throws</strong>(tag, object = nil) &#x21d2; Expectation </a>
409
+
410
+
411
+
412
+ </span>
413
+
414
+
415
+
416
+
417
+
418
+
419
+
420
+
421
+
422
+ <span class="summary_desc"><div class='inline'>
423
+ <p>Modifies expectation so that when the expected method is called, it throws
424
+ the specified <code>tag</code> with the specific return value
425
+ <code>object</code> i.e.</p>
426
+ </div></span>
427
+
428
+ </li>
429
+
430
+
431
+ <li class="public ">
432
+ <span class="summary_signature">
433
+
434
+ <a href="#times-instance_method" title="#times (instance method)">#<strong>times</strong>(range) &#x21d2; Expectation </a>
435
+
436
+
437
+
438
+ </span>
439
+
440
+
441
+
442
+
443
+
444
+
445
+
446
+
447
+
448
+ <span class="summary_desc"><div class='inline'>
449
+ <p>Modifies expectation so that the number of calls to the expected method
450
+ must be within a specific <code>range</code>.</p>
451
+ </div></span>
452
+
453
+ </li>
454
+
455
+
456
+ <li class="public ">
457
+ <span class="summary_signature">
458
+
459
+ <a href="#twice-instance_method" title="#twice (instance method)">#<strong>twice</strong> &#x21d2; Expectation </a>
460
+
461
+
462
+
463
+ </span>
464
+
465
+
466
+
467
+
468
+
469
+
470
+
471
+
472
+
473
+ <span class="summary_desc"><div class='inline'>
474
+ <p>Modifies expectation so that the expected method must be called exactly
475
+ twice.</p>
476
+ </div></span>
477
+
478
+ </li>
479
+
480
+
481
+ <li class="public ">
482
+ <span class="summary_signature">
483
+
484
+ <a href="#when-instance_method" title="#when (instance method)">#<strong>when</strong>(state_predicate) &#x21d2; Expectation </a>
485
+
486
+
487
+
488
+ </span>
489
+
490
+
491
+
492
+
493
+
494
+
495
+
496
+
497
+
498
+ <span class="summary_desc"><div class='inline'>
499
+ <p>Constrains the expectation to occur only when the
500
+ <code>state_machine</code> is in the state specified by
501
+ <code>state_name</code>.</p>
502
+ </div></span>
503
+
504
+ </li>
505
+
506
+
507
+ <li class="public ">
508
+ <span class="summary_signature">
509
+
510
+ <a href="#with-instance_method" title="#with (instance method)">#<strong>with</strong>(*expected_parameters) {|actual_parameters| ... } &#x21d2; Expectation </a>
511
+
512
+
513
+
514
+ </span>
515
+
516
+
517
+
518
+
519
+
520
+
521
+
522
+
523
+
524
+ <span class="summary_desc"><div class='inline'>
525
+ <p>Modifies expectation so that the expected method must be called with
526
+ <code>expected_parameters</code>.</p>
527
+ </div></span>
528
+
529
+ </li>
530
+
531
+
532
+ <li class="public ">
533
+ <span class="summary_signature">
534
+
535
+ <a href="#yields-instance_method" title="#yields (instance method)">#<strong>yields</strong>(*parameters) &#x21d2; Expectation </a>
536
+
537
+
538
+
539
+ </span>
540
+
541
+
542
+
543
+
544
+
545
+
546
+
547
+
548
+
549
+ <span class="summary_desc"><div class='inline'>
550
+ <p>Modifies expectation so that when the expected method is called, it yields
551
+ with the specified <code>parameters</code>.</p>
552
+ </div></span>
553
+
554
+ </li>
555
+
556
+
557
+ </ul>
558
+
559
+
560
+
561
+
562
+ <div id="instance_method_details" class="method_details_list">
563
+ <h2>Instance Method Details</h2>
564
+
565
+
566
+ <div class="method_details first">
567
+ <h3 class="signature first" id="at_least-instance_method">
568
+
569
+ #<strong>at_least</strong>(minimum_number_of_times) &#x21d2; <tt><span class='object_link'><a href="" title="Mocha::Expectation (class)">Expectation</a></span></tt>
570
+
571
+
572
+
573
+
574
+
575
+ </h3><div class="docstring">
576
+ <div class="discussion">
577
+
578
+ <p>Modifies expectation so that the expected method must be called at least a
579
+ <code>minimum_number_of_times</code>.</p>
580
+
581
+
582
+ </div>
583
+ </div>
584
+ <div class="tags">
585
+
586
+ <div class="examples">
587
+ <p class="tag_title">Examples:</p>
588
+
589
+
590
+ <p class="example_title"><div class='inline'>
591
+ <p>Expected method must be called at least twice.</p>
592
+ </div></p>
593
+
594
+ <pre class="example code"><code><span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='rparen'>)</span>
595
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:expected_method</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_at_least'>at_least</span><span class='lparen'>(</span><span class='int'>2</span><span class='rparen'>)</span>
596
+ <span class='int'>3</span><span class='period'>.</span><span class='id identifier rubyid_times'>times</span> <span class='lbrace'>{</span> <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span> <span class='rbrace'>}</span>
597
+ <span class='comment'># =&gt; verify succeeds
598
+ </span>
599
+ <span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='rparen'>)</span>
600
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:expected_method</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_at_least'>at_least</span><span class='lparen'>(</span><span class='int'>2</span><span class='rparen'>)</span>
601
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span>
602
+ <span class='comment'># =&gt; verify fails</span></code></pre>
603
+
604
+ </div>
605
+ <p class="tag_title">Parameters:</p>
606
+ <ul class="param">
607
+
608
+ <li>
609
+
610
+ <span class='name'>minimum_number_of_times</span>
611
+
612
+
613
+ <span class='type'>(<tt>Integer</tt>)</span>
614
+
615
+
616
+
617
+ &mdash;
618
+ <div class='inline'>
619
+ <p>minimum number of expected invocations.</p>
620
+ </div>
621
+
622
+ </li>
623
+
624
+ </ul>
625
+
626
+ <p class="tag_title">Returns:</p>
627
+ <ul class="return">
628
+
629
+ <li>
630
+
631
+
632
+ <span class='type'>(<tt><span class='object_link'><a href="" title="Mocha::Expectation (class)">Expectation</a></span></tt>)</span>
633
+
634
+
635
+
636
+ &mdash;
637
+ <div class='inline'>
638
+ <p>the same expectation, thereby allowing invocations of other <span class='object_link'><a href="" title="Mocha::Expectation (class)">Mocha::Expectation</a></span>
639
+ methods to be chained.</p>
640
+ </div>
641
+
642
+ </li>
643
+
644
+ </ul>
645
+
646
+ </div><table class="source_code">
647
+ <tr>
648
+ <td>
649
+ <pre class="lines">
650
+
651
+
652
+ 130
653
+ 131
654
+ 132
655
+ 133</pre>
656
+ </td>
657
+ <td>
658
+ <pre class="code"><span class="info file"># File 'lib/mocha/expectation.rb', line 130</span>
659
+
660
+ <span class='kw'>def</span> <span class='id identifier rubyid_at_least'>at_least</span><span class='lparen'>(</span><span class='id identifier rubyid_minimum_number_of_times'>minimum_number_of_times</span><span class='rparen'>)</span>
661
+ <span class='ivar'>@cardinality</span> <span class='op'>=</span> <span class='const'>Cardinality</span><span class='period'>.</span><span class='id identifier rubyid_at_least'>at_least</span><span class='lparen'>(</span><span class='id identifier rubyid_minimum_number_of_times'>minimum_number_of_times</span><span class='rparen'>)</span>
662
+ <span class='kw'>self</span>
663
+ <span class='kw'>end</span></pre>
664
+ </td>
665
+ </tr>
666
+ </table>
667
+ </div>
668
+
669
+ <div class="method_details ">
670
+ <h3 class="signature " id="at_least_once-instance_method">
671
+
672
+ #<strong>at_least_once</strong> &#x21d2; <tt><span class='object_link'><a href="" title="Mocha::Expectation (class)">Expectation</a></span></tt>
673
+
674
+
675
+
676
+
677
+
678
+ </h3><div class="docstring">
679
+ <div class="discussion">
680
+
681
+ <p>Modifies expectation so that the expected method must be called at least
682
+ once.</p>
683
+
684
+
685
+ </div>
686
+ </div>
687
+ <div class="tags">
688
+
689
+ <div class="examples">
690
+ <p class="tag_title">Examples:</p>
691
+
692
+
693
+ <p class="example_title"><div class='inline'>
694
+ <p>Expected method must be called at least once.</p>
695
+ </div></p>
696
+
697
+ <pre class="example code"><code><span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='rparen'>)</span>
698
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:expected_method</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_at_least_once'>at_least_once</span>
699
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span>
700
+ <span class='comment'># =&gt; verify succeeds
701
+ </span>
702
+ <span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='rparen'>)</span>
703
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:expected_method</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_at_least_once'>at_least_once</span>
704
+ <span class='comment'># =&gt; verify fails</span></code></pre>
705
+
706
+ </div>
707
+
708
+ <p class="tag_title">Returns:</p>
709
+ <ul class="return">
710
+
711
+ <li>
712
+
713
+
714
+ <span class='type'>(<tt><span class='object_link'><a href="" title="Mocha::Expectation (class)">Expectation</a></span></tt>)</span>
715
+
716
+
717
+
718
+ &mdash;
719
+ <div class='inline'>
720
+ <p>the same expectation, thereby allowing invocations of other <span class='object_link'><a href="" title="Mocha::Expectation (class)">Mocha::Expectation</a></span>
721
+ methods to be chained.</p>
722
+ </div>
723
+
724
+ </li>
725
+
726
+ </ul>
727
+
728
+ </div><table class="source_code">
729
+ <tr>
730
+ <td>
731
+ <pre class="lines">
732
+
733
+
734
+ 148
735
+ 149
736
+ 150
737
+ 151</pre>
738
+ </td>
739
+ <td>
740
+ <pre class="code"><span class="info file"># File 'lib/mocha/expectation.rb', line 148</span>
741
+
742
+ <span class='kw'>def</span> <span class='id identifier rubyid_at_least_once'>at_least_once</span>
743
+ <span class='id identifier rubyid_at_least'>at_least</span><span class='lparen'>(</span><span class='int'>1</span><span class='rparen'>)</span>
744
+ <span class='kw'>self</span>
745
+ <span class='kw'>end</span></pre>
746
+ </td>
747
+ </tr>
748
+ </table>
749
+ </div>
750
+
751
+ <div class="method_details ">
752
+ <h3 class="signature " id="at_most-instance_method">
753
+
754
+ #<strong>at_most</strong>(maximum_number_of_times) &#x21d2; <tt><span class='object_link'><a href="" title="Mocha::Expectation (class)">Expectation</a></span></tt>
755
+
756
+
757
+
758
+
759
+
760
+ </h3><div class="docstring">
761
+ <div class="discussion">
762
+
763
+ <p>Modifies expectation so that the expected method must be called at most a
764
+ <code>maximum_number_of_times</code>.</p>
765
+
766
+
767
+ </div>
768
+ </div>
769
+ <div class="tags">
770
+
771
+ <div class="examples">
772
+ <p class="tag_title">Examples:</p>
773
+
774
+
775
+ <p class="example_title"><div class='inline'>
776
+ <p>Expected method must be called at most twice.</p>
777
+ </div></p>
778
+
779
+ <pre class="example code"><code><span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='rparen'>)</span>
780
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:expected_method</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_at_most'>at_most</span><span class='lparen'>(</span><span class='int'>2</span><span class='rparen'>)</span>
781
+ <span class='int'>2</span><span class='period'>.</span><span class='id identifier rubyid_times'>times</span> <span class='lbrace'>{</span> <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span> <span class='rbrace'>}</span>
782
+ <span class='comment'># =&gt; verify succeeds
783
+ </span>
784
+ <span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='rparen'>)</span>
785
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:expected_method</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_at_most'>at_most</span><span class='lparen'>(</span><span class='int'>2</span><span class='rparen'>)</span>
786
+ <span class='int'>3</span><span class='period'>.</span><span class='id identifier rubyid_times'>times</span> <span class='lbrace'>{</span> <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span> <span class='rbrace'>}</span> <span class='comment'># =&gt; unexpected invocation</span></code></pre>
787
+
788
+ </div>
789
+ <p class="tag_title">Parameters:</p>
790
+ <ul class="param">
791
+
792
+ <li>
793
+
794
+ <span class='name'>maximum_number_of_times</span>
795
+
796
+
797
+ <span class='type'>(<tt>Integer</tt>)</span>
798
+
799
+
800
+
801
+ &mdash;
802
+ <div class='inline'>
803
+ <p>maximum number of expected invocations.</p>
804
+ </div>
805
+
806
+ </li>
807
+
808
+ </ul>
809
+
810
+ <p class="tag_title">Returns:</p>
811
+ <ul class="return">
812
+
813
+ <li>
814
+
815
+
816
+ <span class='type'>(<tt><span class='object_link'><a href="" title="Mocha::Expectation (class)">Expectation</a></span></tt>)</span>
817
+
818
+
819
+
820
+ &mdash;
821
+ <div class='inline'>
822
+ <p>the same expectation, thereby allowing invocations of other <span class='object_link'><a href="" title="Mocha::Expectation (class)">Mocha::Expectation</a></span>
823
+ methods to be chained.</p>
824
+ </div>
825
+
826
+ </li>
827
+
828
+ </ul>
829
+
830
+ </div><table class="source_code">
831
+ <tr>
832
+ <td>
833
+ <pre class="lines">
834
+
835
+
836
+ 167
837
+ 168
838
+ 169
839
+ 170</pre>
840
+ </td>
841
+ <td>
842
+ <pre class="code"><span class="info file"># File 'lib/mocha/expectation.rb', line 167</span>
843
+
844
+ <span class='kw'>def</span> <span class='id identifier rubyid_at_most'>at_most</span><span class='lparen'>(</span><span class='id identifier rubyid_maximum_number_of_times'>maximum_number_of_times</span><span class='rparen'>)</span>
845
+ <span class='ivar'>@cardinality</span> <span class='op'>=</span> <span class='const'>Cardinality</span><span class='period'>.</span><span class='id identifier rubyid_at_most'>at_most</span><span class='lparen'>(</span><span class='id identifier rubyid_maximum_number_of_times'>maximum_number_of_times</span><span class='rparen'>)</span>
846
+ <span class='kw'>self</span>
847
+ <span class='kw'>end</span></pre>
848
+ </td>
849
+ </tr>
850
+ </table>
851
+ </div>
852
+
853
+ <div class="method_details ">
854
+ <h3 class="signature " id="at_most_once-instance_method">
855
+
856
+ #<strong>at_most_once</strong> &#x21d2; <tt><span class='object_link'><a href="" title="Mocha::Expectation (class)">Expectation</a></span></tt>
857
+
858
+
859
+
860
+
861
+
862
+ </h3><div class="docstring">
863
+ <div class="discussion">
864
+
865
+ <p>Modifies expectation so that the expected method must be called at most
866
+ once.</p>
867
+
868
+
869
+ </div>
870
+ </div>
871
+ <div class="tags">
872
+
873
+ <div class="examples">
874
+ <p class="tag_title">Examples:</p>
875
+
876
+
877
+ <p class="example_title"><div class='inline'>
878
+ <p>Expected method must be called at most once.</p>
879
+ </div></p>
880
+
881
+ <pre class="example code"><code><span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='rparen'>)</span>
882
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:expected_method</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_at_most_once'>at_most_once</span>
883
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span>
884
+ <span class='comment'># =&gt; verify succeeds
885
+ </span>
886
+ <span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='rparen'>)</span>
887
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:expected_method</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_at_most_once'>at_most_once</span>
888
+ <span class='int'>2</span><span class='period'>.</span><span class='id identifier rubyid_times'>times</span> <span class='lbrace'>{</span> <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span> <span class='rbrace'>}</span> <span class='comment'># =&gt; unexpected invocation</span></code></pre>
889
+
890
+ </div>
891
+
892
+ <p class="tag_title">Returns:</p>
893
+ <ul class="return">
894
+
895
+ <li>
896
+
897
+
898
+ <span class='type'>(<tt><span class='object_link'><a href="" title="Mocha::Expectation (class)">Expectation</a></span></tt>)</span>
899
+
900
+
901
+
902
+ &mdash;
903
+ <div class='inline'>
904
+ <p>the same expectation, thereby allowing invocations of other <span class='object_link'><a href="" title="Mocha::Expectation (class)">Mocha::Expectation</a></span>
905
+ methods to be chained.</p>
906
+ </div>
907
+
908
+ </li>
909
+
910
+ </ul>
911
+
912
+ </div><table class="source_code">
913
+ <tr>
914
+ <td>
915
+ <pre class="lines">
916
+
917
+
918
+ 185
919
+ 186
920
+ 187
921
+ 188</pre>
922
+ </td>
923
+ <td>
924
+ <pre class="code"><span class="info file"># File 'lib/mocha/expectation.rb', line 185</span>
925
+
926
+ <span class='kw'>def</span> <span class='id identifier rubyid_at_most_once'>at_most_once</span>
927
+ <span class='id identifier rubyid_at_most'>at_most</span><span class='lparen'>(</span><span class='int'>1</span><span class='rparen'>)</span>
928
+ <span class='kw'>self</span>
929
+ <span class='kw'>end</span></pre>
930
+ </td>
931
+ </tr>
932
+ </table>
933
+ </div>
934
+
935
+ <div class="method_details ">
936
+ <h3 class="signature " id="in_sequence-instance_method">
937
+
938
+ #<strong>in_sequence</strong>(*sequences) &#x21d2; <tt><span class='object_link'><a href="" title="Mocha::Expectation (class)">Expectation</a></span></tt>
939
+
940
+
941
+
942
+
943
+
944
+ </h3><div class="docstring">
945
+ <div class="discussion">
946
+
947
+ <p>Constrains the expectation so that it must be invoked at the current point
948
+ in the <code>sequence</code>.</p>
949
+
950
+ <p>To expect a sequence of invocations, write the expectations in order and
951
+ add the <tt>in_sequence(sequence)</tt> clause to each one.</p>
952
+
953
+ <p>Expectations in a <code>sequence</code> can have any invocation count.</p>
954
+
955
+ <p>If an expectation in a sequence is stubbed, rather than expected, it can be
956
+ skipped in the <code>sequence</code>.</p>
957
+
958
+ <p>An expected method can appear in multiple sequences.</p>
959
+
960
+
961
+ </div>
962
+ </div>
963
+ <div class="tags">
964
+
965
+ <div class="examples">
966
+ <p class="tag_title">Examples:</p>
967
+
968
+
969
+ <p class="example_title"><div class='inline'>
970
+ <p>Ensure methods are invoked in a specified order.</p>
971
+ </div></p>
972
+
973
+ <pre class="example code"><code><span class='id identifier rubyid_breakfast'>breakfast</span> <span class='op'>=</span> <span class='id identifier rubyid_sequence'>sequence</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>breakfast</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>
974
+
975
+ <span class='id identifier rubyid_egg'>egg</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>egg</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>
976
+ <span class='id identifier rubyid_egg'>egg</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:crack</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_in_sequence'>in_sequence</span><span class='lparen'>(</span><span class='id identifier rubyid_breakfast'>breakfast</span><span class='rparen'>)</span>
977
+ <span class='id identifier rubyid_egg'>egg</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:fry</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_in_sequence'>in_sequence</span><span class='lparen'>(</span><span class='id identifier rubyid_breakfast'>breakfast</span><span class='rparen'>)</span>
978
+ <span class='id identifier rubyid_egg'>egg</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:eat</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_in_sequence'>in_sequence</span><span class='lparen'>(</span><span class='id identifier rubyid_breakfast'>breakfast</span><span class='rparen'>)</span></code></pre>
979
+
980
+ </div>
981
+ <p class="tag_title">Parameters:</p>
982
+ <ul class="param">
983
+
984
+ <li>
985
+
986
+ <span class='name'>sequences</span>
987
+
988
+
989
+ <span class='type'>(<tt>*Array&lt;<span class='object_link'><a href="Sequence.html" title="Mocha::Sequence (class)">Sequence</a></span>&gt;</tt>)</span>
990
+
991
+
992
+
993
+ &mdash;
994
+ <div class='inline'>
995
+ <p>sequences in which expected method should appear.</p>
996
+ </div>
997
+
998
+ </li>
999
+
1000
+ </ul>
1001
+
1002
+ <p class="tag_title">Returns:</p>
1003
+ <ul class="return">
1004
+
1005
+ <li>
1006
+
1007
+
1008
+ <span class='type'>(<tt><span class='object_link'><a href="" title="Mocha::Expectation (class)">Expectation</a></span></tt>)</span>
1009
+
1010
+
1011
+
1012
+ &mdash;
1013
+ <div class='inline'>
1014
+ <p>the same expectation, thereby allowing invocations of other <span class='object_link'><a href="" title="Mocha::Expectation (class)">Mocha::Expectation</a></span>
1015
+ methods to be chained.</p>
1016
+ </div>
1017
+
1018
+ </li>
1019
+
1020
+ </ul>
1021
+
1022
+ <p class="tag_title">See Also:</p>
1023
+ <ul class="see">
1024
+
1025
+ <li><span class='object_link'><a href="API.html#sequence-instance_method" title="Mocha::API#sequence (method)">API#sequence</a></span></li>
1026
+
1027
+ </ul>
1028
+
1029
+ </div><table class="source_code">
1030
+ <tr>
1031
+ <td>
1032
+ <pre class="lines">
1033
+
1034
+
1035
+ 492
1036
+ 493
1037
+ 494
1038
+ 495</pre>
1039
+ </td>
1040
+ <td>
1041
+ <pre class="code"><span class="info file"># File 'lib/mocha/expectation.rb', line 492</span>
1042
+
1043
+ <span class='kw'>def</span> <span class='id identifier rubyid_in_sequence'>in_sequence</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_sequences'>sequences</span><span class='rparen'>)</span>
1044
+ <span class='id identifier rubyid_sequences'>sequences</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_sequence'>sequence</span><span class='op'>|</span> <span class='id identifier rubyid_add_in_sequence_ordering_constraint'>add_in_sequence_ordering_constraint</span><span class='lparen'>(</span><span class='id identifier rubyid_sequence'>sequence</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
1045
+ <span class='kw'>self</span>
1046
+ <span class='kw'>end</span></pre>
1047
+ </td>
1048
+ </tr>
1049
+ </table>
1050
+ </div>
1051
+
1052
+ <div class="method_details ">
1053
+ <h3 class="signature " id="multiple_yields-instance_method">
1054
+
1055
+ #<strong>multiple_yields</strong>(*parameter_groups) &#x21d2; <tt><span class='object_link'><a href="" title="Mocha::Expectation (class)">Expectation</a></span></tt>
1056
+
1057
+
1058
+
1059
+
1060
+
1061
+ </h3><div class="docstring">
1062
+ <div class="discussion">
1063
+
1064
+ <p>Modifies expectation so that when the expected method is called, it yields
1065
+ multiple times per invocation with the specified
1066
+ <code>parameter_groups</code>.</p>
1067
+
1068
+
1069
+ </div>
1070
+ </div>
1071
+ <div class="tags">
1072
+
1073
+ <div class="examples">
1074
+ <p class="tag_title">Examples:</p>
1075
+
1076
+
1077
+ <p class="example_title"><div class='inline'>
1078
+ <p>When the <code>expected_method</code> is called, the stub will invoke the
1079
+ block twice, the first time it passes <tt>&#39;result_1&#39;</tt>,
1080
+ <tt>&#39;result_2&#39;</tt> as the parameters, and the second time it passes
1081
+ &#39;result_3&#39; as the parameters.</p>
1082
+ </div></p>
1083
+
1084
+ <pre class="example code"><code><span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='rparen'>)</span>
1085
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:expected_method</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_multiple_yields'>multiple_yields</span><span class='lparen'>(</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>result_1</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>result_2</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>result_3</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span><span class='rparen'>)</span>
1086
+ <span class='id identifier rubyid_yielded_values'>yielded_values</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
1087
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='op'>*</span><span class='id identifier rubyid_values'>values</span><span class='op'>|</span> <span class='id identifier rubyid_yielded_values'>yielded_values</span> <span class='op'>&lt;&lt;</span> <span class='id identifier rubyid_values'>values</span> <span class='rbrace'>}</span>
1088
+ <span class='id identifier rubyid_yielded_values'>yielded_values</span> <span class='comment'># =&gt; [[&#39;result_1&#39;, &#39;result_2&#39;], [&#39;result_3]]</span></code></pre>
1089
+
1090
+
1091
+ <p class="example_title"><div class='inline'>
1092
+ <p>Yield different groups of parameters on different invocations of the
1093
+ expected method.</p>
1094
+ </div></p>
1095
+
1096
+ <pre class="example code"><code><span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='rparen'>)</span>
1097
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='symbol'>:expected_method</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_multiple_yields'>multiple_yields</span><span class='lparen'>(</span><span class='lbracket'>[</span><span class='int'>1</span><span class='comma'>,</span> <span class='int'>2</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='lbracket'>[</span><span class='int'>3</span><span class='rbracket'>]</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_then'>then</span><span class='period'>.</span><span class='id identifier rubyid_multiple_yields'>multiple_yields</span><span class='lparen'>(</span><span class='lbracket'>[</span><span class='int'>4</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='lbracket'>[</span><span class='int'>5</span><span class='comma'>,</span> <span class='int'>6</span><span class='rbracket'>]</span><span class='rparen'>)</span>
1098
+ <span class='id identifier rubyid_yielded_values_from_first_invocation'>yielded_values_from_first_invocation</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
1099
+ <span class='id identifier rubyid_yielded_values_from_second_invocation'>yielded_values_from_second_invocation</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
1100
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='op'>*</span><span class='id identifier rubyid_values'>values</span><span class='op'>|</span> <span class='id identifier rubyid_yielded_values_from_first_invocation'>yielded_values_from_first_invocation</span> <span class='op'>&lt;&lt;</span> <span class='id identifier rubyid_values'>values</span> <span class='rbrace'>}</span> <span class='comment'># first invocation
1101
+ </span><span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='op'>*</span><span class='id identifier rubyid_values'>values</span><span class='op'>|</span> <span class='id identifier rubyid_yielded_values_from_second_invocation'>yielded_values_from_second_invocation</span> <span class='op'>&lt;&lt;</span> <span class='id identifier rubyid_values'>values</span> <span class='rbrace'>}</span> <span class='comment'># second invocation
1102
+ </span><span class='id identifier rubyid_yielded_values_from_first_invocation'>yielded_values_from_first_invocation</span> <span class='comment'># =&gt; [[1, 2], [3]]
1103
+ </span><span class='id identifier rubyid_yielded_values_from_second_invocation'>yielded_values_from_second_invocation</span> <span class='comment'># =&gt; [[4], [5, 6]]</span></code></pre>
1104
+
1105
+ </div>
1106
+ <p class="tag_title">Parameters:</p>
1107
+ <ul class="param">
1108
+
1109
+ <li>
1110
+
1111
+ <span class='name'>parameter_groups</span>
1112
+
1113
+
1114
+ <span class='type'>(<tt>*Array&lt;Array&gt;</tt>)</span>
1115
+
1116
+
1117
+
1118
+ &mdash;
1119
+ <div class='inline'>
1120
+ <p>each element of <code>parameter_groups</code> should iself be an
1121
+ <code>Array</code> representing the parameters to be passed to the block
1122
+ for a single yield.</p>
1123
+ </div>
1124
+
1125
+ </li>
1126
+
1127
+ </ul>
1128
+
1129
+ <p class="tag_title">Returns:</p>
1130
+ <ul class="return">
1131
+
1132
+ <li>
1133
+
1134
+
1135
+ <span class='type'>(<tt><span class='object_link'><a href="" title="Mocha::Expectation (class)">Expectation</a></span></tt>)</span>
1136
+
1137
+
1138
+
1139
+ &mdash;
1140
+ <div class='inline'>
1141
+ <p>the same expectation, thereby allowing invocations of other <span class='object_link'><a href="" title="Mocha::Expectation (class)">Mocha::Expectation</a></span>
1142
+ methods to be chained.</p>
1143
+ </div>
1144
+
1145
+ </li>
1146
+
1147
+ </ul>
1148
+
1149
+ <p class="tag_title">See Also:</p>
1150
+ <ul class="see">
1151
+
1152
+ <li><span class='object_link'><a href="#then-instance_method" title="Mocha::Expectation#then (method)">#then</a></span></li>
1153
+
1154
+ </ul>
1155
+
1156
+ </div><table class="source_code">
1157
+ <tr>
1158
+ <td>
1159
+ <pre class="lines">
1160
+
1161
+
1162
+ 277
1163
+ 278
1164
+ 279
1165
+ 280</pre>
1166
+ </td>
1167
+ <td>
1168
+ <pre class="code"><span class="info file"># File 'lib/mocha/expectation.rb', line 277</span>
1169
+
1170
+ <span class='kw'>def</span> <span class='id identifier rubyid_multiple_yields'>multiple_yields</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_parameter_groups'>parameter_groups</span><span class='rparen'>)</span>
1171
+ <span class='ivar'>@yield_parameters</span><span class='period'>.</span><span class='id identifier rubyid_multiple_add'>multiple_add</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_parameter_groups'>parameter_groups</span><span class='rparen'>)</span>
1172
+ <span class='kw'>self</span>
1173
+ <span class='kw'>end</span></pre>
1174
+ </td>
1175
+ </tr>
1176
+ </table>
1177
+ </div>
1178
+
1179
+ <div class="method_details ">
1180
+ <h3 class="signature " id="never-instance_method">
1181
+
1182
+ #<strong>never</strong> &#x21d2; <tt><span class='object_link'><a href="" title="Mocha::Expectation (class)">Expectation</a></span></tt>
1183
+
1184
+
1185
+
1186
+
1187
+
1188
+ </h3><div class="docstring">
1189
+ <div class="discussion">
1190
+
1191
+ <p>Modifies expectation so that the expected method must never be called.</p>
1192
+
1193
+
1194
+ </div>
1195
+ </div>
1196
+ <div class="tags">
1197
+
1198
+ <div class="examples">
1199
+ <p class="tag_title">Examples:</p>
1200
+
1201
+
1202
+ <p class="example_title"><div class='inline'>
1203
+ <p>Expected method must never be called.</p>
1204
+ </div></p>
1205
+
1206
+ <pre class="example code"><code><span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='rparen'>)</span>
1207
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:expected_method</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_never'>never</span>
1208
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span> <span class='comment'># =&gt; unexpected invocation
1209
+ </span>
1210
+ <span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='rparen'>)</span>
1211
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:expected_method</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_never'>never</span>
1212
+ <span class='comment'># =&gt; verify succeeds</span></code></pre>
1213
+
1214
+ </div>
1215
+
1216
+ <p class="tag_title">Returns:</p>
1217
+ <ul class="return">
1218
+
1219
+ <li>
1220
+
1221
+
1222
+ <span class='type'>(<tt><span class='object_link'><a href="" title="Mocha::Expectation (class)">Expectation</a></span></tt>)</span>
1223
+
1224
+
1225
+
1226
+ &mdash;
1227
+ <div class='inline'>
1228
+ <p>the same expectation, thereby allowing invocations of other <span class='object_link'><a href="" title="Mocha::Expectation (class)">Mocha::Expectation</a></span>
1229
+ methods to be chained.</p>
1230
+ </div>
1231
+
1232
+ </li>
1233
+
1234
+ </ul>
1235
+
1236
+ </div><table class="source_code">
1237
+ <tr>
1238
+ <td>
1239
+ <pre class="lines">
1240
+
1241
+
1242
+ 110
1243
+ 111
1244
+ 112
1245
+ 113</pre>
1246
+ </td>
1247
+ <td>
1248
+ <pre class="code"><span class="info file"># File 'lib/mocha/expectation.rb', line 110</span>
1249
+
1250
+ <span class='kw'>def</span> <span class='id identifier rubyid_never'>never</span>
1251
+ <span class='ivar'>@cardinality</span> <span class='op'>=</span> <span class='const'>Cardinality</span><span class='period'>.</span><span class='id identifier rubyid_exactly'>exactly</span><span class='lparen'>(</span><span class='int'>0</span><span class='rparen'>)</span>
1252
+ <span class='kw'>self</span>
1253
+ <span class='kw'>end</span></pre>
1254
+ </td>
1255
+ </tr>
1256
+ </table>
1257
+ </div>
1258
+
1259
+ <div class="method_details ">
1260
+ <h3 class="signature " id="once-instance_method">
1261
+
1262
+ #<strong>once</strong> &#x21d2; <tt><span class='object_link'><a href="" title="Mocha::Expectation (class)">Expectation</a></span></tt>
1263
+
1264
+
1265
+
1266
+
1267
+
1268
+ </h3><div class="docstring">
1269
+ <div class="discussion">
1270
+
1271
+ <p>Modifies expectation so that the expected method must be called exactly
1272
+ once.</p>
1273
+
1274
+ <p>Note that this is the default behaviour for an expectation, but you may
1275
+ wish to use it for clarity/emphasis.</p>
1276
+
1277
+
1278
+ </div>
1279
+ </div>
1280
+ <div class="tags">
1281
+
1282
+ <div class="examples">
1283
+ <p class="tag_title">Examples:</p>
1284
+
1285
+
1286
+ <p class="example_title"><div class='inline'>
1287
+ <p>Expected method must be invoked exactly once.</p>
1288
+ </div></p>
1289
+
1290
+ <pre class="example code"><code><span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='rparen'>)</span>
1291
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:expected_method</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_once'>once</span>
1292
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span>
1293
+ <span class='comment'># =&gt; verify succeeds
1294
+ </span>
1295
+ <span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='rparen'>)</span>
1296
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:expected_method</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_once'>once</span>
1297
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span>
1298
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span> <span class='comment'># =&gt; unexpected invocation
1299
+ </span>
1300
+ <span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='rparen'>)</span>
1301
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:expected_method</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_once'>once</span>
1302
+ <span class='comment'># =&gt; verify fails</span></code></pre>
1303
+
1304
+ </div>
1305
+
1306
+ <p class="tag_title">Returns:</p>
1307
+ <ul class="return">
1308
+
1309
+ <li>
1310
+
1311
+
1312
+ <span class='type'>(<tt><span class='object_link'><a href="" title="Mocha::Expectation (class)">Expectation</a></span></tt>)</span>
1313
+
1314
+
1315
+
1316
+ &mdash;
1317
+ <div class='inline'>
1318
+ <p>the same expectation, thereby allowing invocations of other <span class='object_link'><a href="" title="Mocha::Expectation (class)">Mocha::Expectation</a></span>
1319
+ methods to be chained.</p>
1320
+ </div>
1321
+
1322
+ </li>
1323
+
1324
+ </ul>
1325
+
1326
+ </div><table class="source_code">
1327
+ <tr>
1328
+ <td>
1329
+ <pre class="lines">
1330
+
1331
+
1332
+ 93
1333
+ 94
1334
+ 95
1335
+ 96</pre>
1336
+ </td>
1337
+ <td>
1338
+ <pre class="code"><span class="info file"># File 'lib/mocha/expectation.rb', line 93</span>
1339
+
1340
+ <span class='kw'>def</span> <span class='id identifier rubyid_once'>once</span>
1341
+ <span class='ivar'>@cardinality</span> <span class='op'>=</span> <span class='const'>Cardinality</span><span class='period'>.</span><span class='id identifier rubyid_exactly'>exactly</span><span class='lparen'>(</span><span class='int'>1</span><span class='rparen'>)</span>
1342
+ <span class='kw'>self</span>
1343
+ <span class='kw'>end</span></pre>
1344
+ </td>
1345
+ </tr>
1346
+ </table>
1347
+ </div>
1348
+
1349
+ <div class="method_details ">
1350
+ <h3 class="signature " id="raises-instance_method">
1351
+
1352
+
1353
+ <span class="overload">#<strong>raises</strong> &#x21d2; <tt><span class='object_link'><a href="" title="Mocha::Expectation (class)">Expectation</a></span></tt> </span>
1354
+
1355
+ <span class="overload">#<strong>raises</strong>(exception) &#x21d2; <tt><span class='object_link'><a href="" title="Mocha::Expectation (class)">Expectation</a></span></tt> </span>
1356
+
1357
+ <span class="overload">#<strong>raises</strong>(exception, message) &#x21d2; <tt><span class='object_link'><a href="" title="Mocha::Expectation (class)">Expectation</a></span></tt> </span>
1358
+
1359
+
1360
+
1361
+
1362
+
1363
+
1364
+ </h3><div class="docstring">
1365
+ <div class="discussion">
1366
+
1367
+ <p>Modifies expectation so that when the expected method is called, it raises
1368
+ the specified <code>exception</code> with the specified
1369
+ <code>message</code> i.e. calls <tt>Kernel#raise(exception, message)</tt>.</p>
1370
+
1371
+
1372
+ </div>
1373
+ </div>
1374
+ <div class="tags">
1375
+
1376
+ <div class="examples">
1377
+ <p class="tag_title">Examples:</p>
1378
+
1379
+
1380
+ <p class="example_title"><div class='inline'>
1381
+ <p>Raise specified exception if expected method is invoked.</p>
1382
+ </div></p>
1383
+
1384
+ <pre class="example code"><code><span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_stub'>stub</span><span class='lparen'>(</span><span class='rparen'>)</span>
1385
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='symbol'>:expected_method</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_raises'>raises</span><span class='lparen'>(</span><span class='const'>Exception</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>message</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>
1386
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span> <span class='comment'># =&gt; raises exception of class Exception and with message &#39;message&#39;</span></code></pre>
1387
+
1388
+
1389
+ <p class="example_title"><div class='inline'>
1390
+ <p>Raise custom exception with extra constructor parameters by passing in an
1391
+ instance of the exception.</p>
1392
+ </div></p>
1393
+
1394
+ <pre class="example code"><code><span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_stub'>stub</span><span class='lparen'>(</span><span class='rparen'>)</span>
1395
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='symbol'>:expected_method</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_raises'>raises</span><span class='lparen'>(</span><span class='const'>MyException</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>message</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='int'>1</span><span class='comma'>,</span> <span class='int'>2</span><span class='comma'>,</span> <span class='int'>3</span><span class='rparen'>)</span><span class='rparen'>)</span>
1396
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span> <span class='comment'># =&gt; raises the specified instance of MyException</span></code></pre>
1397
+
1398
+
1399
+ <p class="example_title"><div class='inline'>
1400
+ <p>Raise different exceptions on consecutive invocations of the expected
1401
+ method.</p>
1402
+ </div></p>
1403
+
1404
+ <pre class="example code"><code><span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_stub'>stub</span><span class='lparen'>(</span><span class='rparen'>)</span>
1405
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='symbol'>:expected_method</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_raises'>raises</span><span class='lparen'>(</span><span class='const'>Exception1</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_then'>then</span><span class='period'>.</span><span class='id identifier rubyid_raises'>raises</span><span class='lparen'>(</span><span class='const'>Exception2</span><span class='rparen'>)</span>
1406
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span> <span class='comment'># =&gt; raises exception of class Exception1
1407
+ </span><span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span> <span class='comment'># =&gt; raises exception of class Exception2</span></code></pre>
1408
+
1409
+
1410
+ <p class="example_title"><div class='inline'>
1411
+ <p>Raise an exception on first invocation of expected method and then return
1412
+ values on subsequent invocations.</p>
1413
+ </div></p>
1414
+
1415
+ <pre class="example code"><code><span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_stub'>stub</span><span class='lparen'>(</span><span class='rparen'>)</span>
1416
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='symbol'>:expected_method</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_raises'>raises</span><span class='lparen'>(</span><span class='const'>Exception</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_then'>then</span><span class='period'>.</span><span class='id identifier rubyid_returns'>returns</span><span class='lparen'>(</span><span class='int'>2</span><span class='comma'>,</span> <span class='int'>3</span><span class='rparen'>)</span>
1417
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span> <span class='comment'># =&gt; raises exception of class Exception1
1418
+ </span><span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span> <span class='comment'># =&gt; 2
1419
+ </span><span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span> <span class='comment'># =&gt; 3</span></code></pre>
1420
+
1421
+ </div>
1422
+ <p class="tag_title">Parameters:</p>
1423
+ <ul class="param">
1424
+
1425
+ <li>
1426
+
1427
+ <span class='name'>exception</span>
1428
+
1429
+
1430
+ <span class='type'>(<tt>Class</tt>, <tt>Exception</tt>, <tt>String</tt>, <tt>#exception</tt>)</span>
1431
+
1432
+
1433
+ <em class="default">(defaults to: <tt>RuntimeError</tt>)</em>
1434
+
1435
+
1436
+ &mdash;
1437
+ <div class='inline'>
1438
+ <p>exception to be raised or message to be passed to RuntimeError.</p>
1439
+ </div>
1440
+
1441
+ </li>
1442
+
1443
+ <li>
1444
+
1445
+ <span class='name'>message</span>
1446
+
1447
+
1448
+ <span class='type'>(<tt>String</tt>)</span>
1449
+
1450
+
1451
+ <em class="default">(defaults to: <tt>nil</tt>)</em>
1452
+
1453
+
1454
+ &mdash;
1455
+ <div class='inline'>
1456
+ <p>exception message.</p>
1457
+ </div>
1458
+
1459
+ </li>
1460
+
1461
+ </ul>
1462
+
1463
+ <p class="tag_title">Returns:</p>
1464
+ <ul class="return">
1465
+
1466
+ <li>
1467
+
1468
+
1469
+ <span class='type'>(<tt><span class='object_link'><a href="" title="Mocha::Expectation (class)">Expectation</a></span></tt>)</span>
1470
+
1471
+
1472
+
1473
+ &mdash;
1474
+ <div class='inline'>
1475
+ <p>the same expectation, thereby allowing invocations of other <span class='object_link'><a href="" title="Mocha::Expectation (class)">Mocha::Expectation</a></span>
1476
+ methods to be chained.</p>
1477
+ </div>
1478
+
1479
+ </li>
1480
+
1481
+ </ul>
1482
+
1483
+ <p class="tag_title">See Also:</p>
1484
+ <ul class="see">
1485
+
1486
+ <li>Kernel#raise</li>
1487
+
1488
+ <li><span class='object_link'><a href="#then-instance_method" title="Mocha::Expectation#then (method)">#then</a></span></li>
1489
+
1490
+ </ul>
1491
+
1492
+ </div><table class="source_code">
1493
+ <tr>
1494
+ <td>
1495
+ <pre class="lines">
1496
+
1497
+
1498
+ 364
1499
+ 365
1500
+ 366
1501
+ 367</pre>
1502
+ </td>
1503
+ <td>
1504
+ <pre class="code"><span class="info file"># File 'lib/mocha/expectation.rb', line 364</span>
1505
+
1506
+ <span class='kw'>def</span> <span class='id identifier rubyid_raises'>raises</span><span class='lparen'>(</span><span class='id identifier rubyid_exception'>exception</span> <span class='op'>=</span> <span class='const'>RuntimeError</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
1507
+ <span class='ivar'>@return_values</span> <span class='op'>+=</span> <span class='const'>ReturnValues</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='const'>ExceptionRaiser</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_exception'>exception</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span><span class='rparen'>)</span><span class='rparen'>)</span>
1508
+ <span class='kw'>self</span>
1509
+ <span class='kw'>end</span></pre>
1510
+ </td>
1511
+ </tr>
1512
+ </table>
1513
+ </div>
1514
+
1515
+ <div class="method_details ">
1516
+ <h3 class="signature " id="returns-instance_method">
1517
+
1518
+
1519
+ <span class="overload">#<strong>returns</strong>(value) &#x21d2; <tt><span class='object_link'><a href="" title="Mocha::Expectation (class)">Expectation</a></span></tt> </span>
1520
+
1521
+ <span class="overload">#<strong>returns</strong>(*values) &#x21d2; <tt><span class='object_link'><a href="" title="Mocha::Expectation (class)">Expectation</a></span></tt> </span>
1522
+
1523
+
1524
+
1525
+
1526
+
1527
+
1528
+ </h3><div class="docstring">
1529
+ <div class="discussion">
1530
+
1531
+ <p>Modifies expectation so that when the expected method is called, it returns
1532
+ the specified <code>value</code>.</p>
1533
+
1534
+
1535
+ </div>
1536
+ </div>
1537
+ <div class="tags">
1538
+
1539
+ <div class="examples">
1540
+ <p class="tag_title">Examples:</p>
1541
+
1542
+
1543
+ <p class="example_title"><div class='inline'>
1544
+ <p>Return the same value on every invocation.</p>
1545
+ </div></p>
1546
+
1547
+ <pre class="example code"><code><span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='rparen'>)</span>
1548
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='symbol'>:stubbed_method</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_returns'>returns</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>result</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>
1549
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_stubbed_method'>stubbed_method</span> <span class='comment'># =&gt; &#39;result&#39;
1550
+ </span><span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_stubbed_method'>stubbed_method</span> <span class='comment'># =&gt; &#39;result&#39;</span></code></pre>
1551
+
1552
+
1553
+ <p class="example_title"><div class='inline'>
1554
+ <p>Return a different value on consecutive invocations.</p>
1555
+ </div></p>
1556
+
1557
+ <pre class="example code"><code><span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='rparen'>)</span>
1558
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='symbol'>:stubbed_method</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_returns'>returns</span><span class='lparen'>(</span><span class='int'>1</span><span class='comma'>,</span> <span class='int'>2</span><span class='rparen'>)</span>
1559
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_stubbed_method'>stubbed_method</span> <span class='comment'># =&gt; 1
1560
+ </span><span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_stubbed_method'>stubbed_method</span> <span class='comment'># =&gt; 2</span></code></pre>
1561
+
1562
+
1563
+ <p class="example_title"><div class='inline'>
1564
+ <p>Alternative way to return a different value on consecutive invocations.</p>
1565
+ </div></p>
1566
+
1567
+ <pre class="example code"><code><span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='rparen'>)</span>
1568
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='symbol'>:expected_method</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_returns'>returns</span><span class='lparen'>(</span><span class='int'>1</span><span class='comma'>,</span> <span class='int'>2</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_then'>then</span><span class='period'>.</span><span class='id identifier rubyid_returns'>returns</span><span class='lparen'>(</span><span class='int'>3</span><span class='rparen'>)</span>
1569
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span> <span class='comment'># =&gt; 1
1570
+ </span><span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span> <span class='comment'># =&gt; 2
1571
+ </span><span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span> <span class='comment'># =&gt; 3</span></code></pre>
1572
+
1573
+
1574
+ <p class="example_title"><div class='inline'>
1575
+ <p>May be called in conjunction with <span class='object_link'><a href="#raises-instance_method" title="Mocha::Expectation#raises (method)">#raises</a></span> on the same expectation.</p>
1576
+ </div></p>
1577
+
1578
+ <pre class="example code"><code><span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='rparen'>)</span>
1579
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='symbol'>:expected_method</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_returns'>returns</span><span class='lparen'>(</span><span class='int'>1</span><span class='comma'>,</span> <span class='int'>2</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_then'>then</span><span class='period'>.</span><span class='id identifier rubyid_raises'>raises</span><span class='lparen'>(</span><span class='const'>Exception</span><span class='rparen'>)</span>
1580
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span> <span class='comment'># =&gt; 1
1581
+ </span><span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span> <span class='comment'># =&gt; 2
1582
+ </span><span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span> <span class='comment'># =&gt; raises exception of class Exception1</span></code></pre>
1583
+
1584
+
1585
+ <p class="example_title"><div class='inline'>
1586
+ <p>Note that in Ruby a method returning multiple values is exactly equivalent
1587
+ to a method returning an <code>Array</code> of those values.</p>
1588
+ </div></p>
1589
+
1590
+ <pre class="example code"><code><span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='rparen'>)</span>
1591
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='symbol'>:expected_method</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_returns'>returns</span><span class='lparen'>(</span><span class='lbracket'>[</span><span class='int'>1</span><span class='comma'>,</span> <span class='int'>2</span><span class='rbracket'>]</span><span class='rparen'>)</span>
1592
+ <span class='id identifier rubyid_x'>x</span><span class='comma'>,</span> <span class='id identifier rubyid_y'>y</span> <span class='op'>=</span> <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span>
1593
+ <span class='id identifier rubyid_x'>x</span> <span class='comment'># =&gt; 1
1594
+ </span><span class='id identifier rubyid_y'>y</span> <span class='comment'># =&gt; 2</span></code></pre>
1595
+
1596
+ </div>
1597
+
1598
+ <p class="tag_title">Overloads:</p>
1599
+ <ul class="overload">
1600
+
1601
+
1602
+ <li class="overload_item">
1603
+ <span class="signature">#<strong>returns</strong>(value) &#x21d2; <tt><span class='object_link'><a href="" title="Mocha::Expectation (class)">Expectation</a></span></tt> </span>
1604
+ <div class="docstring">
1605
+ <div class="discussion">
1606
+
1607
+
1608
+ </div>
1609
+ </div>
1610
+ <div class="tags">
1611
+ <p class="tag_title">Parameters:</p>
1612
+ <ul class="param">
1613
+
1614
+ <li>
1615
+
1616
+ <span class='name'>value</span>
1617
+
1618
+
1619
+ <span class='type'>(<tt><span class='object_link'>Object</span></tt>)</span>
1620
+
1621
+
1622
+
1623
+ &mdash;
1624
+ <div class='inline'>
1625
+ <p>value to return on invocation of expected method.</p>
1626
+ </div>
1627
+
1628
+ </li>
1629
+
1630
+ </ul>
1631
+
1632
+
1633
+ </div>
1634
+ </li>
1635
+
1636
+
1637
+ <li class="overload_item">
1638
+ <span class="signature">#<strong>returns</strong>(*values) &#x21d2; <tt><span class='object_link'><a href="" title="Mocha::Expectation (class)">Expectation</a></span></tt> </span>
1639
+ <div class="docstring">
1640
+ <div class="discussion">
1641
+
1642
+
1643
+ </div>
1644
+ </div>
1645
+ <div class="tags">
1646
+ <p class="tag_title">Parameters:</p>
1647
+ <ul class="param">
1648
+
1649
+ <li>
1650
+
1651
+ <span class='name'>values</span>
1652
+
1653
+
1654
+ <span class='type'>(<tt>*Array</tt>)</span>
1655
+
1656
+
1657
+
1658
+ &mdash;
1659
+ <div class='inline'>
1660
+ <p>values to return on consecutive invocations of expected method.</p>
1661
+ </div>
1662
+
1663
+ </li>
1664
+
1665
+ </ul>
1666
+
1667
+
1668
+ </div>
1669
+ </li>
1670
+
1671
+ </ul>
1672
+
1673
+ <p class="tag_title">Returns:</p>
1674
+ <ul class="return">
1675
+
1676
+ <li>
1677
+
1678
+
1679
+ <span class='type'>(<tt><span class='object_link'><a href="" title="Mocha::Expectation (class)">Expectation</a></span></tt>)</span>
1680
+
1681
+
1682
+
1683
+ &mdash;
1684
+ <div class='inline'>
1685
+ <p>the same expectation, thereby allowing invocations of other <span class='object_link'><a href="" title="Mocha::Expectation (class)">Mocha::Expectation</a></span>
1686
+ methods to be chained.</p>
1687
+ </div>
1688
+
1689
+ </li>
1690
+
1691
+ </ul>
1692
+
1693
+ <p class="tag_title">See Also:</p>
1694
+ <ul class="see">
1695
+
1696
+ <li><span class='object_link'><a href="#then-instance_method" title="Mocha::Expectation#then (method)">#then</a></span></li>
1697
+
1698
+ </ul>
1699
+
1700
+ </div><table class="source_code">
1701
+ <tr>
1702
+ <td>
1703
+ <pre class="lines">
1704
+
1705
+
1706
+ 324
1707
+ 325
1708
+ 326
1709
+ 327</pre>
1710
+ </td>
1711
+ <td>
1712
+ <pre class="code"><span class="info file"># File 'lib/mocha/expectation.rb', line 324</span>
1713
+
1714
+ <span class='kw'>def</span> <span class='id identifier rubyid_returns'>returns</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_values'>values</span><span class='rparen'>)</span>
1715
+ <span class='ivar'>@return_values</span> <span class='op'>+=</span> <span class='const'>ReturnValues</span><span class='period'>.</span><span class='id identifier rubyid_build'>build</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_values'>values</span><span class='rparen'>)</span>
1716
+ <span class='kw'>self</span>
1717
+ <span class='kw'>end</span></pre>
1718
+ </td>
1719
+ </tr>
1720
+ </table>
1721
+ </div>
1722
+
1723
+ <div class="method_details ">
1724
+ <h3 class="signature " id="then-instance_method">
1725
+
1726
+
1727
+ <span class="overload">#<strong>then</strong> &#x21d2; <tt><span class='object_link'><a href="" title="Mocha::Expectation (class)">Expectation</a></span></tt> </span>
1728
+
1729
+ <span class="overload">#<strong>then</strong>(state_machine.is(state_name)) &#x21d2; <tt><span class='object_link'><a href="" title="Mocha::Expectation (class)">Expectation</a></span></tt> </span>
1730
+
1731
+
1732
+
1733
+
1734
+
1735
+
1736
+ </h3><div class="docstring">
1737
+ <div class="discussion">
1738
+
1739
+ <p>Returns the same expectation, thereby allowing invocations of other
1740
+ <span class='object_link'><a href="" title="Mocha::Expectation (class)">Mocha::Expectation</a></span> methods to be chained.</p>
1741
+
1742
+
1743
+ </div>
1744
+ </div>
1745
+ <div class="tags">
1746
+
1747
+ <div class="examples">
1748
+ <p class="tag_title">Examples:</p>
1749
+
1750
+
1751
+ <p class="example_title"><div class='inline'>
1752
+ <p>Using <span class='object_link'><a href="#then-instance_method" title="Mocha::Expectation#then (method)">#then</a></span> as syntactic sugar when specifying values to be returned and
1753
+ exceptions to be raised on consecutive invocations of the expected method.</p>
1754
+ </div></p>
1755
+
1756
+ <pre class="example code"><code><span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='rparen'>)</span>
1757
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='symbol'>:expected_method</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_returns'>returns</span><span class='lparen'>(</span><span class='int'>1</span><span class='comma'>,</span> <span class='int'>2</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_then'>then</span><span class='period'>.</span><span class='id identifier rubyid_raises'>raises</span><span class='lparen'>(</span><span class='const'>Exception</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_then'>then</span><span class='period'>.</span><span class='id identifier rubyid_returns'>returns</span><span class='lparen'>(</span><span class='int'>4</span><span class='rparen'>)</span>
1758
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span> <span class='comment'># =&gt; 1
1759
+ </span><span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span> <span class='comment'># =&gt; 2
1760
+ </span><span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span> <span class='comment'># =&gt; raises exception of class Exception
1761
+ </span><span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span> <span class='comment'># =&gt; 4</span></code></pre>
1762
+
1763
+
1764
+ <p class="example_title"><div class='inline'>
1765
+ <p>Using <span class='object_link'><a href="#then-instance_method" title="Mocha::Expectation#then (method)">#then</a></span> to change the <code>state</code> of a
1766
+ <code>state_machine</code> on the invocation of an expected method.</p>
1767
+ </div></p>
1768
+
1769
+ <pre class="example code"><code><span class='id identifier rubyid_power'>power</span> <span class='op'>=</span> <span class='id identifier rubyid_states'>states</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>power</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_starts_as'>starts_as</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>off</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>
1770
+
1771
+ <span class='id identifier rubyid_radio'>radio</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>radio</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>
1772
+ <span class='id identifier rubyid_radio'>radio</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:switch_on</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_then'>then</span><span class='lparen'>(</span><span class='id identifier rubyid_power'>power</span><span class='period'>.</span><span class='id identifier rubyid_is'>is</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>on</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
1773
+ <span class='id identifier rubyid_radio'>radio</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:select_channel</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_with'>with</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>BBC Radio 4</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_when'>when</span><span class='lparen'>(</span><span class='id identifier rubyid_power'>power</span><span class='period'>.</span><span class='id identifier rubyid_is'>is</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>on</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
1774
+ <span class='id identifier rubyid_radio'>radio</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:adjust_volume</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_with'>with</span><span class='lparen'>(</span><span class='int'>+5</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_when'>when</span><span class='lparen'>(</span><span class='id identifier rubyid_power'>power</span><span class='period'>.</span><span class='id identifier rubyid_is'>is</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>on</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
1775
+ <span class='id identifier rubyid_radio'>radio</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:select_channel</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_with'>with</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>BBC World Service</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_when'>when</span><span class='lparen'>(</span><span class='id identifier rubyid_power'>power</span><span class='period'>.</span><span class='id identifier rubyid_is'>is</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>on</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
1776
+ <span class='id identifier rubyid_radio'>radio</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:adjust_volume</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_with'>with</span><span class='lparen'>(</span><span class='op'>-</span><span class='int'>5</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_when'>when</span><span class='lparen'>(</span><span class='id identifier rubyid_power'>power</span><span class='period'>.</span><span class='id identifier rubyid_is'>is</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>on</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
1777
+ <span class='id identifier rubyid_radio'>radio</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:switch_off</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_then'>then</span><span class='lparen'>(</span><span class='id identifier rubyid_power'>power</span><span class='period'>.</span><span class='id identifier rubyid_is'>is</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>off</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span><span class='rparen'>)</span></code></pre>
1778
+
1779
+ </div>
1780
+
1781
+ <p class="tag_title">Overloads:</p>
1782
+ <ul class="overload">
1783
+
1784
+
1785
+ <li class="overload_item">
1786
+ <span class="signature">#<strong>then</strong> &#x21d2; <tt><span class='object_link'><a href="" title="Mocha::Expectation (class)">Expectation</a></span></tt> </span>
1787
+ <div class="docstring">
1788
+ <div class="discussion">
1789
+
1790
+ <p>Used as syntactic sugar to improve readability. It has no effect on state
1791
+ of the expectation.</p>
1792
+
1793
+
1794
+ </div>
1795
+ </div>
1796
+ <div class="tags">
1797
+
1798
+
1799
+ </div>
1800
+ </li>
1801
+
1802
+
1803
+ <li class="overload_item">
1804
+ <span class="signature">#<strong>then</strong>(state_machine.is(state_name)) &#x21d2; <tt><span class='object_link'><a href="" title="Mocha::Expectation (class)">Expectation</a></span></tt> </span>
1805
+ <div class="docstring">
1806
+ <div class="discussion">
1807
+
1808
+ <p>Used to change the <code>state_machine</code> to the state specified by
1809
+ <code>state_name</code> when the expected invocation occurs.</p>
1810
+
1811
+
1812
+ </div>
1813
+ </div>
1814
+ <div class="tags">
1815
+ <p class="tag_title">Parameters:</p>
1816
+ <ul class="param">
1817
+
1818
+ <li>
1819
+
1820
+ <span class='name'>state_machine.is(state_name)</span>
1821
+
1822
+
1823
+ <span class='type'>(<tt><span class='object_link'><a href="StateMachine/State.html" title="Mocha::StateMachine::State (class)">StateMachine::State</a></span></tt>)</span>
1824
+
1825
+
1826
+
1827
+ &mdash;
1828
+ <div class='inline'>
1829
+ <p>provides a mechanism to change the <code>state_machine</code> into the
1830
+ state specified by <code>state_name</code> when the expected method is
1831
+ invoked.</p>
1832
+ </div>
1833
+
1834
+ </li>
1835
+
1836
+ </ul>
1837
+
1838
+
1839
+ <p class="tag_title">See Also:</p>
1840
+ <ul class="see">
1841
+
1842
+ <li><span class='object_link'><a href="API.html#states-instance_method" title="Mocha::API#states (method)">API#states</a></span></li>
1843
+
1844
+ <li><span class='object_link'><a href="StateMachine.html" title="Mocha::StateMachine (class)">StateMachine</a></span></li>
1845
+
1846
+ <li><span class='object_link'><a href="#when-instance_method" title="Mocha::Expectation#when (method)">#when</a></span></li>
1847
+
1848
+ </ul>
1849
+
1850
+ </div>
1851
+ </li>
1852
+
1853
+ </ul>
1854
+
1855
+ <p class="tag_title">Returns:</p>
1856
+ <ul class="return">
1857
+
1858
+ <li>
1859
+
1860
+
1861
+ <span class='type'>(<tt><span class='object_link'><a href="" title="Mocha::Expectation (class)">Expectation</a></span></tt>)</span>
1862
+
1863
+
1864
+
1865
+ &mdash;
1866
+ <div class='inline'>
1867
+ <p>the same expectation, thereby allowing invocations of other <span class='object_link'><a href="" title="Mocha::Expectation (class)">Mocha::Expectation</a></span>
1868
+ methods to be chained.</p>
1869
+ </div>
1870
+
1871
+ </li>
1872
+
1873
+ </ul>
1874
+
1875
+ </div><table class="source_code">
1876
+ <tr>
1877
+ <td>
1878
+ <pre class="lines">
1879
+
1880
+
1881
+ 438
1882
+ 439
1883
+ 440
1884
+ 441
1885
+ 442
1886
+ 443
1887
+ 444</pre>
1888
+ </td>
1889
+ <td>
1890
+ <pre class="code"><span class="info file"># File 'lib/mocha/expectation.rb', line 438</span>
1891
+
1892
+ <span class='kw'>def</span> <span class='kw'>then</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_parameters'>parameters</span><span class='rparen'>)</span>
1893
+ <span class='kw'>if</span> <span class='id identifier rubyid_parameters'>parameters</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span> <span class='op'>==</span> <span class='int'>1</span>
1894
+ <span class='id identifier rubyid_state'>state</span> <span class='op'>=</span> <span class='id identifier rubyid_parameters'>parameters</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span>
1895
+ <span class='id identifier rubyid_add_side_effect'>add_side_effect</span><span class='lparen'>(</span><span class='const'>ChangeStateSideEffect</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_state'>state</span><span class='rparen'>)</span><span class='rparen'>)</span>
1896
+ <span class='kw'>end</span>
1897
+ <span class='kw'>self</span>
1898
+ <span class='kw'>end</span></pre>
1899
+ </td>
1900
+ </tr>
1901
+ </table>
1902
+ </div>
1903
+
1904
+ <div class="method_details ">
1905
+ <h3 class="signature " id="throws-instance_method">
1906
+
1907
+
1908
+ <span class="overload">#<strong>throw</strong>(tag) &#x21d2; <tt><span class='object_link'><a href="" title="Mocha::Expectation (class)">Expectation</a></span></tt> </span>
1909
+
1910
+ <span class="overload">#<strong>throw</strong>(tag, object) &#x21d2; <tt><span class='object_link'><a href="" title="Mocha::Expectation (class)">Expectation</a></span></tt> </span>
1911
+
1912
+
1913
+
1914
+
1915
+
1916
+
1917
+ </h3><div class="docstring">
1918
+ <div class="discussion">
1919
+
1920
+ <p>Modifies expectation so that when the expected method is called, it throws
1921
+ the specified <code>tag</code> with the specific return value
1922
+ <code>object</code> i.e. calls <tt>Kernel#throw(tag, object)</tt>.</p>
1923
+
1924
+
1925
+ </div>
1926
+ </div>
1927
+ <div class="tags">
1928
+
1929
+ <div class="examples">
1930
+ <p class="tag_title">Examples:</p>
1931
+
1932
+
1933
+ <p class="example_title"><div class='inline'>
1934
+ <p>Throw tag when expected method is invoked.</p>
1935
+ </div></p>
1936
+
1937
+ <pre class="example code"><code><span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_stub'>stub</span><span class='lparen'>(</span><span class='rparen'>)</span>
1938
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='symbol'>:expected_method</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_throws'>throws</span><span class='lparen'>(</span><span class='symbol'>:done</span><span class='rparen'>)</span>
1939
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span> <span class='comment'># =&gt; throws tag :done</span></code></pre>
1940
+
1941
+
1942
+ <p class="example_title"><div class='inline'>
1943
+ <p>Throw tag with return value <code>object</code> c.f. <tt>Kernel#throw</tt>.</p>
1944
+ </div></p>
1945
+
1946
+ <pre class="example code"><code><span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_stub'>stub</span><span class='lparen'>(</span><span class='rparen'>)</span>
1947
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='symbol'>:expected_method</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_throws'>throws</span><span class='lparen'>(</span><span class='symbol'>:done</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>result</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>
1948
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span> <span class='comment'># =&gt; throws tag :done and causes catch block to return &#39;result&#39;</span></code></pre>
1949
+
1950
+
1951
+ <p class="example_title"><div class='inline'>
1952
+ <p>Throw different tags on consecutive invocations of the expected method.</p>
1953
+ </div></p>
1954
+
1955
+ <pre class="example code"><code><span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_stub'>stub</span><span class='lparen'>(</span><span class='rparen'>)</span>
1956
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='symbol'>:expected_method</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_throws'>throws</span><span class='lparen'>(</span><span class='symbol'>:done</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_then'>then</span><span class='period'>.</span><span class='id identifier rubyid_throws'>throws</span><span class='lparen'>(</span><span class='symbol'>:continue</span><span class='rparen'>)</span>
1957
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span> <span class='comment'># =&gt; throws :done
1958
+ </span><span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span> <span class='comment'># =&gt; throws :continue</span></code></pre>
1959
+
1960
+
1961
+ <p class="example_title"><div class='inline'>
1962
+ <p>Throw tag on first invocation of expected method and then return values for
1963
+ subsequent invocations.</p>
1964
+ </div></p>
1965
+
1966
+ <pre class="example code"><code><span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_stub'>stub</span><span class='lparen'>(</span><span class='rparen'>)</span>
1967
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='symbol'>:expected_method</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_throws'>throws</span><span class='lparen'>(</span><span class='symbol'>:done</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_then'>then</span><span class='period'>.</span><span class='id identifier rubyid_returns'>returns</span><span class='lparen'>(</span><span class='int'>2</span><span class='comma'>,</span> <span class='int'>3</span><span class='rparen'>)</span>
1968
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span> <span class='comment'># =&gt; throws :done
1969
+ </span><span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span> <span class='comment'># =&gt; 2
1970
+ </span><span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span> <span class='comment'># =&gt; 3</span></code></pre>
1971
+
1972
+ </div>
1973
+ <p class="tag_title">Parameters:</p>
1974
+ <ul class="param">
1975
+
1976
+ <li>
1977
+
1978
+ <span class='name'>tag</span>
1979
+
1980
+
1981
+ <span class='type'>(<tt>Symbol</tt>, <tt>String</tt>)</span>
1982
+
1983
+
1984
+
1985
+ &mdash;
1986
+ <div class='inline'>
1987
+ <p>tag to throw to transfer control to the active catch block.</p>
1988
+ </div>
1989
+
1990
+ </li>
1991
+
1992
+ <li>
1993
+
1994
+ <span class='name'>object</span>
1995
+
1996
+
1997
+ <span class='type'>(<tt><span class='object_link'>Object</span></tt>)</span>
1998
+
1999
+
2000
+ <em class="default">(defaults to: <tt>nil</tt>)</em>
2001
+
2002
+
2003
+ &mdash;
2004
+ <div class='inline'>
2005
+ <p>return value for the catch block.</p>
2006
+ </div>
2007
+
2008
+ </li>
2009
+
2010
+ </ul>
2011
+
2012
+ <p class="tag_title">Returns:</p>
2013
+ <ul class="return">
2014
+
2015
+ <li>
2016
+
2017
+
2018
+ <span class='type'>(<tt><span class='object_link'><a href="" title="Mocha::Expectation (class)">Expectation</a></span></tt>)</span>
2019
+
2020
+
2021
+
2022
+ &mdash;
2023
+ <div class='inline'>
2024
+ <p>the same expectation, thereby allowing invocations of other <span class='object_link'><a href="" title="Mocha::Expectation (class)">Mocha::Expectation</a></span>
2025
+ methods to be chained.</p>
2026
+ </div>
2027
+
2028
+ </li>
2029
+
2030
+ </ul>
2031
+
2032
+ <p class="tag_title">See Also:</p>
2033
+ <ul class="see">
2034
+
2035
+ <li>Kernel#throw</li>
2036
+
2037
+ <li><span class='object_link'><a href="#then-instance_method" title="Mocha::Expectation#then (method)">#then</a></span></li>
2038
+
2039
+ </ul>
2040
+
2041
+ </div><table class="source_code">
2042
+ <tr>
2043
+ <td>
2044
+ <pre class="lines">
2045
+
2046
+
2047
+ 403
2048
+ 404
2049
+ 405
2050
+ 406</pre>
2051
+ </td>
2052
+ <td>
2053
+ <pre class="code"><span class="info file"># File 'lib/mocha/expectation.rb', line 403</span>
2054
+
2055
+ <span class='kw'>def</span> <span class='id identifier rubyid_throws'>throws</span><span class='lparen'>(</span><span class='id identifier rubyid_tag'>tag</span><span class='comma'>,</span> <span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
2056
+ <span class='ivar'>@return_values</span> <span class='op'>+=</span> <span class='const'>ReturnValues</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='const'>Thrower</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_tag'>tag</span><span class='comma'>,</span> <span class='id identifier rubyid_object'>object</span><span class='rparen'>)</span><span class='rparen'>)</span>
2057
+ <span class='kw'>self</span>
2058
+ <span class='kw'>end</span></pre>
2059
+ </td>
2060
+ </tr>
2061
+ </table>
2062
+ </div>
2063
+
2064
+ <div class="method_details ">
2065
+ <h3 class="signature " id="times-instance_method">
2066
+
2067
+ #<strong>times</strong>(range) &#x21d2; <tt><span class='object_link'><a href="" title="Mocha::Expectation (class)">Expectation</a></span></tt>
2068
+
2069
+
2070
+
2071
+
2072
+
2073
+ </h3><div class="docstring">
2074
+ <div class="discussion">
2075
+
2076
+ <p>Modifies expectation so that the number of calls to the expected method
2077
+ must be within a specific <code>range</code>.</p>
2078
+
2079
+
2080
+ </div>
2081
+ </div>
2082
+ <div class="tags">
2083
+
2084
+ <div class="examples">
2085
+ <p class="tag_title">Examples:</p>
2086
+
2087
+
2088
+ <p class="example_title"><div class='inline'>
2089
+ <p>Specifying a specific number of expected invocations.</p>
2090
+ </div></p>
2091
+
2092
+ <pre class="example code"><code><span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='rparen'>)</span>
2093
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:expected_method</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_times'>times</span><span class='lparen'>(</span><span class='int'>3</span><span class='rparen'>)</span>
2094
+ <span class='int'>3</span><span class='period'>.</span><span class='id identifier rubyid_times'>times</span> <span class='lbrace'>{</span> <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span> <span class='rbrace'>}</span>
2095
+ <span class='comment'># =&gt; verify succeeds
2096
+ </span>
2097
+ <span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='rparen'>)</span>
2098
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:expected_method</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_times'>times</span><span class='lparen'>(</span><span class='int'>3</span><span class='rparen'>)</span>
2099
+ <span class='int'>2</span><span class='period'>.</span><span class='id identifier rubyid_times'>times</span> <span class='lbrace'>{</span> <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span> <span class='rbrace'>}</span>
2100
+ <span class='comment'># =&gt; verify fails</span></code></pre>
2101
+
2102
+
2103
+ <p class="example_title"><div class='inline'>
2104
+ <p>Specifying a range in the number of expected invocations.</p>
2105
+ </div></p>
2106
+
2107
+ <pre class="example code"><code><span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='rparen'>)</span>
2108
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:expected_method</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_times'>times</span><span class='lparen'>(</span><span class='int'>2</span><span class='op'>..</span><span class='int'>4</span><span class='rparen'>)</span>
2109
+ <span class='int'>3</span><span class='period'>.</span><span class='id identifier rubyid_times'>times</span> <span class='lbrace'>{</span> <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span> <span class='rbrace'>}</span>
2110
+ <span class='comment'># =&gt; verify succeeds
2111
+ </span>
2112
+ <span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='rparen'>)</span>
2113
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:expected_method</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_times'>times</span><span class='lparen'>(</span><span class='int'>2</span><span class='op'>..</span><span class='int'>4</span><span class='rparen'>)</span>
2114
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span>
2115
+ <span class='comment'># =&gt; verify fails</span></code></pre>
2116
+
2117
+ </div>
2118
+ <p class="tag_title">Parameters:</p>
2119
+ <ul class="param">
2120
+
2121
+ <li>
2122
+
2123
+ <span class='name'>range</span>
2124
+
2125
+
2126
+ <span class='type'>(<tt>Range</tt>, <tt>Integer</tt>)</span>
2127
+
2128
+
2129
+
2130
+ &mdash;
2131
+ <div class='inline'>
2132
+ <p>specifies the allowable range in the number of expected invocations.</p>
2133
+ </div>
2134
+
2135
+ </li>
2136
+
2137
+ </ul>
2138
+
2139
+ <p class="tag_title">Returns:</p>
2140
+ <ul class="return">
2141
+
2142
+ <li>
2143
+
2144
+
2145
+ <span class='type'>(<tt><span class='object_link'><a href="" title="Mocha::Expectation (class)">Expectation</a></span></tt>)</span>
2146
+
2147
+
2148
+
2149
+ &mdash;
2150
+ <div class='inline'>
2151
+ <p>the same expectation, thereby allowing invocations of other <span class='object_link'><a href="" title="Mocha::Expectation (class)">Mocha::Expectation</a></span>
2152
+ methods to be chained.</p>
2153
+ </div>
2154
+
2155
+ </li>
2156
+
2157
+ </ul>
2158
+
2159
+ </div><table class="source_code">
2160
+ <tr>
2161
+ <td>
2162
+ <pre class="lines">
2163
+
2164
+
2165
+ 42
2166
+ 43
2167
+ 44
2168
+ 45</pre>
2169
+ </td>
2170
+ <td>
2171
+ <pre class="code"><span class="info file"># File 'lib/mocha/expectation.rb', line 42</span>
2172
+
2173
+ <span class='kw'>def</span> <span class='id identifier rubyid_times'>times</span><span class='lparen'>(</span><span class='id identifier rubyid_range'>range</span><span class='rparen'>)</span>
2174
+ <span class='ivar'>@cardinality</span> <span class='op'>=</span> <span class='const'>Cardinality</span><span class='period'>.</span><span class='id identifier rubyid_times'>times</span><span class='lparen'>(</span><span class='id identifier rubyid_range'>range</span><span class='rparen'>)</span>
2175
+ <span class='kw'>self</span>
2176
+ <span class='kw'>end</span></pre>
2177
+ </td>
2178
+ </tr>
2179
+ </table>
2180
+ </div>
2181
+
2182
+ <div class="method_details ">
2183
+ <h3 class="signature " id="twice-instance_method">
2184
+
2185
+ #<strong>twice</strong> &#x21d2; <tt><span class='object_link'><a href="" title="Mocha::Expectation (class)">Expectation</a></span></tt>
2186
+
2187
+
2188
+
2189
+
2190
+
2191
+ </h3><div class="docstring">
2192
+ <div class="discussion">
2193
+
2194
+ <p>Modifies expectation so that the expected method must be called exactly
2195
+ twice.</p>
2196
+
2197
+
2198
+ </div>
2199
+ </div>
2200
+ <div class="tags">
2201
+
2202
+ <div class="examples">
2203
+ <p class="tag_title">Examples:</p>
2204
+
2205
+
2206
+ <p class="example_title"><div class='inline'>
2207
+ <p>Expected method must be invoked exactly twice.</p>
2208
+ </div></p>
2209
+
2210
+ <pre class="example code"><code><span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='rparen'>)</span>
2211
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:expected_method</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_twice'>twice</span>
2212
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span>
2213
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span>
2214
+ <span class='comment'># =&gt; verify succeeds
2215
+ </span>
2216
+ <span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='rparen'>)</span>
2217
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:expected_method</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_twice'>twice</span>
2218
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span>
2219
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span>
2220
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span> <span class='comment'># =&gt; unexpected invocation
2221
+ </span>
2222
+ <span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='rparen'>)</span>
2223
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:expected_method</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_twice'>twice</span>
2224
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span>
2225
+ <span class='comment'># =&gt; verify fails</span></code></pre>
2226
+
2227
+ </div>
2228
+
2229
+ <p class="tag_title">Returns:</p>
2230
+ <ul class="return">
2231
+
2232
+ <li>
2233
+
2234
+
2235
+ <span class='type'>(<tt><span class='object_link'><a href="" title="Mocha::Expectation (class)">Expectation</a></span></tt>)</span>
2236
+
2237
+
2238
+
2239
+ &mdash;
2240
+ <div class='inline'>
2241
+ <p>the same expectation, thereby allowing invocations of other <span class='object_link'><a href="" title="Mocha::Expectation (class)">Mocha::Expectation</a></span>
2242
+ methods to be chained.</p>
2243
+ </div>
2244
+
2245
+ </li>
2246
+
2247
+ </ul>
2248
+
2249
+ </div><table class="source_code">
2250
+ <tr>
2251
+ <td>
2252
+ <pre class="lines">
2253
+
2254
+
2255
+ 68
2256
+ 69
2257
+ 70
2258
+ 71</pre>
2259
+ </td>
2260
+ <td>
2261
+ <pre class="code"><span class="info file"># File 'lib/mocha/expectation.rb', line 68</span>
2262
+
2263
+ <span class='kw'>def</span> <span class='id identifier rubyid_twice'>twice</span>
2264
+ <span class='ivar'>@cardinality</span> <span class='op'>=</span> <span class='const'>Cardinality</span><span class='period'>.</span><span class='id identifier rubyid_exactly'>exactly</span><span class='lparen'>(</span><span class='int'>2</span><span class='rparen'>)</span>
2265
+ <span class='kw'>self</span>
2266
+ <span class='kw'>end</span></pre>
2267
+ </td>
2268
+ </tr>
2269
+ </table>
2270
+ </div>
2271
+
2272
+ <div class="method_details ">
2273
+ <h3 class="signature " id="when-instance_method">
2274
+
2275
+ #<strong>when</strong>(state_predicate) &#x21d2; <tt><span class='object_link'><a href="" title="Mocha::Expectation (class)">Expectation</a></span></tt>
2276
+
2277
+
2278
+
2279
+
2280
+
2281
+ </h3><div class="docstring">
2282
+ <div class="discussion">
2283
+
2284
+ <p>Constrains the expectation to occur only when the
2285
+ <code>state_machine</code> is in the state specified by
2286
+ <code>state_name</code>.</p>
2287
+
2288
+
2289
+ </div>
2290
+ </div>
2291
+ <div class="tags">
2292
+
2293
+ <div class="examples">
2294
+ <p class="tag_title">Examples:</p>
2295
+
2296
+
2297
+ <p class="example_title"><div class='inline'>
2298
+ <p>Using <span class='object_link'><a href="#when-instance_method" title="Mocha::Expectation#when (method)">#when</a></span> to only allow invocation of methods when “power” state
2299
+ machine is in the “on” state.</p>
2300
+ </div></p>
2301
+
2302
+ <pre class="example code"><code><span class='id identifier rubyid_power'>power</span> <span class='op'>=</span> <span class='id identifier rubyid_states'>states</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>power</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_starts_as'>starts_as</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>off</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>
2303
+
2304
+ <span class='id identifier rubyid_radio'>radio</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>radio</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>
2305
+ <span class='id identifier rubyid_radio'>radio</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:switch_on</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_then'>then</span><span class='lparen'>(</span><span class='id identifier rubyid_power'>power</span><span class='period'>.</span><span class='id identifier rubyid_is'>is</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>on</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
2306
+ <span class='id identifier rubyid_radio'>radio</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:select_channel</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_with'>with</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>BBC Radio 4</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_when'>when</span><span class='lparen'>(</span><span class='id identifier rubyid_power'>power</span><span class='period'>.</span><span class='id identifier rubyid_is'>is</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>on</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
2307
+ <span class='id identifier rubyid_radio'>radio</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:adjust_volume</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_with'>with</span><span class='lparen'>(</span><span class='int'>+5</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_when'>when</span><span class='lparen'>(</span><span class='id identifier rubyid_power'>power</span><span class='period'>.</span><span class='id identifier rubyid_is'>is</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>on</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
2308
+ <span class='id identifier rubyid_radio'>radio</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:select_channel</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_with'>with</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>BBC World Service</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_when'>when</span><span class='lparen'>(</span><span class='id identifier rubyid_power'>power</span><span class='period'>.</span><span class='id identifier rubyid_is'>is</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>on</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
2309
+ <span class='id identifier rubyid_radio'>radio</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:adjust_volume</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_with'>with</span><span class='lparen'>(</span><span class='op'>-</span><span class='int'>5</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_when'>when</span><span class='lparen'>(</span><span class='id identifier rubyid_power'>power</span><span class='period'>.</span><span class='id identifier rubyid_is'>is</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>on</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
2310
+ <span class='id identifier rubyid_radio'>radio</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:switch_off</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_then'>then</span><span class='lparen'>(</span><span class='id identifier rubyid_power'>power</span><span class='period'>.</span><span class='id identifier rubyid_is'>is</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>off</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span><span class='rparen'>)</span></code></pre>
2311
+
2312
+ </div>
2313
+ <p class="tag_title">Parameters:</p>
2314
+ <ul class="param">
2315
+
2316
+ <li>
2317
+
2318
+ <span class='name'>state_machine.is(state_name)</span>
2319
+
2320
+
2321
+ <span class='type'>(<tt><span class='object_link'><a href="StateMachine/StatePredicate.html" title="Mocha::StateMachine::StatePredicate (class)">StateMachine::StatePredicate</a></span></tt>)</span>
2322
+
2323
+
2324
+
2325
+ &mdash;
2326
+ <div class='inline'>
2327
+ <p>provides a mechanism to determine whether the <code>state_machine</code> is
2328
+ in the state specified by <code>state_name</code> when the expected method
2329
+ is invoked.</p>
2330
+ </div>
2331
+
2332
+ </li>
2333
+
2334
+ </ul>
2335
+
2336
+ <p class="tag_title">Returns:</p>
2337
+ <ul class="return">
2338
+
2339
+ <li>
2340
+
2341
+
2342
+ <span class='type'>(<tt><span class='object_link'><a href="" title="Mocha::Expectation (class)">Expectation</a></span></tt>)</span>
2343
+
2344
+
2345
+
2346
+ &mdash;
2347
+ <div class='inline'>
2348
+ <p>the same expectation, thereby allowing invocations of other <span class='object_link'><a href="" title="Mocha::Expectation (class)">Mocha::Expectation</a></span>
2349
+ methods to be chained.</p>
2350
+ </div>
2351
+
2352
+ </li>
2353
+
2354
+ </ul>
2355
+
2356
+ <p class="tag_title">See Also:</p>
2357
+ <ul class="see">
2358
+
2359
+ <li><span class='object_link'><a href="API.html#states-instance_method" title="Mocha::API#states (method)">API#states</a></span></li>
2360
+
2361
+ <li><span class='object_link'><a href="StateMachine.html" title="Mocha::StateMachine (class)">StateMachine</a></span></li>
2362
+
2363
+ <li><span class='object_link'><a href="#then-instance_method" title="Mocha::Expectation#then (method)">#then</a></span></li>
2364
+
2365
+ </ul>
2366
+
2367
+ </div><table class="source_code">
2368
+ <tr>
2369
+ <td>
2370
+ <pre class="lines">
2371
+
2372
+
2373
+ 465
2374
+ 466
2375
+ 467
2376
+ 468</pre>
2377
+ </td>
2378
+ <td>
2379
+ <pre class="code"><span class="info file"># File 'lib/mocha/expectation.rb', line 465</span>
2380
+
2381
+ <span class='kw'>def</span> <span class='kw'>when</span><span class='lparen'>(</span><span class='id identifier rubyid_state_predicate'>state_predicate</span><span class='rparen'>)</span>
2382
+ <span class='id identifier rubyid_add_ordering_constraint'>add_ordering_constraint</span><span class='lparen'>(</span><span class='const'>InStateOrderingConstraint</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_state_predicate'>state_predicate</span><span class='rparen'>)</span><span class='rparen'>)</span>
2383
+ <span class='kw'>self</span>
2384
+ <span class='kw'>end</span></pre>
2385
+ </td>
2386
+ </tr>
2387
+ </table>
2388
+ </div>
2389
+
2390
+ <div class="method_details ">
2391
+ <h3 class="signature " id="with-instance_method">
2392
+
2393
+ #<strong>with</strong>(*expected_parameters) {|actual_parameters| ... } &#x21d2; <tt><span class='object_link'><a href="" title="Mocha::Expectation (class)">Expectation</a></span></tt>
2394
+
2395
+
2396
+
2397
+
2398
+
2399
+ </h3><div class="docstring">
2400
+ <div class="discussion">
2401
+
2402
+ <p>Modifies expectation so that the expected method must be called with
2403
+ <code>expected_parameters</code>.</p>
2404
+
2405
+ <p>May be used with parameter matchers in <span class='object_link'><a href="ParameterMatchers.html" title="Mocha::ParameterMatchers (module)">ParameterMatchers</a></span>.</p>
2406
+
2407
+
2408
+ </div>
2409
+ </div>
2410
+ <div class="tags">
2411
+
2412
+ <div class="examples">
2413
+ <p class="tag_title">Examples:</p>
2414
+
2415
+
2416
+ <p class="example_title"><div class='inline'>
2417
+ <p>Expected method must be called with expected parameters.</p>
2418
+ </div></p>
2419
+
2420
+ <pre class="example code"><code><span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='rparen'>)</span>
2421
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:expected_method</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_with'>with</span><span class='lparen'>(</span><span class='symbol'>:param1</span><span class='comma'>,</span> <span class='symbol'>:param2</span><span class='rparen'>)</span>
2422
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span><span class='lparen'>(</span><span class='symbol'>:param1</span><span class='comma'>,</span> <span class='symbol'>:param2</span><span class='rparen'>)</span>
2423
+ <span class='comment'># =&gt; verify succeeds
2424
+ </span>
2425
+ <span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='rparen'>)</span>
2426
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:expected_method</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_with'>with</span><span class='lparen'>(</span><span class='symbol'>:param1</span><span class='comma'>,</span> <span class='symbol'>:param2</span><span class='rparen'>)</span>
2427
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span><span class='lparen'>(</span><span class='symbol'>:param3</span><span class='rparen'>)</span>
2428
+ <span class='comment'># =&gt; verify fails</span></code></pre>
2429
+
2430
+
2431
+ <p class="example_title"><div class='inline'>
2432
+ <p>Expected method must be called with a value divisible by 4.</p>
2433
+ </div></p>
2434
+
2435
+ <pre class="example code"><code><span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='rparen'>)</span>
2436
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:expected_method</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_with'>with</span><span class='lparen'>(</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_value'>value</span><span class='op'>|</span> <span class='id identifier rubyid_value'>value</span> <span class='op'>%</span> <span class='int'>4</span> <span class='op'>==</span> <span class='int'>0</span> <span class='rbrace'>}</span>
2437
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span><span class='lparen'>(</span><span class='int'>16</span><span class='rparen'>)</span>
2438
+ <span class='comment'># =&gt; verify succeeds
2439
+ </span>
2440
+ <span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='rparen'>)</span>
2441
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:expected_method</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_with'>with</span><span class='lparen'>(</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_value'>value</span><span class='op'>|</span> <span class='id identifier rubyid_value'>value</span> <span class='op'>%</span> <span class='int'>4</span> <span class='op'>==</span> <span class='int'>0</span> <span class='rbrace'>}</span>
2442
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span><span class='lparen'>(</span><span class='int'>17</span><span class='rparen'>)</span>
2443
+ <span class='comment'># =&gt; verify fails</span></code></pre>
2444
+
2445
+ </div>
2446
+ <p class="tag_title">Parameters:</p>
2447
+ <ul class="param">
2448
+
2449
+ <li>
2450
+
2451
+ <span class='name'>expected_parameters</span>
2452
+
2453
+
2454
+ <span class='type'>(<tt>*Array</tt>)</span>
2455
+
2456
+
2457
+
2458
+ &mdash;
2459
+ <div class='inline'>
2460
+ <p>parameters expected.</p>
2461
+ </div>
2462
+
2463
+ </li>
2464
+
2465
+ </ul>
2466
+
2467
+ <p class="tag_title">Yields:</p>
2468
+ <ul class="yield">
2469
+
2470
+ <li>
2471
+
2472
+
2473
+ <span class='type'></span>
2474
+
2475
+
2476
+
2477
+
2478
+ <div class='inline'>
2479
+ <p>optional block specifying custom matching.</p>
2480
+ </div>
2481
+
2482
+ </li>
2483
+
2484
+ </ul>
2485
+ <p class="tag_title">Yield Parameters:</p>
2486
+ <ul class="yieldparam">
2487
+
2488
+ <li>
2489
+
2490
+ <span class='name'>actual_parameters</span>
2491
+
2492
+
2493
+ <span class='type'>(<tt>*Array</tt>)</span>
2494
+
2495
+
2496
+
2497
+ &mdash;
2498
+ <div class='inline'>
2499
+ <p>parameters with which expected method was invoked.</p>
2500
+ </div>
2501
+
2502
+ </li>
2503
+
2504
+ </ul>
2505
+ <p class="tag_title">Yield Returns:</p>
2506
+ <ul class="yieldreturn">
2507
+
2508
+ <li>
2509
+
2510
+
2511
+ <span class='type'>(<tt>Boolean</tt>)</span>
2512
+
2513
+
2514
+
2515
+ &mdash;
2516
+ <div class='inline'>
2517
+ <p><code>true</code> if <code>actual_parameters</code> are acceptable.</p>
2518
+ </div>
2519
+
2520
+ </li>
2521
+
2522
+ </ul>
2523
+ <p class="tag_title">Returns:</p>
2524
+ <ul class="return">
2525
+
2526
+ <li>
2527
+
2528
+
2529
+ <span class='type'>(<tt><span class='object_link'><a href="" title="Mocha::Expectation (class)">Expectation</a></span></tt>)</span>
2530
+
2531
+
2532
+
2533
+ &mdash;
2534
+ <div class='inline'>
2535
+ <p>the same expectation, thereby allowing invocations of other <span class='object_link'><a href="" title="Mocha::Expectation (class)">Mocha::Expectation</a></span>
2536
+ methods to be chained.</p>
2537
+ </div>
2538
+
2539
+ </li>
2540
+
2541
+ </ul>
2542
+
2543
+ </div><table class="source_code">
2544
+ <tr>
2545
+ <td>
2546
+ <pre class="lines">
2547
+
2548
+
2549
+ 221
2550
+ 222
2551
+ 223
2552
+ 224</pre>
2553
+ </td>
2554
+ <td>
2555
+ <pre class="code"><span class="info file"># File 'lib/mocha/expectation.rb', line 221</span>
2556
+
2557
+ <span class='kw'>def</span> <span class='id identifier rubyid_with'>with</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_expected_parameters'>expected_parameters</span><span class='comma'>,</span> <span class='op'>&amp;</span><span class='id identifier rubyid_matching_block'>matching_block</span><span class='rparen'>)</span>
2558
+ <span class='ivar'>@parameters_matcher</span> <span class='op'>=</span> <span class='const'>ParametersMatcher</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_expected_parameters'>expected_parameters</span><span class='comma'>,</span> <span class='op'>&amp;</span><span class='id identifier rubyid_matching_block'>matching_block</span><span class='rparen'>)</span>
2559
+ <span class='kw'>self</span>
2560
+ <span class='kw'>end</span></pre>
2561
+ </td>
2562
+ </tr>
2563
+ </table>
2564
+ </div>
2565
+
2566
+ <div class="method_details ">
2567
+ <h3 class="signature " id="yields-instance_method">
2568
+
2569
+ #<strong>yields</strong>(*parameters) &#x21d2; <tt><span class='object_link'><a href="" title="Mocha::Expectation (class)">Expectation</a></span></tt>
2570
+
2571
+
2572
+
2573
+
2574
+
2575
+ </h3><div class="docstring">
2576
+ <div class="discussion">
2577
+
2578
+ <p>Modifies expectation so that when the expected method is called, it yields
2579
+ with the specified <code>parameters</code>.</p>
2580
+
2581
+ <p>May be called multiple times on the same expectation for consecutive
2582
+ invocations.</p>
2583
+
2584
+
2585
+ </div>
2586
+ </div>
2587
+ <div class="tags">
2588
+
2589
+ <div class="examples">
2590
+ <p class="tag_title">Examples:</p>
2591
+
2592
+
2593
+ <p class="example_title"><div class='inline'>
2594
+ <p>Yield parameters when expected method is invoked.</p>
2595
+ </div></p>
2596
+
2597
+ <pre class="example code"><code><span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='rparen'>)</span>
2598
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:expected_method</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_yields'>yields</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>result</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>
2599
+ <span class='id identifier rubyid_yielded_value'>yielded_value</span> <span class='op'>=</span> <span class='kw'>nil</span>
2600
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_value'>value</span><span class='op'>|</span> <span class='id identifier rubyid_yielded_value'>yielded_value</span> <span class='op'>=</span> <span class='id identifier rubyid_value'>value</span> <span class='rbrace'>}</span>
2601
+ <span class='id identifier rubyid_yielded_value'>yielded_value</span> <span class='comment'># =&gt; &#39;result&#39;</span></code></pre>
2602
+
2603
+
2604
+ <p class="example_title"><div class='inline'>
2605
+ <p>Yield different parameters on different invocations of the expected method.</p>
2606
+ </div></p>
2607
+
2608
+ <pre class="example code"><code><span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='rparen'>)</span>
2609
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='symbol'>:expected_method</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_yields'>yields</span><span class='lparen'>(</span><span class='int'>1</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_then'>then</span><span class='period'>.</span><span class='id identifier rubyid_yields'>yields</span><span class='lparen'>(</span><span class='int'>2</span><span class='rparen'>)</span>
2610
+ <span class='id identifier rubyid_yielded_values_from_first_invocation'>yielded_values_from_first_invocation</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
2611
+ <span class='id identifier rubyid_yielded_values_from_second_invocation'>yielded_values_from_second_invocation</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
2612
+ <span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_value'>value</span><span class='op'>|</span> <span class='id identifier rubyid_yielded_values_from_first_invocation'>yielded_values_from_first_invocation</span> <span class='op'>&lt;&lt;</span> <span class='id identifier rubyid_value'>value</span> <span class='rbrace'>}</span> <span class='comment'># first invocation
2613
+ </span><span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_value'>value</span><span class='op'>|</span> <span class='id identifier rubyid_yielded_values_from_second_invocation'>yielded_values_from_second_invocation</span> <span class='op'>&lt;&lt;</span> <span class='id identifier rubyid_value'>value</span> <span class='rbrace'>}</span> <span class='comment'># second invocation
2614
+ </span><span class='id identifier rubyid_yielded_values_from_first_invocation'>yielded_values_from_first_invocation</span> <span class='comment'># =&gt; [1]
2615
+ </span><span class='id identifier rubyid_yielded_values_from_second_invocation'>yielded_values_from_second_invocation</span> <span class='comment'># =&gt; [2]</span></code></pre>
2616
+
2617
+ </div>
2618
+ <p class="tag_title">Parameters:</p>
2619
+ <ul class="param">
2620
+
2621
+ <li>
2622
+
2623
+ <span class='name'>parameters</span>
2624
+
2625
+
2626
+ <span class='type'>(<tt>*Array</tt>)</span>
2627
+
2628
+
2629
+
2630
+ &mdash;
2631
+ <div class='inline'>
2632
+ <p>parameters to be yielded.</p>
2633
+ </div>
2634
+
2635
+ </li>
2636
+
2637
+ </ul>
2638
+
2639
+ <p class="tag_title">Returns:</p>
2640
+ <ul class="return">
2641
+
2642
+ <li>
2643
+
2644
+
2645
+ <span class='type'>(<tt><span class='object_link'><a href="" title="Mocha::Expectation (class)">Expectation</a></span></tt>)</span>
2646
+
2647
+
2648
+
2649
+ &mdash;
2650
+ <div class='inline'>
2651
+ <p>the same expectation, thereby allowing invocations of other <span class='object_link'><a href="" title="Mocha::Expectation (class)">Mocha::Expectation</a></span>
2652
+ methods to be chained.</p>
2653
+ </div>
2654
+
2655
+ </li>
2656
+
2657
+ </ul>
2658
+
2659
+ <p class="tag_title">See Also:</p>
2660
+ <ul class="see">
2661
+
2662
+ <li><span class='object_link'><a href="#then-instance_method" title="Mocha::Expectation#then (method)">#then</a></span></li>
2663
+
2664
+ </ul>
2665
+
2666
+ </div><table class="source_code">
2667
+ <tr>
2668
+ <td>
2669
+ <pre class="lines">
2670
+
2671
+
2672
+ 250
2673
+ 251
2674
+ 252
2675
+ 253</pre>
2676
+ </td>
2677
+ <td>
2678
+ <pre class="code"><span class="info file"># File 'lib/mocha/expectation.rb', line 250</span>
2679
+
2680
+ <span class='kw'>def</span> <span class='id identifier rubyid_yields'>yields</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_parameters'>parameters</span><span class='rparen'>)</span>
2681
+ <span class='ivar'>@yield_parameters</span><span class='period'>.</span><span class='id identifier rubyid_add'>add</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_parameters'>parameters</span><span class='rparen'>)</span>
2682
+ <span class='kw'>self</span>
2683
+ <span class='kw'>end</span></pre>
2684
+ </td>
2685
+ </tr>
2686
+ </table>
2687
+ </div>
2688
+
2689
+ </div>
2690
+
2691
+ <script async src="https://www.googletagmanager.com/gtag/js?id=UA-625523-7"></script>
2692
+ <script>
2693
+ window.dataLayer = window.dataLayer || [];
2694
+ function gtag(){dataLayer.push(arguments);}
2695
+ gtag('js', new Date());
2696
+
2697
+ gtag('config', 'UA-625523-7');
2698
+ </script>
2699
+ </div>
2700
+
2701
+ <div id="footer">
2702
+ Generated on Tue Jan 15 17:13:06 2019 by
2703
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
2704
+ 0.9.16 (ruby-2.5.3).
2705
+ </div>
2706
+
2707
+ </div>
2708
+ </body>
2709
+ </html>