mocha 1.11.2 → 1.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (200) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +1 -1
  3. data/README.md +28 -30
  4. data/RELEASE.md +25 -0
  5. data/Rakefile +6 -1
  6. data/lib/mocha/cardinality.rb +30 -27
  7. data/lib/mocha/expectation.rb +24 -24
  8. data/lib/mocha/mock.rb +1 -1
  9. data/lib/mocha/mockery.rb +9 -22
  10. data/lib/mocha/state_machine.rb +30 -38
  11. data/lib/mocha/version.rb +1 -1
  12. data/mocha.gemspec +3 -1
  13. metadata +5 -192
  14. data/docs/CNAME +0 -1
  15. data/docs/Mocha.html +0 -254
  16. data/docs/Mocha/API.html +0 -1285
  17. data/docs/Mocha/ClassMethods.html +0 -264
  18. data/docs/Mocha/Configuration.html +0 -1525
  19. data/docs/Mocha/Expectation.html +0 -2862
  20. data/docs/Mocha/ExpectationError.html +0 -152
  21. data/docs/Mocha/ExpectationErrorFactory.html +0 -260
  22. data/docs/Mocha/Hooks.html +0 -370
  23. data/docs/Mocha/Integration.html +0 -125
  24. data/docs/Mocha/Integration/MiniTest.html +0 -123
  25. data/docs/Mocha/Integration/MiniTest/Adapter.html +0 -164
  26. data/docs/Mocha/Integration/TestUnit.html +0 -123
  27. data/docs/Mocha/Integration/TestUnit/Adapter.html +0 -164
  28. data/docs/Mocha/Mock.html +0 -1210
  29. data/docs/Mocha/ObjectMethods.html +0 -765
  30. data/docs/Mocha/ParameterMatchers.html +0 -2949
  31. data/docs/Mocha/ParameterMatchers/AllOf.html +0 -153
  32. data/docs/Mocha/ParameterMatchers/AnyOf.html +0 -153
  33. data/docs/Mocha/ParameterMatchers/AnyParameters.html +0 -153
  34. data/docs/Mocha/ParameterMatchers/Anything.html +0 -153
  35. data/docs/Mocha/ParameterMatchers/Base.html +0 -441
  36. data/docs/Mocha/ParameterMatchers/Equals.html +0 -153
  37. data/docs/Mocha/ParameterMatchers/EquivalentUri.html +0 -153
  38. data/docs/Mocha/ParameterMatchers/HasEntries.html +0 -153
  39. data/docs/Mocha/ParameterMatchers/HasEntry.html +0 -153
  40. data/docs/Mocha/ParameterMatchers/HasKey.html +0 -153
  41. data/docs/Mocha/ParameterMatchers/HasValue.html +0 -153
  42. data/docs/Mocha/ParameterMatchers/Includes.html +0 -153
  43. data/docs/Mocha/ParameterMatchers/InstanceOf.html +0 -153
  44. data/docs/Mocha/ParameterMatchers/IsA.html +0 -153
  45. data/docs/Mocha/ParameterMatchers/KindOf.html +0 -153
  46. data/docs/Mocha/ParameterMatchers/Not.html +0 -153
  47. data/docs/Mocha/ParameterMatchers/Optionally.html +0 -153
  48. data/docs/Mocha/ParameterMatchers/RegexpMatches.html +0 -153
  49. data/docs/Mocha/ParameterMatchers/RespondsWith.html +0 -153
  50. data/docs/Mocha/ParameterMatchers/YamlEquivalent.html +0 -153
  51. data/docs/Mocha/Sequence.html +0 -149
  52. data/docs/Mocha/StateMachine.html +0 -527
  53. data/docs/Mocha/StateMachine/State.html +0 -140
  54. data/docs/Mocha/StateMachine/StatePredicate.html +0 -140
  55. data/docs/Mocha/StubbingError.html +0 -150
  56. data/docs/_index.html +0 -519
  57. data/docs/class_list.html +0 -51
  58. data/docs/css/common.css +0 -1
  59. data/docs/css/full_list.css +0 -58
  60. data/docs/css/style.css +0 -496
  61. data/docs/file.COPYING.html +0 -81
  62. data/docs/file.MIT-LICENSE.html +0 -85
  63. data/docs/file.README.html +0 -448
  64. data/docs/file.RELEASE.html +0 -1028
  65. data/docs/file_list.html +0 -71
  66. data/docs/frames.html +0 -17
  67. data/docs/index.html +0 -448
  68. data/docs/js/app.js +0 -303
  69. data/docs/js/full_list.js +0 -216
  70. data/docs/js/jquery.js +0 -4
  71. data/docs/method_list.html +0 -651
  72. data/docs/top-level-namespace.html +0 -118
  73. data/test/acceptance/acceptance_test_helper.rb +0 -42
  74. data/test/acceptance/bug_18914_test.rb +0 -37
  75. data/test/acceptance/bug_21465_test.rb +0 -31
  76. data/test/acceptance/bug_21563_test.rb +0 -22
  77. data/test/acceptance/display_matching_invocations_alongside_expectations_test.rb +0 -69
  78. data/test/acceptance/exception_rescue_test.rb +0 -53
  79. data/test/acceptance/expectations_on_multiple_methods_test.rb +0 -55
  80. data/test/acceptance/expected_invocation_count_test.rb +0 -229
  81. data/test/acceptance/failure_messages_test.rb +0 -77
  82. data/test/acceptance/issue_272_test.rb +0 -50
  83. data/test/acceptance/issue_457_test.rb +0 -31
  84. data/test/acceptance/issue_65_test.rb +0 -64
  85. data/test/acceptance/issue_70_test.rb +0 -53
  86. data/test/acceptance/mocha_example_test.rb +0 -106
  87. data/test/acceptance/mocha_test_result_test.rb +0 -83
  88. data/test/acceptance/mock_built_with_first_argument_type_being_string_test.rb +0 -98
  89. data/test/acceptance/mock_test.rb +0 -191
  90. data/test/acceptance/mocked_methods_dispatch_test.rb +0 -75
  91. data/test/acceptance/multiple_expectations_failure_message_test.rb +0 -66
  92. data/test/acceptance/multiple_yielding_test.rb +0 -59
  93. data/test/acceptance/optional_parameters_test.rb +0 -67
  94. data/test/acceptance/parameter_matcher_test.rb +0 -299
  95. data/test/acceptance/partial_mocks_test.rb +0 -44
  96. data/test/acceptance/prepend_test.rb +0 -86
  97. data/test/acceptance/prevent_use_of_mocha_outside_test_test.rb +0 -76
  98. data/test/acceptance/raise_exception_test.rb +0 -36
  99. data/test/acceptance/return_value_test.rb +0 -49
  100. data/test/acceptance/sequence_test.rb +0 -189
  101. data/test/acceptance/states_test.rb +0 -71
  102. data/test/acceptance/stub_any_instance_method_defined_on_superclass_test.rb +0 -64
  103. data/test/acceptance/stub_any_instance_method_test.rb +0 -301
  104. data/test/acceptance/stub_class_method_defined_on_active_record_association_proxy_test.rb +0 -105
  105. data/test/acceptance/stub_class_method_defined_on_class_test.rb +0 -78
  106. data/test/acceptance/stub_class_method_defined_on_module_test.rb +0 -73
  107. data/test/acceptance/stub_class_method_defined_on_superclass_test.rb +0 -144
  108. data/test/acceptance/stub_everything_test.rb +0 -53
  109. data/test/acceptance/stub_instance_method_defined_on_active_record_association_proxy_test.rb +0 -91
  110. data/test/acceptance/stub_instance_method_defined_on_class_and_aliased_test.rb +0 -67
  111. data/test/acceptance/stub_instance_method_defined_on_class_test.rb +0 -67
  112. data/test/acceptance/stub_instance_method_defined_on_kernel_module_test.rb +0 -136
  113. data/test/acceptance/stub_instance_method_defined_on_module_test.rb +0 -76
  114. data/test/acceptance/stub_instance_method_defined_on_object_class_test.rb +0 -75
  115. data/test/acceptance/stub_instance_method_defined_on_singleton_class_test.rb +0 -67
  116. data/test/acceptance/stub_instance_method_defined_on_superclass_test.rb +0 -70
  117. data/test/acceptance/stub_method_defined_on_module_and_aliased_test.rb +0 -38
  118. data/test/acceptance/stub_module_method_test.rb +0 -200
  119. data/test/acceptance/stub_test.rb +0 -49
  120. data/test/acceptance/stubba_example_test.rb +0 -103
  121. data/test/acceptance/stubba_test_result_test.rb +0 -71
  122. data/test/acceptance/stubbing_error_backtrace_test.rb +0 -63
  123. data/test/acceptance/stubbing_frozen_object_test.rb +0 -88
  124. data/test/acceptance/stubbing_method_accepting_block_parameter_test.rb +0 -52
  125. data/test/acceptance/stubbing_method_unnecessarily_test.rb +0 -63
  126. data/test/acceptance/stubbing_nil_test.rb +0 -60
  127. data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +0 -157
  128. data/test/acceptance/stubbing_non_existent_class_method_test.rb +0 -157
  129. data/test/acceptance/stubbing_non_existent_instance_method_test.rb +0 -145
  130. data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +0 -128
  131. data/test/acceptance/stubbing_non_public_class_method_test.rb +0 -163
  132. data/test/acceptance/stubbing_non_public_instance_method_test.rb +0 -141
  133. data/test/acceptance/stubbing_on_non_mock_object_test.rb +0 -70
  134. data/test/acceptance/stubbing_same_class_method_on_parent_and_child_classes_test.rb +0 -33
  135. data/test/acceptance/throw_test.rb +0 -42
  136. data/test/acceptance/unexpected_invocation_test.rb +0 -23
  137. data/test/acceptance/unstubbing_test.rb +0 -194
  138. data/test/acceptance/yielding_test.rb +0 -80
  139. data/test/assertions.rb +0 -8
  140. data/test/deprecation_disabler.rb +0 -15
  141. data/test/execution_point.rb +0 -36
  142. data/test/integration/mini_test_test.rb +0 -8
  143. data/test/integration/shared_tests.rb +0 -178
  144. data/test/integration/test_unit_test.rb +0 -8
  145. data/test/method_definer.rb +0 -16
  146. data/test/mini_test_result.rb +0 -96
  147. data/test/minitest_result.rb +0 -48
  148. data/test/simple_counter.rb +0 -11
  149. data/test/test_helper.rb +0 -58
  150. data/test/test_runner.rb +0 -58
  151. data/test/test_unit_result.rb +0 -22
  152. data/test/unit/any_instance_method_test.rb +0 -175
  153. data/test/unit/array_inspect_test.rb +0 -14
  154. data/test/unit/backtrace_filter_test.rb +0 -17
  155. data/test/unit/cardinality_test.rb +0 -72
  156. data/test/unit/central_test.rb +0 -98
  157. data/test/unit/change_state_side_effect_test.rb +0 -37
  158. data/test/unit/class_methods_test.rb +0 -69
  159. data/test/unit/configuration_test.rb +0 -37
  160. data/test/unit/date_time_inspect_test.rb +0 -19
  161. data/test/unit/exception_raiser_test.rb +0 -45
  162. data/test/unit/expectation_list_test.rb +0 -82
  163. data/test/unit/expectation_test.rb +0 -504
  164. data/test/unit/hash_inspect_test.rb +0 -14
  165. data/test/unit/hooks_test.rb +0 -35
  166. data/test/unit/in_state_ordering_constraint_test.rb +0 -39
  167. data/test/unit/instance_method_test.rb +0 -282
  168. data/test/unit/method_matcher_test.rb +0 -26
  169. data/test/unit/mock_test.rb +0 -372
  170. data/test/unit/mockery_test.rb +0 -171
  171. data/test/unit/module_methods_test.rb +0 -16
  172. data/test/unit/object_inspect_test.rb +0 -60
  173. data/test/unit/object_methods_test.rb +0 -63
  174. data/test/unit/parameter_matchers/all_of_test.rb +0 -24
  175. data/test/unit/parameter_matchers/any_of_test.rb +0 -24
  176. data/test/unit/parameter_matchers/anything_test.rb +0 -19
  177. data/test/unit/parameter_matchers/equals_test.rb +0 -23
  178. data/test/unit/parameter_matchers/equivalent_uri_test.rb +0 -41
  179. data/test/unit/parameter_matchers/has_entries_test.rb +0 -51
  180. data/test/unit/parameter_matchers/has_entry_test.rb +0 -128
  181. data/test/unit/parameter_matchers/has_key_test.rb +0 -54
  182. data/test/unit/parameter_matchers/has_value_test.rb +0 -55
  183. data/test/unit/parameter_matchers/includes_test.rb +0 -106
  184. data/test/unit/parameter_matchers/instance_of_test.rb +0 -23
  185. data/test/unit/parameter_matchers/is_a_test.rb +0 -23
  186. data/test/unit/parameter_matchers/kind_of_test.rb +0 -23
  187. data/test/unit/parameter_matchers/not_test.rb +0 -24
  188. data/test/unit/parameter_matchers/regexp_matches_test.rb +0 -45
  189. data/test/unit/parameter_matchers/responds_with_test.rb +0 -38
  190. data/test/unit/parameter_matchers/stub_matcher.rb +0 -23
  191. data/test/unit/parameter_matchers/yaml_equivalent_test.rb +0 -23
  192. data/test/unit/parameters_matcher_test.rb +0 -119
  193. data/test/unit/receivers_test.rb +0 -96
  194. data/test/unit/return_values_test.rb +0 -66
  195. data/test/unit/sequence_test.rb +0 -100
  196. data/test/unit/single_return_value_test.rb +0 -17
  197. data/test/unit/state_machine_test.rb +0 -96
  198. data/test/unit/string_inspect_test.rb +0 -9
  199. data/test/unit/thrower_test.rb +0 -23
  200. data/test/unit/yield_parameters_test.rb +0 -73
@@ -1,264 +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
- Module: Mocha::ClassMethods
8
-
9
- &mdash; Mocha 1.11.2
10
-
11
- </title>
12
-
13
- <link rel="stylesheet" href="../css/style.css" type="text/css" charset="utf-8" />
14
-
15
- <link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8" />
16
-
17
- <script type="text/javascript" charset="utf-8">
18
- pathId = "Mocha::ClassMethods";
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 (C)</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">ClassMethods</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>Module: Mocha::ClassMethods
63
-
64
-
65
-
66
- </h1>
67
- <div class="box_info">
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-
78
-
79
- <dl>
80
- <dt>Defined in:</dt>
81
- <dd>lib/mocha/class_methods.rb</dd>
82
- </dl>
83
-
84
- </div>
85
-
86
- <h2>Overview</h2><div class="docstring">
87
- <div class="discussion">
88
-
89
- <p>Methods added to all classes to allow mocking and stubbing on real (i.e. non-mock) objects.</p>
90
-
91
-
92
- </div>
93
- </div>
94
- <div class="tags">
95
-
96
-
97
- </div>
98
-
99
-
100
-
101
-
102
-
103
-
104
-
105
- <h2>
106
- Instance Method Summary
107
- <small><a href="#" class="summary_toggle">collapse</a></small>
108
- </h2>
109
-
110
- <ul class="summary">
111
-
112
- <li class="public ">
113
- <span class="summary_signature">
114
-
115
- <a href="#any_instance-instance_method" title="#any_instance (instance method)">#<strong>any_instance</strong> &#x21d2; Mock </a>
116
-
117
-
118
-
119
- </span>
120
-
121
-
122
-
123
-
124
-
125
-
126
-
127
-
128
-
129
- <span class="summary_desc"><div class='inline'>
130
- <p>A mock object which will detect calls to any instance of this class.</p>
131
- </div></span>
132
-
133
- </li>
134
-
135
-
136
- </ul>
137
-
138
-
139
-
140
-
141
- <div id="instance_method_details" class="method_details_list">
142
- <h2>Instance Method Details</h2>
143
-
144
-
145
- <div class="method_details first">
146
- <h3 class="signature first" id="any_instance-instance_method">
147
-
148
- #<strong>any_instance</strong> &#x21d2; <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt>
149
-
150
-
151
-
152
-
153
-
154
- </h3><div class="docstring">
155
- <div class="discussion">
156
-
157
- <p>Returns a mock object which will detect calls to any instance of this class.</p>
158
-
159
-
160
- </div>
161
- </div>
162
- <div class="tags">
163
-
164
- <div class="examples">
165
- <p class="tag_title">Examples:</p>
166
-
167
-
168
- <p class="example_title"><div class='inline'>
169
- <p>Return false to invocation of <tt>Product#save</tt> for any instance of <code>Product</code>.</p>
170
- </div></p>
171
-
172
- <pre class="example code"><code><span class='const'>Product</span><span class='period'>.</span><span class='id identifier rubyid_any_instance'>any_instance</span><span class='period'>.</span><span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='symbol'>:save</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_returns'>returns</span><span class='lparen'>(</span><span class='kw'>false</span><span class='rparen'>)</span>
173
- <span class='id identifier rubyid_product_1'>product_1</span> <span class='op'>=</span> <span class='const'>Product</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
174
- <span class='id identifier rubyid_assert_equal'>assert_equal</span> <span class='kw'>false</span><span class='comma'>,</span> <span class='id identifier rubyid_product_1'>product_1</span><span class='period'>.</span><span class='id identifier rubyid_save'>save</span>
175
- <span class='id identifier rubyid_product_2'>product_2</span> <span class='op'>=</span> <span class='const'>Product</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
176
- <span class='id identifier rubyid_assert_equal'>assert_equal</span> <span class='kw'>false</span><span class='comma'>,</span> <span class='id identifier rubyid_product_2'>product_2</span><span class='period'>.</span><span class='id identifier rubyid_save'>save</span></code></pre>
177
-
178
- </div>
179
-
180
- <p class="tag_title">Returns:</p>
181
- <ul class="return">
182
-
183
- <li>
184
-
185
-
186
- <span class='type'>(<tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt>)</span>
187
-
188
-
189
-
190
- &mdash;
191
- <div class='inline'>
192
- <p>a mock object which will detect calls to any instance of this class.</p>
193
- </div>
194
-
195
- </li>
196
-
197
- </ul>
198
- <p class="tag_title">Raises:</p>
199
- <ul class="raise">
200
-
201
- <li>
202
-
203
-
204
- <span class='type'>(<tt><span class='object_link'><a href="StubbingError.html" title="Mocha::StubbingError (class)">StubbingError</a></span></tt>)</span>
205
-
206
-
207
-
208
- &mdash;
209
- <div class='inline'>
210
- <p>if attempting to stub method which is not allowed.</p>
211
- </div>
212
-
213
- </li>
214
-
215
- </ul>
216
-
217
- </div><table class="source_code">
218
- <tr>
219
- <td>
220
- <pre class="lines">
221
-
222
-
223
- 45
224
- 46
225
- 47
226
- 48
227
- 49
228
- 50</pre>
229
- </td>
230
- <td>
231
- <pre class="code"><span class="info file"># File 'lib/mocha/class_methods.rb', line 45</span>
232
-
233
- <span class='kw'>def</span> <span class='id identifier rubyid_any_instance'>any_instance</span>
234
- <span class='kw'>if</span> <span class='id identifier rubyid_frozen?'>frozen?</span>
235
- <span class='id identifier rubyid_raise'>raise</span> <span class='const'><span class='object_link'><a href="StubbingError.html" title="Mocha::StubbingError (class)">StubbingError</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>can&#39;t stub method on frozen object: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_mocha_inspect'>mocha_inspect</span><span class='embexpr_end'>}</span><span class='tstring_content'>.any_instance</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='id identifier rubyid_caller'>caller</span><span class='rparen'>)</span>
236
- <span class='kw'>end</span>
237
- <span class='ivar'>@any_instance</span> <span class='op'>||=</span> <span class='const'>AnyInstance</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='kw'>self</span><span class='rparen'>)</span>
238
- <span class='kw'>end</span></pre>
239
- </td>
240
- </tr>
241
- </table>
242
- </div>
243
-
244
- </div>
245
-
246
- <script async src="https://www.googletagmanager.com/gtag/js?id=UA-625523-7"></script>
247
- <script>
248
- window.dataLayer = window.dataLayer || [];
249
- function gtag(){dataLayer.push(arguments);}
250
- gtag('js', new Date());
251
-
252
- gtag('config', 'UA-625523-7');
253
- </script>
254
- </div>
255
-
256
- <div id="footer">
257
- Generated on Sat Jan 4 17:36:47 2020 by
258
- <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
259
- 0.9.20 (ruby-2.6.5).
260
- </div>
261
-
262
- </div>
263
- </body>
264
- </html>
@@ -1,1525 +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::Configuration
8
-
9
- &mdash; Mocha 1.11.2
10
-
11
- </title>
12
-
13
- <link rel="stylesheet" href="../css/style.css" type="text/css" charset="utf-8" />
14
-
15
- <link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8" />
16
-
17
- <script type="text/javascript" charset="utf-8">
18
- pathId = "Mocha::Configuration";
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 (C)</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">Configuration</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::Configuration
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::Configuration</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/configuration.rb</dd>
98
- </dl>
99
-
100
- </div>
101
-
102
- <h2>Overview</h2><div class="docstring">
103
- <div class="discussion">
104
-
105
- <p>This class provides a number of ways to configure the library.</p>
106
-
107
- <p>Typically the configuration is set globally in a <code>test_helper.rb</code> or <code>spec_helper.rb</code> file.</p>
108
-
109
-
110
- </div>
111
- </div>
112
- <div class="tags">
113
-
114
- <div class="examples">
115
- <p class="tag_title">Examples:</p>
116
-
117
-
118
- <p class="example_title"><div class='inline'>
119
- <p>Setting multiple configuration options</p>
120
- </div></p>
121
-
122
- <pre class="example code"><code><span class='const'><span class='object_link'><a href="../Mocha.html" title="Mocha (module)">Mocha</a></span></span><span class='period'>.</span><span class='id identifier rubyid_configure'><span class='object_link'><a href="../Mocha.html#configure-class_method" title="Mocha.configure (method)">configure</a></span></span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_c'>c</span><span class='op'>|</span>
123
- <span class='id identifier rubyid_c'>c</span><span class='period'>.</span><span class='id identifier rubyid_stubbing_method_unnecessarily'>stubbing_method_unnecessarily</span> <span class='op'>=</span> <span class='symbol'>:prevent</span>
124
- <span class='id identifier rubyid_c'>c</span><span class='period'>.</span><span class='id identifier rubyid_stubbing_method_on_non_mock_object'>stubbing_method_on_non_mock_object</span> <span class='op'>=</span> <span class='symbol'>:warn</span>
125
- <span class='id identifier rubyid_c'>c</span><span class='period'>.</span><span class='id identifier rubyid_stubbing_method_on_nil'>stubbing_method_on_nil</span> <span class='op'>=</span> <span class='symbol'>:allow</span>
126
- <span class='kw'>end</span></code></pre>
127
-
128
- </div>
129
-
130
-
131
- </div>
132
-
133
-
134
-
135
-
136
-
137
-
138
-
139
- <h2>
140
- Class Method Summary
141
- <small><a href="#" class="summary_toggle">collapse</a></small>
142
- </h2>
143
-
144
- <ul class="summary">
145
-
146
- <li class="public deprecated">
147
- <span class="summary_signature">
148
-
149
- <a href="#allow-class_method" title="allow (class method)">.<strong>allow</strong>(action) { ... } &#x21d2; Object </a>
150
-
151
-
152
-
153
- </span>
154
-
155
-
156
-
157
-
158
-
159
- <span class="deprecated note title">deprecated</span>
160
-
161
-
162
-
163
- <span class="summary_desc"><strong>Deprecated.</strong> <div class='inline'>
164
- <p>If a block is supplied, call <span class='object_link'><a href="#override-class_method" title="Mocha::Configuration.override (method)">Configuration.override</a></span> with a <code>Hash</code> containing an entry with the <code>action</code> as the key and <code>:allow</code> as the value. If no block is supplied, call the appropriate <code>action</code> writer method with <code>value</code> set to <code>:allow</code> via <span class='object_link'><a href="../Mocha.html#configure-class_method" title="Mocha.configure (method)">configure</a></span>. The writer method will be the one of the following corresponding to the <code>action</code>:</p>
165
- <ul><li>
166
- <p><span class='object_link'><a href="#stubbing_method_unnecessarily=-instance_method" title="Mocha::Configuration#stubbing_method_unnecessarily= (method)">#stubbing_method_unnecessarily=</a></span></p>
167
- </li><li>
168
- <p><span class='object_link'><a href="#stubbing_method_on_non_mock_object=-instance_method" title="Mocha::Configuration#stubbing_method_on_non_mock_object= (method)">#stubbing_method_on_non_mock_object=</a></span></p>
169
- </li><li>
170
- <p><span class='object_link'><a href="#stubbing_non_existent_method=-instance_method" title="Mocha::Configuration#stubbing_non_existent_method= (method)">#stubbing_non_existent_method=</a></span></p>
171
- </li><li>
172
- <p><span class='object_link'><a href="#stubbing_non_public_method=-instance_method" title="Mocha::Configuration#stubbing_non_public_method= (method)">#stubbing_non_public_method=</a></span></p>
173
- </li><li>
174
- <p><span class='object_link'><a href="#stubbing_method_on_nil=-instance_method" title="Mocha::Configuration#stubbing_method_on_nil= (method)">#stubbing_method_on_nil=</a></span></p>
175
- </li></ul>
176
- </div></span>
177
-
178
- </li>
179
-
180
-
181
- <li class="public ">
182
- <span class="summary_signature">
183
-
184
- <a href="#override-class_method" title="override (class method)">.<strong>override</strong>(temporary_options) { ... } &#x21d2; Object </a>
185
-
186
-
187
-
188
- </span>
189
-
190
-
191
-
192
-
193
-
194
-
195
-
196
-
197
-
198
- <span class="summary_desc"><div class='inline'>
199
- <p>Temporarily modify <span class='object_link'><a href="" title="Mocha::Configuration (class)">Configuration</a></span> options.</p>
200
- </div></span>
201
-
202
- </li>
203
-
204
-
205
- <li class="public deprecated">
206
- <span class="summary_signature">
207
-
208
- <a href="#prevent-class_method" title="prevent (class method)">.<strong>prevent</strong>(action) { ... } &#x21d2; Object </a>
209
-
210
-
211
-
212
- </span>
213
-
214
-
215
-
216
-
217
-
218
- <span class="deprecated note title">deprecated</span>
219
-
220
-
221
-
222
- <span class="summary_desc"><strong>Deprecated.</strong> <div class='inline'>
223
- <p>If a block is supplied, call <span class='object_link'><a href="#override-class_method" title="Mocha::Configuration.override (method)">Configuration.override</a></span> with a <code>Hash</code> containing an entry with the <code>action</code> as the key and <code>:prevent</code> as the value. If no block is supplied, call the appropriate <code>action</code> writer method with <code>value</code> set to <code>:prevent</code> via <span class='object_link'><a href="../Mocha.html#configure-class_method" title="Mocha.configure (method)">configure</a></span>. The writer method will be the one of the following corresponding to the <code>action</code>:</p>
224
- <ul><li>
225
- <p><span class='object_link'><a href="#stubbing_method_unnecessarily=-instance_method" title="Mocha::Configuration#stubbing_method_unnecessarily= (method)">#stubbing_method_unnecessarily=</a></span></p>
226
- </li><li>
227
- <p><span class='object_link'><a href="#stubbing_method_on_non_mock_object=-instance_method" title="Mocha::Configuration#stubbing_method_on_non_mock_object= (method)">#stubbing_method_on_non_mock_object=</a></span></p>
228
- </li><li>
229
- <p><span class='object_link'><a href="#stubbing_non_existent_method=-instance_method" title="Mocha::Configuration#stubbing_non_existent_method= (method)">#stubbing_non_existent_method=</a></span></p>
230
- </li><li>
231
- <p><span class='object_link'><a href="#stubbing_non_public_method=-instance_method" title="Mocha::Configuration#stubbing_non_public_method= (method)">#stubbing_non_public_method=</a></span></p>
232
- </li><li>
233
- <p><span class='object_link'><a href="#stubbing_method_on_nil=-instance_method" title="Mocha::Configuration#stubbing_method_on_nil= (method)">#stubbing_method_on_nil=</a></span></p>
234
- </li></ul>
235
- </div></span>
236
-
237
- </li>
238
-
239
-
240
- <li class="public deprecated">
241
- <span class="summary_signature">
242
-
243
- <a href="#warn_when-class_method" title="warn_when (class method)">.<strong>warn_when</strong>(action) { ... } &#x21d2; Object </a>
244
-
245
-
246
-
247
- </span>
248
-
249
-
250
-
251
-
252
-
253
- <span class="deprecated note title">deprecated</span>
254
-
255
-
256
-
257
- <span class="summary_desc"><strong>Deprecated.</strong> <div class='inline'>
258
- <p>If a block is supplied, call <span class='object_link'><a href="#override-class_method" title="Mocha::Configuration.override (method)">Configuration.override</a></span> with a <code>Hash</code> containing an entry with the <code>action</code> as the key and <code>:warn</code> as the value. If no block is supplied, call the appropriate <code>action</code> writer method with <code>value</code> set to <code>:warn</code> via <span class='object_link'><a href="../Mocha.html#configure-class_method" title="Mocha.configure (method)">configure</a></span>. The writer method will be the one of the following corresponding to the <code>action</code>:</p>
259
- <ul><li>
260
- <p><span class='object_link'><a href="#stubbing_method_unnecessarily=-instance_method" title="Mocha::Configuration#stubbing_method_unnecessarily= (method)">#stubbing_method_unnecessarily=</a></span></p>
261
- </li><li>
262
- <p><span class='object_link'><a href="#stubbing_method_on_non_mock_object=-instance_method" title="Mocha::Configuration#stubbing_method_on_non_mock_object= (method)">#stubbing_method_on_non_mock_object=</a></span></p>
263
- </li><li>
264
- <p><span class='object_link'><a href="#stubbing_non_existent_method=-instance_method" title="Mocha::Configuration#stubbing_non_existent_method= (method)">#stubbing_non_existent_method=</a></span></p>
265
- </li><li>
266
- <p><span class='object_link'><a href="#stubbing_non_public_method=-instance_method" title="Mocha::Configuration#stubbing_non_public_method= (method)">#stubbing_non_public_method=</a></span></p>
267
- </li><li>
268
- <p><span class='object_link'><a href="#stubbing_method_on_nil=-instance_method" title="Mocha::Configuration#stubbing_method_on_nil= (method)">#stubbing_method_on_nil=</a></span></p>
269
- </li></ul>
270
- </div></span>
271
-
272
- </li>
273
-
274
-
275
- </ul>
276
-
277
- <h2>
278
- Instance Method Summary
279
- <small><a href="#" class="summary_toggle">collapse</a></small>
280
- </h2>
281
-
282
- <ul class="summary">
283
-
284
- <li class="public ">
285
- <span class="summary_signature">
286
-
287
- <a href="#display_matching_invocations_on_failure=-instance_method" title="#display_matching_invocations_on_failure= (instance method)">#<strong>display_matching_invocations_on_failure=</strong>(value) &#x21d2; Object </a>
288
-
289
-
290
-
291
- </span>
292
-
293
-
294
-
295
-
296
-
297
-
298
-
299
-
300
-
301
- <span class="summary_desc"><div class='inline'>
302
- <p>Display matching invocations alongside expectations on Mocha-related test failure.</p>
303
- </div></span>
304
-
305
- </li>
306
-
307
-
308
- <li class="public ">
309
- <span class="summary_signature">
310
-
311
- <a href="#reinstate_undocumented_behaviour_from_v1_9=-instance_method" title="#reinstate_undocumented_behaviour_from_v1_9= (instance method)">#<strong>reinstate_undocumented_behaviour_from_v1_9=</strong>(value) &#x21d2; Object </a>
312
-
313
-
314
-
315
- </span>
316
-
317
-
318
-
319
-
320
-
321
-
322
-
323
-
324
-
325
- <span class="summary_desc"><div class='inline'>
326
- <p>Reinstate undocumented behaviour from v1.9.</p>
327
- </div></span>
328
-
329
- </li>
330
-
331
-
332
- <li class="public ">
333
- <span class="summary_signature">
334
-
335
- <a href="#stubbing_method_on_nil=-instance_method" title="#stubbing_method_on_nil= (instance method)">#<strong>stubbing_method_on_nil=</strong>(value) &#x21d2; Object </a>
336
-
337
-
338
-
339
- </span>
340
-
341
-
342
-
343
-
344
-
345
-
346
-
347
-
348
-
349
- <span class="summary_desc"><div class='inline'>
350
- <p>Configure whether stubbing methods on the <code>nil</code> object is allowed.</p>
351
- </div></span>
352
-
353
- </li>
354
-
355
-
356
- <li class="public ">
357
- <span class="summary_signature">
358
-
359
- <a href="#stubbing_method_on_non_mock_object=-instance_method" title="#stubbing_method_on_non_mock_object= (instance method)">#<strong>stubbing_method_on_non_mock_object=</strong>(value) &#x21d2; Object </a>
360
-
361
-
362
-
363
- </span>
364
-
365
-
366
-
367
-
368
-
369
-
370
-
371
-
372
-
373
- <span class="summary_desc"><div class='inline'>
374
- <p>Configure whether stubbing methods on non-mock objects is allowed.</p>
375
- </div></span>
376
-
377
- </li>
378
-
379
-
380
- <li class="public ">
381
- <span class="summary_signature">
382
-
383
- <a href="#stubbing_method_unnecessarily=-instance_method" title="#stubbing_method_unnecessarily= (instance method)">#<strong>stubbing_method_unnecessarily=</strong>(value) &#x21d2; Object </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>Configure whether stubbing methods unnecessarily is allowed.</p>
399
- </div></span>
400
-
401
- </li>
402
-
403
-
404
- <li class="public ">
405
- <span class="summary_signature">
406
-
407
- <a href="#stubbing_non_existent_method=-instance_method" title="#stubbing_non_existent_method= (instance method)">#<strong>stubbing_non_existent_method=</strong>(value) &#x21d2; Object </a>
408
-
409
-
410
-
411
- </span>
412
-
413
-
414
-
415
-
416
-
417
-
418
-
419
-
420
-
421
- <span class="summary_desc"><div class='inline'>
422
- <p>Configure whether stubbing of non-existent methods is allowed.</p>
423
- </div></span>
424
-
425
- </li>
426
-
427
-
428
- <li class="public ">
429
- <span class="summary_signature">
430
-
431
- <a href="#stubbing_non_public_method=-instance_method" title="#stubbing_non_public_method= (instance method)">#<strong>stubbing_non_public_method=</strong>(value) &#x21d2; Object </a>
432
-
433
-
434
-
435
- </span>
436
-
437
-
438
-
439
-
440
-
441
-
442
-
443
-
444
-
445
- <span class="summary_desc"><div class='inline'>
446
- <p>Configure whether stubbing of non-public methods is allowed.</p>
447
- </div></span>
448
-
449
- </li>
450
-
451
-
452
- </ul>
453
-
454
-
455
-
456
-
457
- <div id="class_method_details" class="method_details_list">
458
- <h2>Class Method Details</h2>
459
-
460
-
461
- <div class="method_details first">
462
- <h3 class="signature first" id="allow-class_method">
463
-
464
- .<strong>allow</strong>(action) { ... } &#x21d2; <tt><span class='object_link'>Object</span></tt>
465
-
466
-
467
-
468
-
469
-
470
- </h3><div class="docstring">
471
- <div class="discussion">
472
- <div class="note deprecated"><strong>Deprecated.</strong> <div class='inline'>
473
- <p>If a block is supplied, call <span class='object_link'><a href="#override-class_method" title="Mocha::Configuration.override (method)">override</a></span> with a <code>Hash</code> containing an entry with the <code>action</code> as the key and <code>:allow</code> as the value. If no block is supplied, call the appropriate <code>action</code> writer method with <code>value</code> set to <code>:allow</code> via <span class='object_link'><a href="../Mocha.html#configure-class_method" title="Mocha.configure (method)">Mocha.configure</a></span>. The writer method will be the one of the following corresponding to the <code>action</code>:</p>
474
- <ul><li>
475
- <p><span class='object_link'><a href="#stubbing_method_unnecessarily=-instance_method" title="Mocha::Configuration#stubbing_method_unnecessarily= (method)">#stubbing_method_unnecessarily=</a></span></p>
476
- </li><li>
477
- <p><span class='object_link'><a href="#stubbing_method_on_non_mock_object=-instance_method" title="Mocha::Configuration#stubbing_method_on_non_mock_object= (method)">#stubbing_method_on_non_mock_object=</a></span></p>
478
- </li><li>
479
- <p><span class='object_link'><a href="#stubbing_non_existent_method=-instance_method" title="Mocha::Configuration#stubbing_non_existent_method= (method)">#stubbing_non_existent_method=</a></span></p>
480
- </li><li>
481
- <p><span class='object_link'><a href="#stubbing_non_public_method=-instance_method" title="Mocha::Configuration#stubbing_non_public_method= (method)">#stubbing_non_public_method=</a></span></p>
482
- </li><li>
483
- <p><span class='object_link'><a href="#stubbing_method_on_nil=-instance_method" title="Mocha::Configuration#stubbing_method_on_nil= (method)">#stubbing_method_on_nil=</a></span></p>
484
- </li></ul>
485
- </div></div>
486
-
487
- <p>Allow the specified <code>action</code>.</p>
488
-
489
-
490
- </div>
491
- </div>
492
- <div class="tags">
493
- <p class="tag_title">Parameters:</p>
494
- <ul class="param">
495
-
496
- <li>
497
-
498
- <span class='name'>action</span>
499
-
500
-
501
- <span class='type'>(<tt>Symbol</tt>)</span>
502
-
503
-
504
-
505
- &mdash;
506
- <div class='inline'>
507
- <p>one of <code>:stubbing_method_unnecessarily</code>, <code>:stubbing_method_on_non_mock_object</code>, <code>:stubbing_non_existent_method</code>, <code>:stubbing_non_public_method</code>, <code>:stubbing_method_on_nil</code>.</p>
508
- </div>
509
-
510
- </li>
511
-
512
- </ul>
513
-
514
- <p class="tag_title">Yields:</p>
515
- <ul class="yield">
516
-
517
- <li>
518
-
519
-
520
- <span class='type'></span>
521
-
522
-
523
-
524
-
525
- <div class='inline'>
526
- <p>optional block during which the configuration change will be changed before being returned to its original value at the end of the block.</p>
527
- </div>
528
-
529
- </li>
530
-
531
- </ul>
532
-
533
- </div><table class="source_code">
534
- <tr>
535
- <td>
536
- <pre class="lines">
537
-
538
-
539
- 317
540
- 318
541
- 319
542
- 320
543
- 321
544
- 322
545
- 323
546
- 324</pre>
547
- </td>
548
- <td>
549
- <pre class="code"><span class="info file"># File 'lib/mocha/configuration.rb', line 317</span>
550
-
551
- <span class='kw'>def</span> <span class='id identifier rubyid_allow'>allow</span><span class='lparen'>(</span><span class='id identifier rubyid_action'>action</span><span class='comma'>,</span> <span class='op'>&amp;</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
552
- <span class='kw'>if</span> <span class='id identifier rubyid_block_given?'>block_given?</span>
553
- <span class='const'>Deprecation</span><span class='period'>.</span><span class='id identifier rubyid_warning'>warning</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Use Mocha::Configuration.override(</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_action'>action</span><span class='embexpr_end'>}</span><span class='tstring_content'>: :allow) with the same block</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
554
- <span class='kw'>else</span>
555
- <span class='const'>Deprecation</span><span class='period'>.</span><span class='id identifier rubyid_warning'>warning</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Use Mocha.configure { |c| c.</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_action'>action</span><span class='embexpr_end'>}</span><span class='tstring_content'> = :allow }</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
556
- <span class='kw'>end</span>
557
- <span class='id identifier rubyid_change_config'>change_config</span> <span class='id identifier rubyid_action'>action</span><span class='comma'>,</span> <span class='symbol'>:allow</span><span class='comma'>,</span> <span class='op'>&amp;</span><span class='id identifier rubyid_block'>block</span>
558
- <span class='kw'>end</span></pre>
559
- </td>
560
- </tr>
561
- </table>
562
- </div>
563
-
564
- <div class="method_details ">
565
- <h3 class="signature " id="override-class_method">
566
-
567
- .<strong>override</strong>(temporary_options) { ... } &#x21d2; <tt><span class='object_link'>Object</span></tt>
568
-
569
-
570
-
571
-
572
-
573
- </h3><div class="docstring">
574
- <div class="discussion">
575
-
576
- <p>Temporarily modify <span class='object_link'><a href="" title="Mocha::Configuration (class)">Mocha::Configuration</a></span> options.</p>
577
-
578
- <p>The supplied <code>temporary_options</code> will override the current configuration for the duration of the supplied block. The configuration will be returned to its original state when the block returns.</p>
579
-
580
-
581
- </div>
582
- </div>
583
- <div class="tags">
584
-
585
- <div class="examples">
586
- <p class="tag_title">Examples:</p>
587
-
588
-
589
- <p class="example_title"><div class='inline'>
590
- <p>Temporarily allow stubbing of <code>nil</code></p>
591
- </div></p>
592
-
593
- <pre class="example code"><code><span class='const'><span class='object_link'><a href="../Mocha.html" title="Mocha (module)">Mocha</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="" title="Mocha::Configuration (class)">Configuration</a></span></span><span class='period'>.</span><span class='id identifier rubyid_override'>override</span><span class='lparen'>(</span><span class='label'>stubbing_method_on_nil:</span> <span class='symbol'>:allow</span><span class='rparen'>)</span> <span class='kw'>do</span>
594
- <span class='kw'>nil</span><span class='period'>.</span><span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='symbol'>:foo</span><span class='rparen'>)</span>
595
- <span class='kw'>end</span></code></pre>
596
-
597
- </div>
598
- <p class="tag_title">Parameters:</p>
599
- <ul class="param">
600
-
601
- <li>
602
-
603
- <span class='name'>temporary_options</span>
604
-
605
-
606
- <span class='type'>(<tt>Hash</tt>)</span>
607
-
608
-
609
-
610
- &mdash;
611
- <div class='inline'>
612
- <p>the configuration options to apply for the duration of the block.</p>
613
- </div>
614
-
615
- </li>
616
-
617
- </ul>
618
-
619
- <p class="tag_title">Yields:</p>
620
- <ul class="yield">
621
-
622
- <li>
623
-
624
-
625
- <span class='type'></span>
626
-
627
-
628
-
629
-
630
- <div class='inline'>
631
- <p>block during which the configuration change will be in force.</p>
632
- </div>
633
-
634
- </li>
635
-
636
- </ul>
637
-
638
- </div><table class="source_code">
639
- <tr>
640
- <td>
641
- <pre class="lines">
642
-
643
-
644
- 396
645
- 397
646
- 398
647
- 399
648
- 400
649
- 401
650
- 402</pre>
651
- </td>
652
- <td>
653
- <pre class="code"><span class="info file"># File 'lib/mocha/configuration.rb', line 396</span>
654
-
655
- <span class='kw'>def</span> <span class='id identifier rubyid_override'>override</span><span class='lparen'>(</span><span class='id identifier rubyid_temporary_options'>temporary_options</span><span class='rparen'>)</span>
656
- <span class='id identifier rubyid_original_configuration'>original_configuration</span> <span class='op'>=</span> <span class='id identifier rubyid_configuration'>configuration</span>
657
- <span class='ivar'>@configuration</span> <span class='op'>=</span> <span class='id identifier rubyid_configuration'>configuration</span><span class='period'>.</span><span class='id identifier rubyid_merge'>merge</span><span class='lparen'>(</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_temporary_options'>temporary_options</span><span class='rparen'>)</span><span class='rparen'>)</span>
658
- <span class='kw'>yield</span>
659
- <span class='kw'>ensure</span>
660
- <span class='ivar'>@configuration</span> <span class='op'>=</span> <span class='id identifier rubyid_original_configuration'>original_configuration</span>
661
- <span class='kw'>end</span></pre>
662
- </td>
663
- </tr>
664
- </table>
665
- </div>
666
-
667
- <div class="method_details ">
668
- <h3 class="signature " id="prevent-class_method">
669
-
670
- .<strong>prevent</strong>(action) { ... } &#x21d2; <tt><span class='object_link'>Object</span></tt>
671
-
672
-
673
-
674
-
675
-
676
- </h3><div class="docstring">
677
- <div class="discussion">
678
- <div class="note deprecated"><strong>Deprecated.</strong> <div class='inline'>
679
- <p>If a block is supplied, call <span class='object_link'><a href="#override-class_method" title="Mocha::Configuration.override (method)">override</a></span> with a <code>Hash</code> containing an entry with the <code>action</code> as the key and <code>:prevent</code> as the value. If no block is supplied, call the appropriate <code>action</code> writer method with <code>value</code> set to <code>:prevent</code> via <span class='object_link'><a href="../Mocha.html#configure-class_method" title="Mocha.configure (method)">Mocha.configure</a></span>. The writer method will be the one of the following corresponding to the <code>action</code>:</p>
680
- <ul><li>
681
- <p><span class='object_link'><a href="#stubbing_method_unnecessarily=-instance_method" title="Mocha::Configuration#stubbing_method_unnecessarily= (method)">#stubbing_method_unnecessarily=</a></span></p>
682
- </li><li>
683
- <p><span class='object_link'><a href="#stubbing_method_on_non_mock_object=-instance_method" title="Mocha::Configuration#stubbing_method_on_non_mock_object= (method)">#stubbing_method_on_non_mock_object=</a></span></p>
684
- </li><li>
685
- <p><span class='object_link'><a href="#stubbing_non_existent_method=-instance_method" title="Mocha::Configuration#stubbing_non_existent_method= (method)">#stubbing_non_existent_method=</a></span></p>
686
- </li><li>
687
- <p><span class='object_link'><a href="#stubbing_non_public_method=-instance_method" title="Mocha::Configuration#stubbing_non_public_method= (method)">#stubbing_non_public_method=</a></span></p>
688
- </li><li>
689
- <p><span class='object_link'><a href="#stubbing_method_on_nil=-instance_method" title="Mocha::Configuration#stubbing_method_on_nil= (method)">#stubbing_method_on_nil=</a></span></p>
690
- </li></ul>
691
- </div></div>
692
-
693
- <p>Raise a <span class='object_link'><a href="StubbingError.html" title="Mocha::StubbingError (class)">StubbingError</a></span> if the specified <code>action</code> is attempted.</p>
694
-
695
-
696
- </div>
697
- </div>
698
- <div class="tags">
699
- <p class="tag_title">Parameters:</p>
700
- <ul class="param">
701
-
702
- <li>
703
-
704
- <span class='name'>action</span>
705
-
706
-
707
- <span class='type'>(<tt>Symbol</tt>)</span>
708
-
709
-
710
-
711
- &mdash;
712
- <div class='inline'>
713
- <p>one of <code>:stubbing_method_unnecessarily</code>, <code>:stubbing_method_on_non_mock_object</code>, <code>:stubbing_non_existent_method</code>, <code>:stubbing_non_public_method</code>, <code>:stubbing_method_on_nil</code>.</p>
714
- </div>
715
-
716
- </li>
717
-
718
- </ul>
719
-
720
- <p class="tag_title">Yields:</p>
721
- <ul class="yield">
722
-
723
- <li>
724
-
725
-
726
- <span class='type'></span>
727
-
728
-
729
-
730
-
731
- <div class='inline'>
732
- <p>optional block during which the configuration change will be changed before being returned to its original value at the end of the block.</p>
733
- </div>
734
-
735
- </li>
736
-
737
- </ul>
738
-
739
- </div><table class="source_code">
740
- <tr>
741
- <td>
742
- <pre class="lines">
743
-
744
-
745
- 365
746
- 366
747
- 367
748
- 368
749
- 369
750
- 370
751
- 371
752
- 372</pre>
753
- </td>
754
- <td>
755
- <pre class="code"><span class="info file"># File 'lib/mocha/configuration.rb', line 365</span>
756
-
757
- <span class='kw'>def</span> <span class='id identifier rubyid_prevent'>prevent</span><span class='lparen'>(</span><span class='id identifier rubyid_action'>action</span><span class='comma'>,</span> <span class='op'>&amp;</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
758
- <span class='kw'>if</span> <span class='id identifier rubyid_block_given?'>block_given?</span>
759
- <span class='const'>Deprecation</span><span class='period'>.</span><span class='id identifier rubyid_warning'>warning</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Use Mocha::Configuration.override(</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_action'>action</span><span class='embexpr_end'>}</span><span class='tstring_content'>: :prevent) with the same block</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
760
- <span class='kw'>else</span>
761
- <span class='const'>Deprecation</span><span class='period'>.</span><span class='id identifier rubyid_warning'>warning</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Use Mocha.configure { |c| c.</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_action'>action</span><span class='embexpr_end'>}</span><span class='tstring_content'> = :prevent }</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
762
- <span class='kw'>end</span>
763
- <span class='id identifier rubyid_change_config'>change_config</span> <span class='id identifier rubyid_action'>action</span><span class='comma'>,</span> <span class='symbol'>:prevent</span><span class='comma'>,</span> <span class='op'>&amp;</span><span class='id identifier rubyid_block'>block</span>
764
- <span class='kw'>end</span></pre>
765
- </td>
766
- </tr>
767
- </table>
768
- </div>
769
-
770
- <div class="method_details ">
771
- <h3 class="signature " id="warn_when-class_method">
772
-
773
- .<strong>warn_when</strong>(action) { ... } &#x21d2; <tt><span class='object_link'>Object</span></tt>
774
-
775
-
776
-
777
-
778
-
779
- </h3><div class="docstring">
780
- <div class="discussion">
781
- <div class="note deprecated"><strong>Deprecated.</strong> <div class='inline'>
782
- <p>If a block is supplied, call <span class='object_link'><a href="#override-class_method" title="Mocha::Configuration.override (method)">override</a></span> with a <code>Hash</code> containing an entry with the <code>action</code> as the key and <code>:warn</code> as the value. If no block is supplied, call the appropriate <code>action</code> writer method with <code>value</code> set to <code>:warn</code> via <span class='object_link'><a href="../Mocha.html#configure-class_method" title="Mocha.configure (method)">Mocha.configure</a></span>. The writer method will be the one of the following corresponding to the <code>action</code>:</p>
783
- <ul><li>
784
- <p><span class='object_link'><a href="#stubbing_method_unnecessarily=-instance_method" title="Mocha::Configuration#stubbing_method_unnecessarily= (method)">#stubbing_method_unnecessarily=</a></span></p>
785
- </li><li>
786
- <p><span class='object_link'><a href="#stubbing_method_on_non_mock_object=-instance_method" title="Mocha::Configuration#stubbing_method_on_non_mock_object= (method)">#stubbing_method_on_non_mock_object=</a></span></p>
787
- </li><li>
788
- <p><span class='object_link'><a href="#stubbing_non_existent_method=-instance_method" title="Mocha::Configuration#stubbing_non_existent_method= (method)">#stubbing_non_existent_method=</a></span></p>
789
- </li><li>
790
- <p><span class='object_link'><a href="#stubbing_non_public_method=-instance_method" title="Mocha::Configuration#stubbing_non_public_method= (method)">#stubbing_non_public_method=</a></span></p>
791
- </li><li>
792
- <p><span class='object_link'><a href="#stubbing_method_on_nil=-instance_method" title="Mocha::Configuration#stubbing_method_on_nil= (method)">#stubbing_method_on_nil=</a></span></p>
793
- </li></ul>
794
- </div></div>
795
-
796
- <p>Warn if the specified <code>action</code> is attempted.</p>
797
-
798
-
799
- </div>
800
- </div>
801
- <div class="tags">
802
- <p class="tag_title">Parameters:</p>
803
- <ul class="param">
804
-
805
- <li>
806
-
807
- <span class='name'>action</span>
808
-
809
-
810
- <span class='type'>(<tt>Symbol</tt>)</span>
811
-
812
-
813
-
814
- &mdash;
815
- <div class='inline'>
816
- <p>one of <code>:stubbing_method_unnecessarily</code>, <code>:stubbing_method_on_non_mock_object</code>, <code>:stubbing_non_existent_method</code>, <code>:stubbing_non_public_method</code>, <code>:stubbing_method_on_nil</code>.</p>
817
- </div>
818
-
819
- </li>
820
-
821
- </ul>
822
-
823
- <p class="tag_title">Yields:</p>
824
- <ul class="yield">
825
-
826
- <li>
827
-
828
-
829
- <span class='type'></span>
830
-
831
-
832
-
833
-
834
- <div class='inline'>
835
- <p>optional block during which the configuration change will be changed before being returned to its original value at the end of the block.</p>
836
- </div>
837
-
838
- </li>
839
-
840
- </ul>
841
-
842
- </div><table class="source_code">
843
- <tr>
844
- <td>
845
- <pre class="lines">
846
-
847
-
848
- 341
849
- 342
850
- 343
851
- 344
852
- 345
853
- 346
854
- 347
855
- 348</pre>
856
- </td>
857
- <td>
858
- <pre class="code"><span class="info file"># File 'lib/mocha/configuration.rb', line 341</span>
859
-
860
- <span class='kw'>def</span> <span class='id identifier rubyid_warn_when'>warn_when</span><span class='lparen'>(</span><span class='id identifier rubyid_action'>action</span><span class='comma'>,</span> <span class='op'>&amp;</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
861
- <span class='kw'>if</span> <span class='id identifier rubyid_block_given?'>block_given?</span>
862
- <span class='const'>Deprecation</span><span class='period'>.</span><span class='id identifier rubyid_warning'>warning</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Use Mocha::Configuration.override(</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_action'>action</span><span class='embexpr_end'>}</span><span class='tstring_content'>: :warn) with the same block</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
863
- <span class='kw'>else</span>
864
- <span class='const'>Deprecation</span><span class='period'>.</span><span class='id identifier rubyid_warning'>warning</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Use Mocha.configure { |c| c.</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_action'>action</span><span class='embexpr_end'>}</span><span class='tstring_content'> = :warn }</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
865
- <span class='kw'>end</span>
866
- <span class='id identifier rubyid_change_config'>change_config</span> <span class='id identifier rubyid_action'>action</span><span class='comma'>,</span> <span class='symbol'>:warn</span><span class='comma'>,</span> <span class='op'>&amp;</span><span class='id identifier rubyid_block'>block</span>
867
- <span class='kw'>end</span></pre>
868
- </td>
869
- </tr>
870
- </table>
871
- </div>
872
-
873
- </div>
874
-
875
- <div id="instance_method_details" class="method_details_list">
876
- <h2>Instance Method Details</h2>
877
-
878
-
879
- <div class="method_details first">
880
- <h3 class="signature first" id="display_matching_invocations_on_failure=-instance_method">
881
-
882
- #<strong>display_matching_invocations_on_failure=</strong>(value) &#x21d2; <tt><span class='object_link'>Object</span></tt>
883
-
884
-
885
-
886
-
887
-
888
- </h3><div class="docstring">
889
- <div class="discussion">
890
-
891
- <p>Display matching invocations alongside expectations on Mocha-related test failure.</p>
892
-
893
-
894
- </div>
895
- </div>
896
- <div class="tags">
897
-
898
- <div class="examples">
899
- <p class="tag_title">Examples:</p>
900
-
901
-
902
- <p class="example_title"><div class='inline'>
903
- <p>Enable display of matching invocations</p>
904
- </div></p>
905
-
906
- <pre class="example code"><code>Mocha.configure do |c|
907
- c.display_matching_invocations_on_failure = true
908
- end
909
-
910
- foo = mock(&#39;foo&#39;)
911
- foo.expects(:bar)
912
- foo.stubs(:baz).returns(&#39;baz&#39;).raises(RuntimeError).throws(:tag, &#39;value&#39;)
913
-
914
- foo.baz(1, 2)
915
- assert_raises(RuntimeError) { foo.baz(3, 4) }
916
- assert_throws(:tag) { foo.baz(5, 6) }
917
-
918
- not all expectations were satisfied
919
- unsatisfied expectations:
920
- - expected exactly once, invoked never: #&lt;Mock:foo&gt;.bar
921
- satisfied expectations:
922
- - allowed any number of times, invoked 3 times: #&lt;Mock:foo&gt;.baz(any_parameters)
923
- - #&lt;Mock:foo&gt;.baz(1, 2) # =&gt; &quot;baz&quot;
924
- - #&lt;Mock:foo&gt;.baz(3, 4) # =&gt; raised RuntimeError
925
- - #&lt;Mock:foo&gt;.baz(5, 6) # =&gt; threw (:tag, &quot;value&quot;)</code></pre>
926
-
927
- </div>
928
- <p class="tag_title">Parameters:</p>
929
- <ul class="param">
930
-
931
- <li>
932
-
933
- <span class='name'>value</span>
934
-
935
-
936
- <span class='type'>(<tt>Boolean</tt>)</span>
937
-
938
-
939
-
940
- &mdash;
941
- <div class='inline'>
942
- <p><code>true</code> to enable display of matching invocations; disabled by default.</p>
943
- </div>
944
-
945
- </li>
946
-
947
- </ul>
948
-
949
-
950
- </div><table class="source_code">
951
- <tr>
952
- <td>
953
- <pre class="lines">
954
-
955
-
956
- 242
957
- 243
958
- 244</pre>
959
- </td>
960
- <td>
961
- <pre class="code"><span class="info file"># File 'lib/mocha/configuration.rb', line 242</span>
962
-
963
- <span class='kw'>def</span> <span class='id identifier rubyid_display_matching_invocations_on_failure='>display_matching_invocations_on_failure=</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
964
- <span class='ivar'>@options</span><span class='lbracket'>[</span><span class='symbol'>:display_matching_invocations_on_failure</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_value'>value</span>
965
- <span class='kw'>end</span></pre>
966
- </td>
967
- </tr>
968
- </table>
969
- </div>
970
-
971
- <div class="method_details ">
972
- <h3 class="signature " id="reinstate_undocumented_behaviour_from_v1_9=-instance_method">
973
-
974
- #<strong>reinstate_undocumented_behaviour_from_v1_9=</strong>(value) &#x21d2; <tt><span class='object_link'>Object</span></tt>
975
-
976
-
977
-
978
-
979
-
980
- </h3><div class="docstring">
981
- <div class="discussion">
982
-
983
- <p>Reinstate undocumented behaviour from v1.9</p>
984
-
985
- <p>Previously when <span class='object_link'><a href="API.html#mock-instance_method" title="Mocha::API#mock (method)">API#mock</a></span>, <span class='object_link'><a href="API.html#stub-instance_method" title="Mocha::API#stub (method)">API#stub</a></span>, or <span class='object_link'><a href="API.html#stub_everything-instance_method" title="Mocha::API#stub_everything (method)">API#stub_everything</a></span> were called with the first argument being a symbol, they built an <strong>unnamed</strong> mock object <strong>and</strong> expected or stubbed the method identified by the symbol argument; subsequent arguments were ignored. Now these methods build a <strong>named</strong> mock with the name specified by the symbol argument; <strong>no</strong> methods are expected or stubbed and subsequent arguments <strong>are</strong> taken into account.</p>
986
-
987
- <p>Previously if <span class='object_link'><a href="Expectation.html#yields-instance_method" title="Mocha::Expectation#yields (method)">Expectation#yields</a></span> or <span class='object_link'><a href="Expectation.html#multiple_yields-instance_method" title="Mocha::Expectation#multiple_yields (method)">Expectation#multiple_yields</a></span> was called on an expectation, but no block was given when the method was invoked, the instruction to yield was ignored. Now a <code>LocalJumpError</code> is raised.</p>
988
-
989
- <p>Enabling this configuration option reinstates the previous behaviour, but displays a deprecation warning.</p>
990
-
991
-
992
- </div>
993
- </div>
994
- <div class="tags">
995
-
996
- <div class="examples">
997
- <p class="tag_title">Examples:</p>
998
-
999
-
1000
- <p class="example_title"><div class='inline'>
1001
- <p>Reinstate undocumented behaviour for <span class='object_link'><a href="API.html#mock-instance_method" title="Mocha::API#mock (method)">API#mock</a></span></p>
1002
- </div></p>
1003
-
1004
- <pre class="example code"><code>Mocha.configure do |c|
1005
- c.reinstate_undocumented_behaviour_from_v1_9 = true
1006
- end
1007
-
1008
- foo = mock(:bar)
1009
- foo.inspect # =&gt; #&lt;Mock&gt;
1010
-
1011
- not all expectations were satisfied
1012
- unsatisfied expectations:
1013
- - expected exactly once, invoked never: #&lt;Mock&gt;.foo</code></pre>
1014
-
1015
-
1016
- <p class="example_title"><div class='inline'>
1017
- <p>Reinstate undocumented behaviour for <span class='object_link'><a href="API.html#stub-instance_method" title="Mocha::API#stub (method)">API#stub</a></span></p>
1018
- </div></p>
1019
-
1020
- <pre class="example code"><code><span class='const'><span class='object_link'><a href="../Mocha.html" title="Mocha (module)">Mocha</a></span></span><span class='period'>.</span><span class='id identifier rubyid_configure'><span class='object_link'><a href="../Mocha.html#configure-class_method" title="Mocha.configure (method)">configure</a></span></span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_c'>c</span><span class='op'>|</span>
1021
- <span class='id identifier rubyid_c'>c</span><span class='period'>.</span><span class='id identifier rubyid_reinstate_undocumented_behaviour_from_v1_9'>reinstate_undocumented_behaviour_from_v1_9</span> <span class='op'>=</span> <span class='kw'>true</span>
1022
- <span class='kw'>end</span>
1023
-
1024
- <span class='id identifier rubyid_foo'>foo</span> <span class='op'>=</span> <span class='id identifier rubyid_stub'>stub</span><span class='lparen'>(</span><span class='symbol'>:bar</span><span class='rparen'>)</span>
1025
- <span class='id identifier rubyid_foo'>foo</span><span class='period'>.</span><span class='id identifier rubyid_inspect'>inspect</span> <span class='comment'># =&gt; #&lt;Mock&gt;
1026
- </span><span class='id identifier rubyid_foo'>foo</span><span class='period'>.</span><span class='id identifier rubyid_bar'>bar</span> <span class='comment'># =&gt; nil</span></code></pre>
1027
-
1028
-
1029
- <p class="example_title"><div class='inline'>
1030
- <p>Reinstate undocumented behaviour for <span class='object_link'><a href="Expectation.html#yields-instance_method" title="Mocha::Expectation#yields (method)">Expectation#yields</a></span></p>
1031
- </div></p>
1032
-
1033
- <pre class="example code"><code><span class='id identifier rubyid_foo'>foo</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'>foo</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>
1034
- <span class='id identifier rubyid_foo'>foo</span><span class='period'>.</span><span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='symbol'>:my_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='comma'>,</span> <span class='int'>2</span><span class='rparen'>)</span>
1035
- <span class='id identifier rubyid_foo'>foo</span><span class='period'>.</span><span class='id identifier rubyid_my_method'>my_method</span> <span class='comment'># =&gt; raises LocalJumpError when no block is supplied
1036
- </span>
1037
- <span class='const'><span class='object_link'><a href="../Mocha.html" title="Mocha (module)">Mocha</a></span></span><span class='period'>.</span><span class='id identifier rubyid_configure'><span class='object_link'><a href="../Mocha.html#configure-class_method" title="Mocha.configure (method)">configure</a></span></span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_c'>c</span><span class='op'>|</span>
1038
- <span class='id identifier rubyid_c'>c</span><span class='period'>.</span><span class='id identifier rubyid_reinstate_undocumented_behaviour_from_v1_9'>reinstate_undocumented_behaviour_from_v1_9</span> <span class='op'>=</span> <span class='kw'>true</span>
1039
- <span class='kw'>end</span>
1040
-
1041
- <span class='id identifier rubyid_foo'>foo</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'>foo</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>
1042
- <span class='id identifier rubyid_foo'>foo</span><span class='period'>.</span><span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='symbol'>:my_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='comma'>,</span> <span class='int'>2</span><span class='rparen'>)</span>
1043
- <span class='id identifier rubyid_foo'>foo</span><span class='period'>.</span><span class='id identifier rubyid_my_method'>my_method</span> <span class='comment'># =&gt; does *not* raise LocalJumpError when no block is supplied</span></code></pre>
1044
-
1045
- </div>
1046
- <p class="tag_title">Parameters:</p>
1047
- <ul class="param">
1048
-
1049
- <li>
1050
-
1051
- <span class='name'>value</span>
1052
-
1053
-
1054
- <span class='type'>(<tt>Boolean</tt>)</span>
1055
-
1056
-
1057
-
1058
- &mdash;
1059
- <div class='inline'>
1060
- <p><code>true</code> to reinstate undocumented behaviour; enabled by default.</p>
1061
- </div>
1062
-
1063
- </li>
1064
-
1065
- </ul>
1066
-
1067
-
1068
- </div><table class="source_code">
1069
- <tr>
1070
- <td>
1071
- <pre class="lines">
1072
-
1073
-
1074
- 297
1075
- 298
1076
- 299</pre>
1077
- </td>
1078
- <td>
1079
- <pre class="code"><span class="info file"># File 'lib/mocha/configuration.rb', line 297</span>
1080
-
1081
- <span class='kw'>def</span> <span class='id identifier rubyid_reinstate_undocumented_behaviour_from_v1_9='>reinstate_undocumented_behaviour_from_v1_9=</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
1082
- <span class='ivar'>@options</span><span class='lbracket'>[</span><span class='symbol'>:reinstate_undocumented_behaviour_from_v1_9</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_value'>value</span>
1083
- <span class='kw'>end</span></pre>
1084
- </td>
1085
- </tr>
1086
- </table>
1087
- </div>
1088
-
1089
- <div class="method_details ">
1090
- <h3 class="signature " id="stubbing_method_on_nil=-instance_method">
1091
-
1092
- #<strong>stubbing_method_on_nil=</strong>(value) &#x21d2; <tt><span class='object_link'>Object</span></tt>
1093
-
1094
-
1095
-
1096
-
1097
-
1098
- </h3><div class="docstring">
1099
- <div class="discussion">
1100
-
1101
- <p>Configure whether stubbing methods on the <code>nil</code> object is allowed.</p>
1102
-
1103
- <p>This is usually done accidentally, but there might be rare cases where it is intended.</p>
1104
-
1105
- <p>This option only works for Ruby &lt; v2.2.0. In later versions of Ruby <code>nil</code> is frozen and so a <span class='object_link'><a href="StubbingError.html" title="Mocha::StubbingError (class)">StubbingError</a></span> will be raised if you attempt to stub a method on <code>nil</code>.</p>
1106
-
1107
- <p>When <code>value</code> is <code>:allow</code>, do nothing. When <code>value</code> is <code>:warn</code>, display a warning. When <code>value</code> is <code>:prevent</code>, raise a <span class='object_link'><a href="StubbingError.html" title="Mocha::StubbingError (class)">StubbingError</a></span>. This is the default.</p>
1108
-
1109
-
1110
- </div>
1111
- </div>
1112
- <div class="tags">
1113
- <p class="tag_title">Parameters:</p>
1114
- <ul class="param">
1115
-
1116
- <li>
1117
-
1118
- <span class='name'>value</span>
1119
-
1120
-
1121
- <span class='type'>(<tt>Symbol</tt>)</span>
1122
-
1123
-
1124
-
1125
- &mdash;
1126
- <div class='inline'>
1127
- <p>one of <code>:allow</code>, <code>:warn</code>, <code>:prevent</code>.</p>
1128
- </div>
1129
-
1130
- </li>
1131
-
1132
- </ul>
1133
-
1134
-
1135
- </div><table class="source_code">
1136
- <tr>
1137
- <td>
1138
- <pre class="lines">
1139
-
1140
-
1141
- 208
1142
- 209
1143
- 210</pre>
1144
- </td>
1145
- <td>
1146
- <pre class="code"><span class="info file"># File 'lib/mocha/configuration.rb', line 208</span>
1147
-
1148
- <span class='kw'>def</span> <span class='id identifier rubyid_stubbing_method_on_nil='>stubbing_method_on_nil=</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
1149
- <span class='ivar'>@options</span><span class='lbracket'>[</span><span class='symbol'>:stubbing_method_on_nil</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_value'>value</span>
1150
- <span class='kw'>end</span></pre>
1151
- </td>
1152
- </tr>
1153
- </table>
1154
- </div>
1155
-
1156
- <div class="method_details ">
1157
- <h3 class="signature " id="stubbing_method_on_non_mock_object=-instance_method">
1158
-
1159
- #<strong>stubbing_method_on_non_mock_object=</strong>(value) &#x21d2; <tt><span class='object_link'>Object</span></tt>
1160
-
1161
-
1162
-
1163
-
1164
-
1165
- </h3><div class="docstring">
1166
- <div class="discussion">
1167
-
1168
- <p>Configure whether stubbing methods on non-mock objects is allowed.</p>
1169
-
1170
- <p>If you like the idea of <a href="http://www.jmock.org/oopsla2004.pdf" target="_parent" title="mocking roles not objects">mocking roles not objects</a> and <a href="http://www.mockobjects.com/2007/04/test-smell-mocking-concrete-classes.html" target="_parent" title="you don&amp;#39;t like stubbing concrete classes">you don&#39;t like stubbing concrete classes</a>, this is the setting for you. However, while this restriction makes a lot of sense in Java with its <a href="http://java.sun.com/docs/books/tutorial/java/concepts/interface.html" target="_parent" title="explicit interfaces">explicit interfaces</a>, it may be moot in Ruby where roles are probably best represented as Modules.</p>
1171
-
1172
- <p>When <code>value</code> is <code>:allow</code>, do nothing. This is the default. When <code>value</code> is <code>:warn</code>, display a warning. When <code>value</code> is <code>:prevent</code>, raise a <span class='object_link'><a href="StubbingError.html" title="Mocha::StubbingError (class)">StubbingError</a></span>.</p>
1173
-
1174
-
1175
- </div>
1176
- </div>
1177
- <div class="tags">
1178
-
1179
- <div class="examples">
1180
- <p class="tag_title">Examples:</p>
1181
-
1182
-
1183
- <p class="example_title"><div class='inline'>
1184
- <p>Preventing stubbing of a method on a non-mock object</p>
1185
- </div></p>
1186
-
1187
- <pre class="example code"><code><span class='const'><span class='object_link'><a href="../Mocha.html" title="Mocha (module)">Mocha</a></span></span><span class='period'>.</span><span class='id identifier rubyid_configure'><span class='object_link'><a href="../Mocha.html#configure-class_method" title="Mocha.configure (method)">configure</a></span></span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_c'>c</span><span class='op'>|</span>
1188
- <span class='id identifier rubyid_c'>c</span><span class='period'>.</span><span class='id identifier rubyid_stubbing_method_on_non_mock_object'>stubbing_method_on_non_mock_object</span> <span class='op'>=</span> <span class='symbol'>:prevent</span>
1189
- <span class='kw'>end</span>
1190
-
1191
- <span class='kw'>class</span> <span class='const'>Example</span>
1192
- <span class='kw'>def</span> <span class='id identifier rubyid_example_method'>example_method</span><span class='semicolon'>;</span> <span class='kw'>end</span>
1193
- <span class='kw'>end</span>
1194
-
1195
- <span class='id identifier rubyid_example'>example</span> <span class='op'>=</span> <span class='const'>Example</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
1196
- <span class='id identifier rubyid_example'>example</span><span class='period'>.</span><span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='symbol'>:example_method</span><span class='rparen'>)</span>
1197
- <span class='comment'># =&gt; Mocha::StubbingError: stubbing method on non-mock object:
1198
- </span><span class='comment'># =&gt; #&lt;Example:0x593620&gt;.example_method</span></code></pre>
1199
-
1200
- </div>
1201
- <p class="tag_title">Parameters:</p>
1202
- <ul class="param">
1203
-
1204
- <li>
1205
-
1206
- <span class='name'>value</span>
1207
-
1208
-
1209
- <span class='type'>(<tt>Symbol</tt>)</span>
1210
-
1211
-
1212
-
1213
- &mdash;
1214
- <div class='inline'>
1215
- <p>one of <code>:allow</code>, <code>:warn</code>, <code>:prevent</code>.</p>
1216
- </div>
1217
-
1218
- </li>
1219
-
1220
- </ul>
1221
-
1222
-
1223
- </div><table class="source_code">
1224
- <tr>
1225
- <td>
1226
- <pre class="lines">
1227
-
1228
-
1229
- 120
1230
- 121
1231
- 122</pre>
1232
- </td>
1233
- <td>
1234
- <pre class="code"><span class="info file"># File 'lib/mocha/configuration.rb', line 120</span>
1235
-
1236
- <span class='kw'>def</span> <span class='id identifier rubyid_stubbing_method_on_non_mock_object='>stubbing_method_on_non_mock_object=</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
1237
- <span class='ivar'>@options</span><span class='lbracket'>[</span><span class='symbol'>:stubbing_method_on_non_mock_object</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_value'>value</span>
1238
- <span class='kw'>end</span></pre>
1239
- </td>
1240
- </tr>
1241
- </table>
1242
- </div>
1243
-
1244
- <div class="method_details ">
1245
- <h3 class="signature " id="stubbing_method_unnecessarily=-instance_method">
1246
-
1247
- #<strong>stubbing_method_unnecessarily=</strong>(value) &#x21d2; <tt><span class='object_link'>Object</span></tt>
1248
-
1249
-
1250
-
1251
-
1252
-
1253
- </h3><div class="docstring">
1254
- <div class="discussion">
1255
-
1256
- <p>Configure whether stubbing methods unnecessarily is allowed.</p>
1257
-
1258
- <p>This is useful for identifying unused stubs. Unused stubs are often accidentally introduced when code is <a href="http://martinfowler.com/bliki/DefinitionOfRefactoring.html" target="_parent" title="refactored">refactored</a>.</p>
1259
-
1260
- <p>When <code>value</code> is <code>:allow</code>, do nothing. This is the default. When <code>value</code> is <code>:warn</code>, display a warning. When <code>value</code> is <code>:prevent</code>, raise a <span class='object_link'><a href="StubbingError.html" title="Mocha::StubbingError (class)">StubbingError</a></span>.</p>
1261
-
1262
-
1263
- </div>
1264
- </div>
1265
- <div class="tags">
1266
-
1267
- <div class="examples">
1268
- <p class="tag_title">Examples:</p>
1269
-
1270
-
1271
- <p class="example_title"><div class='inline'>
1272
- <p>Preventing unnecessary stubbing of a method</p>
1273
- </div></p>
1274
-
1275
- <pre class="example code"><code><span class='const'><span class='object_link'><a href="../Mocha.html" title="Mocha (module)">Mocha</a></span></span><span class='period'>.</span><span class='id identifier rubyid_configure'><span class='object_link'><a href="../Mocha.html#configure-class_method" title="Mocha.configure (method)">configure</a></span></span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_c'>c</span><span class='op'>|</span>
1276
- <span class='id identifier rubyid_c'>c</span><span class='period'>.</span><span class='id identifier rubyid_stubbing_method_unnecessarily'>stubbing_method_unnecessarily</span> <span class='op'>=</span> <span class='symbol'>:prevent</span>
1277
- <span class='kw'>end</span>
1278
-
1279
- <span class='id identifier rubyid_example'>example</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'>example</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>
1280
- <span class='id identifier rubyid_example'>example</span><span class='period'>.</span><span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='symbol'>:unused_stub</span><span class='rparen'>)</span>
1281
- <span class='comment'># =&gt; Mocha::StubbingError: stubbing method unnecessarily:
1282
- </span><span class='comment'># =&gt; #&lt;Mock:example&gt;.unused_stub(any_parameters)</span></code></pre>
1283
-
1284
- </div>
1285
- <p class="tag_title">Parameters:</p>
1286
- <ul class="param">
1287
-
1288
- <li>
1289
-
1290
- <span class='name'>value</span>
1291
-
1292
-
1293
- <span class='type'>(<tt>Symbol</tt>)</span>
1294
-
1295
-
1296
-
1297
- &mdash;
1298
- <div class='inline'>
1299
- <p>one of <code>:allow</code>, <code>:warn</code>, <code>:prevent</code>.</p>
1300
- </div>
1301
-
1302
- </li>
1303
-
1304
- </ul>
1305
-
1306
-
1307
- </div><table class="source_code">
1308
- <tr>
1309
- <td>
1310
- <pre class="lines">
1311
-
1312
-
1313
- 87
1314
- 88
1315
- 89</pre>
1316
- </td>
1317
- <td>
1318
- <pre class="code"><span class="info file"># File 'lib/mocha/configuration.rb', line 87</span>
1319
-
1320
- <span class='kw'>def</span> <span class='id identifier rubyid_stubbing_method_unnecessarily='>stubbing_method_unnecessarily=</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
1321
- <span class='ivar'>@options</span><span class='lbracket'>[</span><span class='symbol'>:stubbing_method_unnecessarily</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_value'>value</span>
1322
- <span class='kw'>end</span></pre>
1323
- </td>
1324
- </tr>
1325
- </table>
1326
- </div>
1327
-
1328
- <div class="method_details ">
1329
- <h3 class="signature " id="stubbing_non_existent_method=-instance_method">
1330
-
1331
- #<strong>stubbing_non_existent_method=</strong>(value) &#x21d2; <tt><span class='object_link'>Object</span></tt>
1332
-
1333
-
1334
-
1335
-
1336
-
1337
- </h3><div class="docstring">
1338
- <div class="discussion">
1339
-
1340
- <p>Configure whether stubbing of non-existent methods is allowed.</p>
1341
-
1342
- <p>This is useful if you want to ensure that methods you&#39;re mocking really exist. A common criticism of unit tests with mock objects is that such a test may (incorrectly) pass when an equivalent non-mocking test would (correctly) fail. While you should always have some integration tests, particularly for critical business functionality, this Mocha configuration setting should catch scenarios when mocked methods and real methods have become misaligned.</p>
1343
-
1344
- <p>When <code>value</code> is <code>:allow</code>, do nothing. This is the default. When <code>value</code> is <code>:warn</code>, display a warning. When <code>value</code> is <code>:prevent</code>, raise a <span class='object_link'><a href="StubbingError.html" title="Mocha::StubbingError (class)">StubbingError</a></span>.</p>
1345
-
1346
-
1347
- </div>
1348
- </div>
1349
- <div class="tags">
1350
-
1351
- <div class="examples">
1352
- <p class="tag_title">Examples:</p>
1353
-
1354
-
1355
- <p class="example_title"><div class='inline'>
1356
- <p>Preventing stubbing of a non-existent method</p>
1357
- </div></p>
1358
-
1359
- <pre class="example code"><code>
1360
- <span class='const'><span class='object_link'><a href="../Mocha.html" title="Mocha (module)">Mocha</a></span></span><span class='period'>.</span><span class='id identifier rubyid_configure'><span class='object_link'><a href="../Mocha.html#configure-class_method" title="Mocha.configure (method)">configure</a></span></span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_c'>c</span><span class='op'>|</span>
1361
- <span class='id identifier rubyid_c'>c</span><span class='period'>.</span><span class='id identifier rubyid_stubbing_non_existent_method'>stubbing_non_existent_method</span> <span class='op'>=</span> <span class='symbol'>:prevent</span>
1362
- <span class='kw'>end</span>
1363
-
1364
- <span class='kw'>class</span> <span class='const'>Example</span>
1365
- <span class='kw'>end</span>
1366
-
1367
- <span class='id identifier rubyid_example'>example</span> <span class='op'>=</span> <span class='const'>Example</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
1368
- <span class='id identifier rubyid_example'>example</span><span class='period'>.</span><span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='symbol'>:method_that_doesnt_exist</span><span class='rparen'>)</span>
1369
- <span class='comment'># =&gt; Mocha::StubbingError: stubbing non-existent method:
1370
- </span><span class='comment'># =&gt; #&lt;Example:0x593760&gt;.method_that_doesnt_exist</span></code></pre>
1371
-
1372
- </div>
1373
- <p class="tag_title">Parameters:</p>
1374
- <ul class="param">
1375
-
1376
- <li>
1377
-
1378
- <span class='name'>value</span>
1379
-
1380
-
1381
- <span class='type'>(<tt>Symbol</tt>)</span>
1382
-
1383
-
1384
-
1385
- &mdash;
1386
- <div class='inline'>
1387
- <p>one of <code>:allow</code>, <code>:warn</code>, <code>:prevent</code>.</p>
1388
- </div>
1389
-
1390
- </li>
1391
-
1392
- </ul>
1393
-
1394
-
1395
- </div><table class="source_code">
1396
- <tr>
1397
- <td>
1398
- <pre class="lines">
1399
-
1400
-
1401
- 153
1402
- 154
1403
- 155</pre>
1404
- </td>
1405
- <td>
1406
- <pre class="code"><span class="info file"># File 'lib/mocha/configuration.rb', line 153</span>
1407
-
1408
- <span class='kw'>def</span> <span class='id identifier rubyid_stubbing_non_existent_method='>stubbing_non_existent_method=</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
1409
- <span class='ivar'>@options</span><span class='lbracket'>[</span><span class='symbol'>:stubbing_non_existent_method</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_value'>value</span>
1410
- <span class='kw'>end</span></pre>
1411
- </td>
1412
- </tr>
1413
- </table>
1414
- </div>
1415
-
1416
- <div class="method_details ">
1417
- <h3 class="signature " id="stubbing_non_public_method=-instance_method">
1418
-
1419
- #<strong>stubbing_non_public_method=</strong>(value) &#x21d2; <tt><span class='object_link'>Object</span></tt>
1420
-
1421
-
1422
-
1423
-
1424
-
1425
- </h3><div class="docstring">
1426
- <div class="discussion">
1427
-
1428
- <p>Configure whether stubbing of non-public methods is allowed.</p>
1429
-
1430
- <p>Many people think that it&#39;s good practice only to mock public methods. This is one way to prevent your tests being too tightly coupled to the internal implementation of a class. Such tests tend to be very brittle and not much use when refactoring.</p>
1431
-
1432
- <p>When <code>value</code> is <code>:allow</code>, do nothing. This is the default. When <code>value</code> is <code>:warn</code>, display a warning. When <code>value</code> is <code>:prevent</code>, raise a <span class='object_link'><a href="StubbingError.html" title="Mocha::StubbingError (class)">StubbingError</a></span>.</p>
1433
-
1434
-
1435
- </div>
1436
- </div>
1437
- <div class="tags">
1438
-
1439
- <div class="examples">
1440
- <p class="tag_title">Examples:</p>
1441
-
1442
-
1443
- <p class="example_title"><div class='inline'>
1444
- <p>Preventing stubbing of a non-public method</p>
1445
- </div></p>
1446
-
1447
- <pre class="example code"><code><span class='const'><span class='object_link'><a href="../Mocha.html" title="Mocha (module)">Mocha</a></span></span><span class='period'>.</span><span class='id identifier rubyid_configure'><span class='object_link'><a href="../Mocha.html#configure-class_method" title="Mocha.configure (method)">configure</a></span></span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_c'>c</span><span class='op'>|</span>
1448
- <span class='id identifier rubyid_c'>c</span><span class='period'>.</span><span class='id identifier rubyid_stubbing_non_public_method'>stubbing_non_public_method</span> <span class='op'>=</span> <span class='symbol'>:prevent</span>
1449
- <span class='kw'>end</span>
1450
-
1451
- <span class='kw'>class</span> <span class='const'>Example</span>
1452
- <span class='kw'>def</span> <span class='id identifier rubyid_internal_method'>internal_method</span><span class='semicolon'>;</span> <span class='kw'>end</span>
1453
- <span class='id identifier rubyid_private'>private</span> <span class='symbol'>:internal_method</span>
1454
- <span class='kw'>end</span>
1455
-
1456
- <span class='id identifier rubyid_example'>example</span> <span class='op'>=</span> <span class='const'>Example</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
1457
- <span class='id identifier rubyid_example'>example</span><span class='period'>.</span><span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='symbol'>:internal_method</span><span class='rparen'>)</span>
1458
- <span class='comment'># =&gt; Mocha::StubbingError: stubbing non-public method:
1459
- </span><span class='comment'># =&gt; #&lt;Example:0x593530&gt;.internal_method</span></code></pre>
1460
-
1461
- </div>
1462
- <p class="tag_title">Parameters:</p>
1463
- <ul class="param">
1464
-
1465
- <li>
1466
-
1467
- <span class='name'>value</span>
1468
-
1469
-
1470
- <span class='type'>(<tt>Symbol</tt>)</span>
1471
-
1472
-
1473
-
1474
- &mdash;
1475
- <div class='inline'>
1476
- <p>one of <code>:allow</code>, <code>:warn</code>, <code>:prevent</code>.</p>
1477
- </div>
1478
-
1479
- </li>
1480
-
1481
- </ul>
1482
-
1483
-
1484
- </div><table class="source_code">
1485
- <tr>
1486
- <td>
1487
- <pre class="lines">
1488
-
1489
-
1490
- 187
1491
- 188
1492
- 189</pre>
1493
- </td>
1494
- <td>
1495
- <pre class="code"><span class="info file"># File 'lib/mocha/configuration.rb', line 187</span>
1496
-
1497
- <span class='kw'>def</span> <span class='id identifier rubyid_stubbing_non_public_method='>stubbing_non_public_method=</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
1498
- <span class='ivar'>@options</span><span class='lbracket'>[</span><span class='symbol'>:stubbing_non_public_method</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_value'>value</span>
1499
- <span class='kw'>end</span></pre>
1500
- </td>
1501
- </tr>
1502
- </table>
1503
- </div>
1504
-
1505
- </div>
1506
-
1507
- <script async src="https://www.googletagmanager.com/gtag/js?id=UA-625523-7"></script>
1508
- <script>
1509
- window.dataLayer = window.dataLayer || [];
1510
- function gtag(){dataLayer.push(arguments);}
1511
- gtag('js', new Date());
1512
-
1513
- gtag('config', 'UA-625523-7');
1514
- </script>
1515
- </div>
1516
-
1517
- <div id="footer">
1518
- Generated on Sat Jan 4 17:36:48 2020 by
1519
- <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
1520
- 0.9.20 (ruby-2.6.5).
1521
- </div>
1522
-
1523
- </div>
1524
- </body>
1525
- </html>