mocha 0.11.3 → 0.11.4

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