mocha 1.8.0 → 1.13.0

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