mocha 1.10.2 → 1.13.0

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