mocha 1.11.2 → 1.12.0

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