mocha 1.9.0 → 1.10.0.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/.rubocop_todo.yml +7 -30
- data/README.md +10 -11
- data/RELEASE.md +48 -0
- data/Rakefile +9 -3
- data/docs/CNAME +1 -0
- data/docs/Mocha.html +132 -5
- data/docs/Mocha/API.html +289 -216
- data/docs/Mocha/ClassMethods.html +88 -16
- data/docs/Mocha/Configuration.html +931 -174
- data/docs/Mocha/Expectation.html +200 -255
- data/docs/Mocha/ExpectationError.html +5 -10
- data/docs/Mocha/ExpectationErrorFactory.html +9 -18
- data/docs/Mocha/Hooks.html +12 -27
- data/docs/Mocha/Integration.html +3 -3
- data/docs/Mocha/Integration/MiniTest.html +3 -3
- data/docs/Mocha/Integration/MiniTest/Adapter.html +5 -6
- data/docs/Mocha/Integration/TestUnit.html +3 -3
- data/docs/Mocha/Integration/TestUnit/Adapter.html +5 -6
- data/docs/Mocha/Mock.html +202 -162
- data/docs/Mocha/ObjectMethods.html +121 -68
- data/docs/Mocha/ParameterMatchers.html +21 -109
- data/docs/Mocha/ParameterMatchers/AllOf.html +4 -5
- data/docs/Mocha/ParameterMatchers/AnyOf.html +4 -5
- data/docs/Mocha/ParameterMatchers/AnyParameters.html +3 -3
- data/docs/Mocha/ParameterMatchers/Anything.html +3 -3
- data/docs/Mocha/ParameterMatchers/Base.html +8 -15
- data/docs/Mocha/ParameterMatchers/Equals.html +4 -5
- data/docs/Mocha/ParameterMatchers/EquivalentUri.html +3 -3
- data/docs/Mocha/ParameterMatchers/HasEntries.html +4 -5
- data/docs/Mocha/ParameterMatchers/HasEntry.html +4 -5
- data/docs/Mocha/ParameterMatchers/HasKey.html +4 -5
- data/docs/Mocha/ParameterMatchers/HasValue.html +4 -5
- data/docs/Mocha/ParameterMatchers/Includes.html +4 -5
- data/docs/Mocha/ParameterMatchers/InstanceOf.html +4 -5
- data/docs/Mocha/ParameterMatchers/IsA.html +3 -3
- data/docs/Mocha/ParameterMatchers/KindOf.html +4 -5
- data/docs/Mocha/ParameterMatchers/Not.html +4 -5
- data/docs/Mocha/ParameterMatchers/Optionally.html +3 -3
- data/docs/Mocha/ParameterMatchers/RegexpMatches.html +4 -5
- data/docs/Mocha/ParameterMatchers/RespondsWith.html +4 -5
- data/docs/Mocha/ParameterMatchers/YamlEquivalent.html +4 -5
- data/docs/Mocha/Sequence.html +3 -3
- data/docs/Mocha/StateMachine.html +13 -25
- data/docs/Mocha/StateMachine/State.html +4 -5
- data/docs/Mocha/StateMachine/StatePredicate.html +4 -5
- data/docs/Mocha/StubbingError.html +3 -3
- data/docs/_index.html +4 -22
- data/docs/class_list.html +1 -1
- data/docs/file.COPYING.html +3 -3
- data/docs/file.MIT-LICENSE.html +3 -3
- data/docs/file.README.html +18 -15
- data/docs/file.RELEASE.html +58 -3
- data/docs/frames.html +1 -1
- data/docs/index.html +18 -15
- data/docs/method_list.html +103 -39
- data/docs/top-level-namespace.html +3 -3
- data/gemfiles/Gemfile.minitest.5.11.3 +7 -0
- data/init.rb +1 -3
- data/lib/mocha.rb +8 -0
- data/lib/mocha/any_instance_method.rb +9 -25
- data/lib/mocha/api.rb +62 -66
- data/lib/mocha/cardinality.rb +26 -11
- data/lib/mocha/class_methods.rb +16 -15
- data/lib/mocha/configuration.rb +295 -67
- data/lib/mocha/detection/test_unit.rb +1 -3
- data/lib/mocha/exception_raiser.rb +2 -1
- data/lib/mocha/expectation.rb +56 -58
- data/lib/mocha/expectation_error.rb +1 -3
- data/lib/mocha/expectation_list.rb +6 -6
- data/lib/mocha/inspect.rb +28 -26
- data/lib/mocha/instance_method.rb +19 -2
- data/lib/mocha/integration.rb +1 -3
- data/lib/mocha/integration/mini_test.rb +7 -0
- data/lib/mocha/integration/test_unit.rb +7 -0
- data/lib/mocha/invocation.rb +61 -0
- data/lib/mocha/macos_version.rb +5 -0
- data/lib/mocha/minitest.rb +6 -1
- data/lib/mocha/mock.rb +46 -31
- data/lib/mocha/mockery.rb +28 -61
- data/lib/mocha/names.rb +1 -1
- data/lib/mocha/object_methods.rb +13 -19
- data/lib/mocha/parameter_matchers.rb +1 -1
- data/lib/mocha/parameter_matchers/all_of.rb +1 -1
- data/lib/mocha/parameter_matchers/any_of.rb +1 -1
- data/lib/mocha/parameter_matchers/equivalent_uri.rb +0 -9
- data/lib/mocha/parameter_matchers/includes.rb +2 -0
- data/lib/mocha/parameter_matchers/instance_methods.rb +18 -0
- data/lib/mocha/raised_exception.rb +11 -0
- data/lib/mocha/return_values.rb +3 -3
- data/lib/mocha/setup.rb +5 -0
- data/lib/mocha/single_return_value.rb +2 -1
- data/lib/mocha/singleton_class.rb +9 -0
- data/lib/mocha/{class_method.rb → stubbed_method.rb} +23 -43
- data/lib/mocha/test_unit.rb +6 -1
- data/lib/mocha/thrower.rb +2 -1
- data/lib/mocha/thrown_object.rb +12 -0
- data/lib/mocha/version.rb +1 -1
- data/mocha.gemspec +1 -3
- data/test/acceptance/acceptance_test_helper.rb +6 -0
- data/test/acceptance/bug_18914_test.rb +0 -1
- data/test/acceptance/bug_21465_test.rb +0 -1
- data/test/acceptance/bug_21563_test.rb +0 -1
- data/test/acceptance/display_matching_invocations_alongside_expectations_test.rb +69 -0
- data/test/acceptance/exception_rescue_test.rb +1 -2
- data/test/acceptance/expectations_on_multiple_methods_test.rb +0 -1
- data/test/acceptance/expected_invocation_count_test.rb +2 -3
- data/test/acceptance/failure_messages_test.rb +0 -1
- data/test/acceptance/issue_272_test.rb +1 -2
- data/test/acceptance/issue_65_test.rb +0 -1
- data/test/acceptance/issue_70_test.rb +0 -1
- data/test/acceptance/mocha_example_test.rb +0 -1
- data/test/acceptance/mocha_test_result_test.rb +0 -1
- data/test/acceptance/mock_test.rb +47 -6
- data/test/acceptance/mocked_methods_dispatch_test.rb +0 -1
- data/test/acceptance/multiple_expectations_failure_message_test.rb +0 -1
- data/test/acceptance/optional_parameters_test.rb +0 -1
- data/test/acceptance/parameter_matcher_test.rb +0 -1
- data/test/acceptance/partial_mocks_test.rb +0 -1
- data/test/acceptance/prepend_test.rb +0 -1
- data/test/acceptance/prevent_use_of_mocha_outside_test_test.rb +0 -1
- data/test/acceptance/raise_exception_test.rb +0 -1
- data/test/acceptance/return_value_test.rb +0 -1
- data/test/acceptance/sequence_test.rb +0 -1
- data/test/acceptance/states_test.rb +0 -1
- data/test/acceptance/stub_any_instance_method_defined_on_superclass_test.rb +1 -2
- data/test/acceptance/stub_any_instance_method_test.rb +20 -1
- data/test/acceptance/stub_class_method_defined_on_active_record_association_proxy_test.rb +0 -1
- data/test/acceptance/stub_class_method_defined_on_class_test.rb +0 -1
- data/test/acceptance/stub_class_method_defined_on_module_test.rb +0 -1
- data/test/acceptance/stub_class_method_defined_on_superclass_test.rb +1 -2
- data/test/acceptance/stub_everything_test.rb +0 -1
- data/test/acceptance/stub_instance_method_defined_on_active_record_association_proxy_test.rb +0 -1
- data/test/acceptance/stub_instance_method_defined_on_class_and_aliased_test.rb +0 -1
- data/test/acceptance/stub_instance_method_defined_on_class_test.rb +0 -1
- data/test/acceptance/stub_instance_method_defined_on_kernel_module_test.rb +0 -1
- data/test/acceptance/stub_instance_method_defined_on_module_test.rb +0 -1
- data/test/acceptance/stub_instance_method_defined_on_object_class_test.rb +0 -1
- data/test/acceptance/stub_instance_method_defined_on_singleton_class_test.rb +0 -1
- data/test/acceptance/stub_instance_method_defined_on_superclass_test.rb +0 -1
- data/test/acceptance/stub_method_defined_on_module_and_aliased_test.rb +0 -1
- data/test/acceptance/stub_module_method_test.rb +0 -1
- data/test/acceptance/stub_test.rb +0 -1
- data/test/acceptance/stubba_example_test.rb +0 -1
- data/test/acceptance/stubba_test_result_test.rb +0 -1
- data/test/acceptance/stubbing_error_backtrace_test.rb +4 -5
- data/test/acceptance/stubbing_frozen_object_test.rb +0 -1
- data/test/acceptance/stubbing_method_accepting_block_parameter_test.rb +0 -1
- data/test/acceptance/stubbing_method_unnecessarily_test.rb +5 -5
- data/test/acceptance/stubbing_nil_test.rb +5 -5
- data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +11 -11
- data/test/acceptance/stubbing_non_existent_class_method_test.rb +11 -11
- data/test/acceptance/stubbing_non_existent_instance_method_test.rb +11 -11
- data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +8 -8
- data/test/acceptance/stubbing_non_public_class_method_test.rb +9 -9
- data/test/acceptance/stubbing_non_public_instance_method_test.rb +9 -9
- data/test/acceptance/stubbing_on_non_mock_object_test.rb +5 -5
- data/test/acceptance/stubbing_same_class_method_on_parent_and_child_classes_test.rb +0 -1
- data/test/acceptance/throw_test.rb +0 -1
- data/test/acceptance/unexpected_invocation_test.rb +0 -1
- data/test/acceptance/unstubbing_test.rb +0 -1
- data/test/integration/shared_tests.rb +5 -3
- data/test/method_definer.rb +11 -17
- data/test/test_runner.rb +2 -0
- data/test/unit/any_instance_method_test.rb +41 -40
- data/test/unit/cardinality_test.rb +41 -23
- data/test/unit/central_test.rb +0 -1
- data/test/unit/class_methods_test.rb +1 -1
- data/test/unit/configuration_test.rb +12 -12
- data/test/unit/exception_raiser_test.rb +10 -5
- data/test/unit/expectation_list_test.rb +13 -11
- data/test/unit/expectation_test.rb +88 -103
- data/test/unit/instance_method_test.rb +282 -0
- data/test/unit/mock_test.rb +28 -19
- data/test/unit/mockery_test.rb +8 -11
- data/test/unit/module_methods_test.rb +2 -3
- data/test/unit/object_inspect_test.rb +6 -4
- data/test/unit/object_methods_test.rb +3 -2
- data/test/unit/parameter_matchers/equivalent_uri_test.rb +0 -9
- data/test/unit/parameter_matchers/has_entries_test.rb +1 -1
- data/test/unit/parameter_matchers/has_entry_test.rb +1 -1
- data/test/unit/parameter_matchers/has_key_test.rb +1 -1
- data/test/unit/parameter_matchers/has_value_test.rb +1 -1
- data/test/unit/parameter_matchers/includes_test.rb +1 -1
- data/test/unit/parameter_matchers/responds_with_test.rb +1 -1
- data/test/unit/return_values_test.rb +25 -20
- data/test/unit/single_return_value_test.rb +6 -1
- data/test/unit/thrower_test.rb +7 -2
- metadata +16 -30
- data/docs/Mocha/UnexpectedInvocation.html +0 -140
- data/lib/mocha/mini_test.rb +0 -5
- data/lib/mocha/module_method.rb +0 -6
- data/lib/mocha/module_methods.rb +0 -10
- data/lib/mocha/parameter_matchers/object.rb +0 -15
- data/lib/mocha/standalone.rb +0 -4
- data/lib/mocha/unexpected_invocation.rb +0 -24
- data/lib/mocha_standalone.rb +0 -4
- data/test/acceptance/mock_with_initializer_block_test.rb +0 -56
- data/test/unit/class_method_test.rb +0 -276
@@ -6,7 +6,7 @@
|
|
6
6
|
<title>
|
7
7
|
Module: Mocha::ClassMethods
|
8
8
|
|
9
|
-
— Mocha 1.
|
9
|
+
— Mocha 1.10.0.alpha
|
10
10
|
|
11
11
|
</title>
|
12
12
|
|
@@ -86,8 +86,7 @@
|
|
86
86
|
<h2>Overview</h2><div class="docstring">
|
87
87
|
<div class="discussion">
|
88
88
|
|
89
|
-
<p>Methods added to all classes to allow mocking and stubbing on real (i.e.
|
90
|
-
non-mock) objects.</p>
|
89
|
+
<p>Methods added to all classes to allow mocking and stubbing on real (i.e. non-mock) objects.</p>
|
91
90
|
|
92
91
|
|
93
92
|
</div>
|
@@ -131,6 +130,32 @@ non-mock) objects.</p>
|
|
131
130
|
<p>A mock object which will detect calls to any instance of this class.</p>
|
132
131
|
</div></span>
|
133
132
|
|
133
|
+
</li>
|
134
|
+
|
135
|
+
|
136
|
+
<li class="public ">
|
137
|
+
<span class="summary_signature">
|
138
|
+
|
139
|
+
<a href="#method_visibility-instance_method" title="#method_visibility (instance method)">#<strong>method_visibility</strong>(method, include_public_methods = true) ⇒ Object </a>
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
(also: #method_exists?)
|
144
|
+
|
145
|
+
</span>
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
<span class="summary_desc"><div class='inline'>
|
156
|
+
<p>rubocop:disable Metrics/CyclomaticComplexity.</p>
|
157
|
+
</div></span>
|
158
|
+
|
134
159
|
</li>
|
135
160
|
|
136
161
|
|
@@ -155,8 +180,7 @@ non-mock) objects.</p>
|
|
155
180
|
</h3><div class="docstring">
|
156
181
|
<div class="discussion">
|
157
182
|
|
158
|
-
<p>Returns a mock object which will detect calls to any instance of this
|
159
|
-
class.</p>
|
183
|
+
<p>Returns a mock object which will detect calls to any instance of this class.</p>
|
160
184
|
|
161
185
|
|
162
186
|
</div>
|
@@ -168,8 +192,7 @@ class.</p>
|
|
168
192
|
|
169
193
|
|
170
194
|
<p class="example_title"><div class='inline'>
|
171
|
-
<p>Return false to invocation of <tt>Product#save</tt> for any instance of
|
172
|
-
<code>Product</code>.</p>
|
195
|
+
<p>Return false to invocation of <tt>Product#save</tt> for any instance of <code>Product</code>.</p>
|
173
196
|
</div></p>
|
174
197
|
|
175
198
|
<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>
|
@@ -223,15 +246,15 @@ class.</p>
|
|
223
246
|
<pre class="lines">
|
224
247
|
|
225
248
|
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
249
|
+
45
|
250
|
+
46
|
251
|
+
47
|
252
|
+
48
|
253
|
+
49
|
254
|
+
50</pre>
|
232
255
|
</td>
|
233
256
|
<td>
|
234
|
-
<pre class="code"><span class="info file"># File 'lib/mocha/class_methods.rb', line
|
257
|
+
<pre class="code"><span class="info file"># File 'lib/mocha/class_methods.rb', line 45</span>
|
235
258
|
|
236
259
|
<span class='kw'>def</span> <span class='id identifier rubyid_any_instance'>any_instance</span>
|
237
260
|
<span class='kw'>if</span> <span class='id identifier rubyid_frozen?'>frozen?</span>
|
@@ -242,6 +265,55 @@ class.</p>
|
|
242
265
|
</td>
|
243
266
|
</tr>
|
244
267
|
</table>
|
268
|
+
</div>
|
269
|
+
|
270
|
+
<div class="method_details ">
|
271
|
+
<h3 class="signature " id="method_visibility-instance_method">
|
272
|
+
|
273
|
+
#<strong>method_visibility</strong>(method, include_public_methods = true) ⇒ <tt><span class='object_link'>Object</span></tt>
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
<span class="aliases">Also known as:
|
278
|
+
<span class="names"><span id='method_exists?-instance_method'>method_exists?</span></span>
|
279
|
+
</span>
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
</h3><div class="docstring">
|
284
|
+
<div class="discussion">
|
285
|
+
|
286
|
+
<p>rubocop:disable Metrics/CyclomaticComplexity</p>
|
287
|
+
|
288
|
+
|
289
|
+
</div>
|
290
|
+
</div>
|
291
|
+
<div class="tags">
|
292
|
+
|
293
|
+
|
294
|
+
</div><table class="source_code">
|
295
|
+
<tr>
|
296
|
+
<td>
|
297
|
+
<pre class="lines">
|
298
|
+
|
299
|
+
|
300
|
+
53
|
301
|
+
54
|
302
|
+
55
|
303
|
+
56
|
304
|
+
57</pre>
|
305
|
+
</td>
|
306
|
+
<td>
|
307
|
+
<pre class="code"><span class="info file"># File 'lib/mocha/class_methods.rb', line 53</span>
|
308
|
+
|
309
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_method_visibility'>method_visibility</span><span class='lparen'>(</span><span class='id identifier rubyid_method'>method</span><span class='comma'>,</span> <span class='id identifier rubyid_include_public_methods'>include_public_methods</span> <span class='op'>=</span> <span class='kw'>true</span><span class='rparen'>)</span>
|
310
|
+
<span class='lparen'>(</span><span class='id identifier rubyid_include_public_methods'>include_public_methods</span> <span class='op'>&&</span> <span class='id identifier rubyid_public_method_defined?'>public_method_defined?</span><span class='lparen'>(</span><span class='id identifier rubyid_method'>method</span><span class='rparen'>)</span> <span class='op'>&&</span> <span class='symbol'>:public</span><span class='rparen'>)</span> <span class='op'>||</span>
|
311
|
+
<span class='lparen'>(</span><span class='id identifier rubyid_protected_method_defined?'>protected_method_defined?</span><span class='lparen'>(</span><span class='id identifier rubyid_method'>method</span><span class='rparen'>)</span> <span class='op'>&&</span> <span class='symbol'>:protected</span><span class='rparen'>)</span> <span class='op'>||</span>
|
312
|
+
<span class='lparen'>(</span><span class='id identifier rubyid_private_method_defined?'>private_method_defined?</span><span class='lparen'>(</span><span class='id identifier rubyid_method'>method</span><span class='rparen'>)</span> <span class='op'>&&</span> <span class='symbol'>:private</span><span class='rparen'>)</span>
|
313
|
+
<span class='kw'>end</span></pre>
|
314
|
+
</td>
|
315
|
+
</tr>
|
316
|
+
</table>
|
245
317
|
</div>
|
246
318
|
|
247
319
|
</div>
|
@@ -257,9 +329,9 @@ class.</p>
|
|
257
329
|
</div>
|
258
330
|
|
259
331
|
<div id="footer">
|
260
|
-
Generated on
|
332
|
+
Generated on Sun Nov 24 15:26:49 2019 by
|
261
333
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
262
|
-
0.9.
|
334
|
+
0.9.20 (ruby-2.6.5).
|
263
335
|
</div>
|
264
336
|
|
265
337
|
</div>
|
@@ -6,7 +6,7 @@
|
|
6
6
|
<title>
|
7
7
|
Class: Mocha::Configuration
|
8
8
|
|
9
|
-
— Mocha 1.
|
9
|
+
— Mocha 1.10.0.alpha
|
10
10
|
|
11
11
|
</title>
|
12
12
|
|
@@ -102,46 +102,9 @@
|
|
102
102
|
<h2>Overview</h2><div class="docstring">
|
103
103
|
<div class="discussion">
|
104
104
|
|
105
|
-
<p>This class
|
106
|
-
circumstances. In each scenario, Mocha can be configured to <span class='object_link'><a href="#allow-class_method" title="Mocha::Configuration.allow (method)">do nothing</a></span>, <span class='object_link'><a href="#warn_when-class_method" title="Mocha::Configuration.warn_when (method)">display a warning message</a></span>, or <span class='object_link'><a href="#prevent-class_method" title="Mocha::Configuration.prevent (method)">raise an exception</a></span>. The relevant scenario is identified using one of the following
|
107
|
-
symbols:</p>
|
108
|
-
<ul><li>
|
109
|
-
<p><code>:stubbing_method_unnecessarily</code> This is useful for identifying
|
110
|
-
unused stubs. Unused stubs are often accidentally introduced when code is
|
111
|
-
<a href="http://martinfowler.com/bliki/DefinitionOfRefactoring.html" target="_parent" title="refactored">refactored</a>.
|
112
|
-
Allowed by default.</p>
|
113
|
-
</li><li>
|
114
|
-
<p><code>:stubbing_non_existent_method</code> - This is useful if you want to
|
115
|
-
ensure that methods you're mocking really exist. A common criticism of
|
116
|
-
unit tests with mock objects is that such a test may (incorrectly) pass
|
117
|
-
when an equivalent non-mocking test would (correctly) fail. While you
|
118
|
-
should always have some integration tests, particularly for critical
|
119
|
-
business functionality, this Mocha configuration setting should catch
|
120
|
-
scenarios when mocked methods and real methods have become misaligned.
|
121
|
-
Allowed by default.</p>
|
122
|
-
</li><li>
|
123
|
-
<p><code>:stubbing_non_public_method</code> - Many people think that it's
|
124
|
-
good practice only to mock public methods. This is one way to prevent your
|
125
|
-
tests being too tightly coupled to the internal implementation of a class.
|
126
|
-
Such tests tend to be very brittle and not much use when refactoring.
|
127
|
-
Allowed by default.</p>
|
128
|
-
</li><li>
|
129
|
-
<p><code>:stubbing_method_on_non_mock_object</code> - If you like the idea of
|
130
|
-
<a href="http://www.jmock.org/oopsla2004.pdf" target="_parent" title="mocking roles not objects">mocking roles not objects</a> and
|
131
|
-
<a href="http://www.mockobjects.com/2007/04/test-smell-mocking-concrete-classes.html" target="_parent" title="you don&#39;t like stubbing concrete classes">you don't like stubbing concrete classes</a>, this is the setting for you.
|
132
|
-
However, while this restriction makes a lot of sense in Java with its
|
133
|
-
<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
|
134
|
-
represented as Modules. Allowed by default.</p>
|
135
|
-
</li><li>
|
136
|
-
<p><code>:stubbing_method_on_nil</code> - This is usually done accidentally,
|
137
|
-
but there might be rare cases where it is intended. Prevented by default.</p>
|
138
|
-
</li></ul>
|
105
|
+
<p>This class provides a number of ways to configure the library.</p>
|
139
106
|
|
140
|
-
<p>Typically the configuration
|
141
|
-
<code>test_helper.rb</code> or <code>spec_helper.rb</code> file. However,
|
142
|
-
it can also be temporarily overridden locally using the block syntax of the
|
143
|
-
relevant method. In the latter case, the original configuration settings
|
144
|
-
are restored when the block is exited.</p>
|
107
|
+
<p>Typically the configuration is set globally in a <code>test_helper.rb</code> or <code>spec_helper.rb</code> file.</p>
|
145
108
|
|
146
109
|
|
147
110
|
</div>
|
@@ -153,125 +116,247 @@ are restored when the block is exited.</p>
|
|
153
116
|
|
154
117
|
|
155
118
|
<p class="example_title"><div class='inline'>
|
156
|
-
<p>
|
119
|
+
<p>Setting multiple configuration options</p>
|
157
120
|
</div></p>
|
158
121
|
|
159
|
-
<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='
|
160
|
-
|
161
|
-
<span class='id identifier
|
162
|
-
<span class='id identifier
|
163
|
-
<span class='
|
164
|
-
</span><span class='comment'># => #<Mock:example>.unused_stub(any_parameters)</span></code></pre>
|
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>
|
165
127
|
|
166
|
-
|
167
|
-
<p class="example_title"><div class='inline'>
|
168
|
-
<p>Preventing stubbing of a method on a non-mock object</p>
|
169
|
-
</div></p>
|
170
|
-
|
171
|
-
<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'>Configuration</span><span class='period'>.</span><span class='id identifier rubyid_prevent'><span class='object_link'><a href="#prevent-class_method" title="Mocha::Configuration.prevent (method)">prevent</a></span></span><span class='lparen'>(</span><span class='symbol'>:stubbing_method_on_non_mock_object</span><span class='rparen'>)</span>
|
128
|
+
</div>
|
172
129
|
|
173
|
-
<span class='kw'>class</span> <span class='const'>Example</span>
|
174
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_example_method'>example_method</span><span class='semicolon'>;</span> <span class='kw'>end</span>
|
175
|
-
<span class='kw'>end</span>
|
176
130
|
|
177
|
-
|
178
|
-
<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>
|
179
|
-
<span class='comment'># => Mocha::StubbingError: stubbing method on non-mock object:
|
180
|
-
</span><span class='comment'># => #<Example:0x593620>.example_method</span></code></pre>
|
181
|
-
|
182
|
-
|
183
|
-
<p class="example_title"><div class='inline'>
|
184
|
-
<p>Preventing stubbing of a non-existent method</p>
|
185
|
-
</div></p>
|
186
|
-
|
187
|
-
<pre class="example code"><code>
|
188
|
-
<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'>Configuration</span><span class='period'>.</span><span class='id identifier rubyid_prevent'><span class='object_link'><a href="#prevent-class_method" title="Mocha::Configuration.prevent (method)">prevent</a></span></span><span class='lparen'>(</span><span class='symbol'>:stubbing_non_existent_method</span><span class='rparen'>)</span>
|
131
|
+
</div>
|
189
132
|
|
190
|
-
<span class='kw'>class</span> <span class='const'>Example</span>
|
191
|
-
<span class='kw'>end</span>
|
192
133
|
|
193
|
-
<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>
|
194
|
-
<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>
|
195
|
-
<span class='comment'># => Mocha::StubbingError: stubbing non-existent method:
|
196
|
-
</span><span class='comment'># => #<Example:0x593760>.method_that_doesnt_exist</span></code></pre>
|
197
|
-
|
198
|
-
|
199
|
-
<p class="example_title"><div class='inline'>
|
200
|
-
<p>Preventing stubbing of a non-public method</p>
|
201
|
-
</div></p>
|
202
|
-
|
203
|
-
<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'>Configuration</span><span class='period'>.</span><span class='id identifier rubyid_prevent'><span class='object_link'><a href="#prevent-class_method" title="Mocha::Configuration.prevent (method)">prevent</a></span></span><span class='lparen'>(</span><span class='symbol'>:stubbing_non_public_method</span><span class='rparen'>)</span>
|
204
134
|
|
205
|
-
<span class='kw'>class</span> <span class='const'>Example</span>
|
206
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_internal_method'>internal_method</span><span class='semicolon'>;</span> <span class='kw'>end</span>
|
207
|
-
<span class='id identifier rubyid_private'>private</span> <span class='symbol'>:internal_method</span>
|
208
|
-
<span class='kw'>end</span>
|
209
135
|
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
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">
|
214
148
|
|
149
|
+
<a href="#allow-class_method" title="allow (class method)">.<strong>allow</strong>(action) { ... } ⇒ 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
|
+
|
215
180
|
|
216
|
-
<
|
217
|
-
<
|
218
|
-
|
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) { ... } ⇒ 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
|
+
|
219
204
|
|
220
|
-
|
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) { ... } ⇒ Object </a>
|
209
|
+
|
221
210
|
|
222
|
-
|
223
|
-
|
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) { ... } ⇒ Object </a>
|
244
|
+
|
224
245
|
|
225
|
-
<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'>Configuration</span><span class='period'>.</span><span class='id identifier rubyid_allow'><span class='object_link'><a href="#allow-class_method" title="Mocha::Configuration.allow (method)">allow</a></span></span><span class='lparen'>(</span><span class='symbol'>:stubbing_non_existent_method</span><span class='rparen'>)</span> <span class='kw'>do</span>
|
226
|
-
<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>
|
227
|
-
<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>
|
228
|
-
<span class='comment'># => no exception raised
|
229
|
-
</span><span class='kw'>end</span></code></pre>
|
230
246
|
|
231
|
-
</
|
247
|
+
</span>
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
<span class="deprecated note title">deprecated</span>
|
254
|
+
|
232
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>
|
233
273
|
|
234
|
-
|
274
|
+
|
275
|
+
</ul>
|
235
276
|
|
236
277
|
<h2>
|
237
|
-
|
238
|
-
<small><a href="#" class="
|
278
|
+
Instance Method Summary
|
279
|
+
<small><a href="#" class="summary_toggle">collapse</a></small>
|
239
280
|
</h2>
|
240
281
|
|
241
|
-
<
|
242
|
-
|
243
|
-
<dt id="DEFAULTS-constant" class="">DEFAULTS =
|
244
|
-
|
245
|
-
</dt>
|
246
|
-
<dd><pre class="code"><span class='lbrace'>{</span>
|
247
|
-
<span class='symbol'>:stubbing_method_unnecessarily</span> <span class='op'>=></span> <span class='symbol'>:allow</span><span class='comma'>,</span>
|
248
|
-
<span class='symbol'>:stubbing_method_on_non_mock_object</span> <span class='op'>=></span> <span class='symbol'>:allow</span><span class='comma'>,</span>
|
249
|
-
<span class='symbol'>:stubbing_non_existent_method</span> <span class='op'>=></span> <span class='symbol'>:allow</span><span class='comma'>,</span>
|
250
|
-
<span class='symbol'>:stubbing_non_public_method</span> <span class='op'>=></span> <span class='symbol'>:allow</span><span class='comma'>,</span>
|
251
|
-
<span class='symbol'>:stubbing_method_on_nil</span> <span class='op'>=></span> <span class='symbol'>:prevent</span>
|
252
|
-
<span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_freeze'>freeze</span></pre></dd>
|
282
|
+
<ul class="summary">
|
253
283
|
|
254
|
-
|
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) ⇒ Object </a>
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
</span>
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
|
255
298
|
|
256
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>
|
257
306
|
|
307
|
+
|
308
|
+
<li class="public ">
|
309
|
+
<span class="summary_signature">
|
310
|
+
|
311
|
+
<a href="#stubbing_method_on_nil=-instance_method" title="#stubbing_method_on_nil= (instance method)">#<strong>stubbing_method_on_nil=</strong>(value) ⇒ Object </a>
|
312
|
+
|
258
313
|
|
314
|
+
|
315
|
+
</span>
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
|
322
|
+
|
259
323
|
|
324
|
+
|
325
|
+
<span class="summary_desc"><div class='inline'>
|
326
|
+
<p>Configure whether stubbing methods on the <code>nil</code> object is allowed.</p>
|
327
|
+
</div></span>
|
328
|
+
|
329
|
+
</li>
|
260
330
|
|
331
|
+
|
332
|
+
<li class="public ">
|
333
|
+
<span class="summary_signature">
|
334
|
+
|
335
|
+
<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) ⇒ Object </a>
|
336
|
+
|
261
337
|
|
338
|
+
|
339
|
+
</span>
|
340
|
+
|
341
|
+
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
|
346
|
+
|
262
347
|
|
263
348
|
|
264
|
-
<
|
265
|
-
|
266
|
-
|
267
|
-
|
349
|
+
<span class="summary_desc"><div class='inline'>
|
350
|
+
<p>Configure whether stubbing methods on non-mock objects is allowed.</p>
|
351
|
+
</div></span>
|
352
|
+
|
353
|
+
</li>
|
268
354
|
|
269
|
-
<ul class="summary">
|
270
355
|
|
271
356
|
<li class="public ">
|
272
357
|
<span class="summary_signature">
|
273
358
|
|
274
|
-
<a href="#
|
359
|
+
<a href="#stubbing_method_unnecessarily=-instance_method" title="#stubbing_method_unnecessarily= (instance method)">#<strong>stubbing_method_unnecessarily=</strong>(value) ⇒ Object </a>
|
275
360
|
|
276
361
|
|
277
362
|
|
@@ -286,7 +371,7 @@ are restored when the block is exited.</p>
|
|
286
371
|
|
287
372
|
|
288
373
|
<span class="summary_desc"><div class='inline'>
|
289
|
-
<p>
|
374
|
+
<p>Configure whether stubbing methods unnecessarily is allowed.</p>
|
290
375
|
</div></span>
|
291
376
|
|
292
377
|
</li>
|
@@ -295,7 +380,7 @@ are restored when the block is exited.</p>
|
|
295
380
|
<li class="public ">
|
296
381
|
<span class="summary_signature">
|
297
382
|
|
298
|
-
<a href="#
|
383
|
+
<a href="#stubbing_non_existent_method=-instance_method" title="#stubbing_non_existent_method= (instance method)">#<strong>stubbing_non_existent_method=</strong>(value) ⇒ Object </a>
|
299
384
|
|
300
385
|
|
301
386
|
|
@@ -310,8 +395,7 @@ are restored when the block is exited.</p>
|
|
310
395
|
|
311
396
|
|
312
397
|
<span class="summary_desc"><div class='inline'>
|
313
|
-
<p>
|
314
|
-
attempted.</p>
|
398
|
+
<p>Configure whether stubbing of non-existent methods is allowed.</p>
|
315
399
|
</div></span>
|
316
400
|
|
317
401
|
</li>
|
@@ -320,7 +404,7 @@ attempted.</p>
|
|
320
404
|
<li class="public ">
|
321
405
|
<span class="summary_signature">
|
322
406
|
|
323
|
-
<a href="#
|
407
|
+
<a href="#stubbing_non_public_method=-instance_method" title="#stubbing_non_public_method= (instance method)">#<strong>stubbing_non_public_method=</strong>(value) ⇒ Object </a>
|
324
408
|
|
325
409
|
|
326
410
|
|
@@ -335,7 +419,7 @@ attempted.</p>
|
|
335
419
|
|
336
420
|
|
337
421
|
<span class="summary_desc"><div class='inline'>
|
338
|
-
<p>
|
422
|
+
<p>Configure whether stubbing of non-public methods is allowed.</p>
|
339
423
|
</div></span>
|
340
424
|
|
341
425
|
</li>
|
@@ -361,7 +445,21 @@ attempted.</p>
|
|
361
445
|
|
362
446
|
</h3><div class="docstring">
|
363
447
|
<div class="discussion">
|
364
|
-
|
448
|
+
<div class="note deprecated"><strong>Deprecated.</strong> <div class='inline'>
|
449
|
+
<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>
|
450
|
+
<ul><li>
|
451
|
+
<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>
|
452
|
+
</li><li>
|
453
|
+
<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>
|
454
|
+
</li><li>
|
455
|
+
<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>
|
456
|
+
</li><li>
|
457
|
+
<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>
|
458
|
+
</li><li>
|
459
|
+
<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>
|
460
|
+
</li></ul>
|
461
|
+
</div></div>
|
462
|
+
|
365
463
|
<p>Allow the specified <code>action</code>.</p>
|
366
464
|
|
367
465
|
|
@@ -382,11 +480,7 @@ attempted.</p>
|
|
382
480
|
|
383
481
|
—
|
384
482
|
<div class='inline'>
|
385
|
-
<p>one of <code>:stubbing_method_unnecessarily</code>,
|
386
|
-
<code>:stubbing_method_on_non_mock_object</code>,
|
387
|
-
<code>:stubbing_non_existent_method</code>,
|
388
|
-
<code>:stubbing_non_public_method</code>,
|
389
|
-
<code>:stubbing_method_on_nil</code>.</p>
|
483
|
+
<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>
|
390
484
|
</div>
|
391
485
|
|
392
486
|
</li>
|
@@ -405,8 +499,7 @@ attempted.</p>
|
|
405
499
|
|
406
500
|
|
407
501
|
<div class='inline'>
|
408
|
-
<p>optional block during which the configuration change will be changed before
|
409
|
-
being returned to its original value at the end of the block.</p>
|
502
|
+
<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>
|
410
503
|
</div>
|
411
504
|
|
412
505
|
</li>
|
@@ -419,14 +512,24 @@ being returned to its original value at the end of the block.</p>
|
|
419
512
|
<pre class="lines">
|
420
513
|
|
421
514
|
|
422
|
-
|
423
|
-
|
424
|
-
|
515
|
+
261
|
516
|
+
262
|
517
|
+
263
|
518
|
+
264
|
519
|
+
265
|
520
|
+
266
|
521
|
+
267
|
522
|
+
268</pre>
|
425
523
|
</td>
|
426
524
|
<td>
|
427
|
-
<pre class="code"><span class="info file"># File 'lib/mocha/configuration.rb', line
|
525
|
+
<pre class="code"><span class="info file"># File 'lib/mocha/configuration.rb', line 261</span>
|
428
526
|
|
429
527
|
<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'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
528
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_block_given?'>block_given?</span>
|
529
|
+
<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'>"</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'>"</span></span><span class='rparen'>)</span>
|
530
|
+
<span class='kw'>else</span>
|
531
|
+
<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'>"</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'>"</span></span><span class='rparen'>)</span>
|
532
|
+
<span class='kw'>end</span>
|
430
533
|
<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'>&</span><span class='id identifier rubyid_block'>block</span>
|
431
534
|
<span class='kw'>end</span></pre>
|
432
535
|
</td>
|
@@ -435,9 +538,9 @@ being returned to its original value at the end of the block.</p>
|
|
435
538
|
</div>
|
436
539
|
|
437
540
|
<div class="method_details ">
|
438
|
-
<h3 class="signature " id="
|
541
|
+
<h3 class="signature " id="override-class_method">
|
439
542
|
|
440
|
-
.<strong>
|
543
|
+
.<strong>override</strong>(temporary_options) { ... } ⇒ <tt><span class='object_link'>Object</span></tt>
|
441
544
|
|
442
545
|
|
443
546
|
|
@@ -446,32 +549,43 @@ being returned to its original value at the end of the block.</p>
|
|
446
549
|
</h3><div class="docstring">
|
447
550
|
<div class="discussion">
|
448
551
|
|
449
|
-
<p>
|
450
|
-
|
552
|
+
<p>Temporarily modify <span class='object_link'><a href="" title="Mocha::Configuration (class)">Mocha::Configuration</a></span> options.</p>
|
553
|
+
|
554
|
+
<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>
|
451
555
|
|
452
556
|
|
453
557
|
</div>
|
454
558
|
</div>
|
455
559
|
<div class="tags">
|
456
|
-
|
560
|
+
|
561
|
+
<div class="examples">
|
562
|
+
<p class="tag_title">Examples:</p>
|
563
|
+
|
564
|
+
|
565
|
+
<p class="example_title"><div class='inline'>
|
566
|
+
<p>Temporarily allow stubbing of <code>nil</code></p>
|
567
|
+
</div></p>
|
568
|
+
|
569
|
+
<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>
|
570
|
+
<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>
|
571
|
+
<span class='kw'>end</span></code></pre>
|
572
|
+
|
573
|
+
</div>
|
574
|
+
<p class="tag_title">Parameters:</p>
|
457
575
|
<ul class="param">
|
458
576
|
|
459
577
|
<li>
|
460
578
|
|
461
|
-
<span class='name'>
|
579
|
+
<span class='name'>temporary_options</span>
|
462
580
|
|
463
581
|
|
464
|
-
<span class='type'>(<tt>
|
582
|
+
<span class='type'>(<tt>Hash</tt>)</span>
|
465
583
|
|
466
584
|
|
467
585
|
|
468
586
|
—
|
469
587
|
<div class='inline'>
|
470
|
-
<p>
|
471
|
-
<code>:stubbing_method_on_non_mock_object</code>,
|
472
|
-
<code>:stubbing_non_existent_method</code>,
|
473
|
-
<code>:stubbing_non_public_method</code>,
|
474
|
-
<code>:stubbing_method_on_nil</code>.</p>
|
588
|
+
<p>the configuration options to apply for the duration of the block.</p>
|
475
589
|
</div>
|
476
590
|
|
477
591
|
</li>
|
@@ -490,8 +604,7 @@ attempted.</p>
|
|
490
604
|
|
491
605
|
|
492
606
|
<div class='inline'>
|
493
|
-
<p>
|
494
|
-
being returned to its original value at the end of the block.</p>
|
607
|
+
<p>block during which the configuration change will be in force.</p>
|
495
608
|
</div>
|
496
609
|
|
497
610
|
</li>
|
@@ -504,14 +617,125 @@ being returned to its original value at the end of the block.</p>
|
|
504
617
|
<pre class="lines">
|
505
618
|
|
506
619
|
|
507
|
-
|
508
|
-
|
509
|
-
|
620
|
+
340
|
621
|
+
341
|
622
|
+
342
|
623
|
+
343
|
624
|
+
344
|
625
|
+
345
|
626
|
+
346</pre>
|
510
627
|
</td>
|
511
628
|
<td>
|
512
|
-
<pre class="code"><span class="info file"># File 'lib/mocha/configuration.rb', line
|
513
|
-
|
629
|
+
<pre class="code"><span class="info file"># File 'lib/mocha/configuration.rb', line 340</span>
|
630
|
+
|
631
|
+
<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>
|
632
|
+
<span class='id identifier rubyid_original_configuration'>original_configuration</span> <span class='op'>=</span> <span class='id identifier rubyid_configuration'>configuration</span>
|
633
|
+
<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>
|
634
|
+
<span class='kw'>yield</span>
|
635
|
+
<span class='kw'>ensure</span>
|
636
|
+
<span class='ivar'>@configuration</span> <span class='op'>=</span> <span class='id identifier rubyid_original_configuration'>original_configuration</span>
|
637
|
+
<span class='kw'>end</span></pre>
|
638
|
+
</td>
|
639
|
+
</tr>
|
640
|
+
</table>
|
641
|
+
</div>
|
642
|
+
|
643
|
+
<div class="method_details ">
|
644
|
+
<h3 class="signature " id="prevent-class_method">
|
645
|
+
|
646
|
+
.<strong>prevent</strong>(action) { ... } ⇒ <tt><span class='object_link'>Object</span></tt>
|
647
|
+
|
648
|
+
|
649
|
+
|
650
|
+
|
651
|
+
|
652
|
+
</h3><div class="docstring">
|
653
|
+
<div class="discussion">
|
654
|
+
<div class="note deprecated"><strong>Deprecated.</strong> <div class='inline'>
|
655
|
+
<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>
|
656
|
+
<ul><li>
|
657
|
+
<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>
|
658
|
+
</li><li>
|
659
|
+
<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>
|
660
|
+
</li><li>
|
661
|
+
<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>
|
662
|
+
</li><li>
|
663
|
+
<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>
|
664
|
+
</li><li>
|
665
|
+
<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>
|
666
|
+
</li></ul>
|
667
|
+
</div></div>
|
668
|
+
|
669
|
+
<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>
|
670
|
+
|
671
|
+
|
672
|
+
</div>
|
673
|
+
</div>
|
674
|
+
<div class="tags">
|
675
|
+
<p class="tag_title">Parameters:</p>
|
676
|
+
<ul class="param">
|
677
|
+
|
678
|
+
<li>
|
679
|
+
|
680
|
+
<span class='name'>action</span>
|
681
|
+
|
682
|
+
|
683
|
+
<span class='type'>(<tt>Symbol</tt>)</span>
|
684
|
+
|
685
|
+
|
686
|
+
|
687
|
+
—
|
688
|
+
<div class='inline'>
|
689
|
+
<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>
|
690
|
+
</div>
|
691
|
+
|
692
|
+
</li>
|
693
|
+
|
694
|
+
</ul>
|
695
|
+
|
696
|
+
<p class="tag_title">Yields:</p>
|
697
|
+
<ul class="yield">
|
698
|
+
|
699
|
+
<li>
|
700
|
+
|
701
|
+
|
702
|
+
<span class='type'></span>
|
703
|
+
|
704
|
+
|
705
|
+
|
706
|
+
|
707
|
+
<div class='inline'>
|
708
|
+
<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>
|
709
|
+
</div>
|
710
|
+
|
711
|
+
</li>
|
712
|
+
|
713
|
+
</ul>
|
714
|
+
|
715
|
+
</div><table class="source_code">
|
716
|
+
<tr>
|
717
|
+
<td>
|
718
|
+
<pre class="lines">
|
719
|
+
|
720
|
+
|
721
|
+
309
|
722
|
+
310
|
723
|
+
311
|
724
|
+
312
|
725
|
+
313
|
726
|
+
314
|
727
|
+
315
|
728
|
+
316</pre>
|
729
|
+
</td>
|
730
|
+
<td>
|
731
|
+
<pre class="code"><span class="info file"># File 'lib/mocha/configuration.rb', line 309</span>
|
732
|
+
|
514
733
|
<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'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
734
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_block_given?'>block_given?</span>
|
735
|
+
<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'>"</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'>"</span></span><span class='rparen'>)</span>
|
736
|
+
<span class='kw'>else</span>
|
737
|
+
<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'>"</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'>"</span></span><span class='rparen'>)</span>
|
738
|
+
<span class='kw'>end</span>
|
515
739
|
<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'>&</span><span class='id identifier rubyid_block'>block</span>
|
516
740
|
<span class='kw'>end</span></pre>
|
517
741
|
</td>
|
@@ -530,7 +754,21 @@ being returned to its original value at the end of the block.</p>
|
|
530
754
|
|
531
755
|
</h3><div class="docstring">
|
532
756
|
<div class="discussion">
|
533
|
-
|
757
|
+
<div class="note deprecated"><strong>Deprecated.</strong> <div class='inline'>
|
758
|
+
<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>
|
759
|
+
<ul><li>
|
760
|
+
<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>
|
761
|
+
</li><li>
|
762
|
+
<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>
|
763
|
+
</li><li>
|
764
|
+
<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>
|
765
|
+
</li><li>
|
766
|
+
<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>
|
767
|
+
</li><li>
|
768
|
+
<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>
|
769
|
+
</li></ul>
|
770
|
+
</div></div>
|
771
|
+
|
534
772
|
<p>Warn if the specified <code>action</code> is attempted.</p>
|
535
773
|
|
536
774
|
|
@@ -551,11 +789,7 @@ being returned to its original value at the end of the block.</p>
|
|
551
789
|
|
552
790
|
—
|
553
791
|
<div class='inline'>
|
554
|
-
<p>one of <code>:stubbing_method_unnecessarily</code>,
|
555
|
-
<code>:stubbing_method_on_non_mock_object</code>,
|
556
|
-
<code>:stubbing_non_existent_method</code>,
|
557
|
-
<code>:stubbing_non_public_method</code>,
|
558
|
-
<code>:stubbing_method_on_nil</code>.</p>
|
792
|
+
<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>
|
559
793
|
</div>
|
560
794
|
|
561
795
|
</li>
|
@@ -574,8 +808,7 @@ being returned to its original value at the end of the block.</p>
|
|
574
808
|
|
575
809
|
|
576
810
|
<div class='inline'>
|
577
|
-
<p>optional block during which the configuration change will be changed before
|
578
|
-
being returned to its original value at the end of the block.</p>
|
811
|
+
<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>
|
579
812
|
</div>
|
580
813
|
|
581
814
|
</li>
|
@@ -588,19 +821,543 @@ being returned to its original value at the end of the block.</p>
|
|
588
821
|
<pre class="lines">
|
589
822
|
|
590
823
|
|
591
|
-
|
592
|
-
|
593
|
-
|
824
|
+
285
|
825
|
+
286
|
826
|
+
287
|
827
|
+
288
|
828
|
+
289
|
829
|
+
290
|
830
|
+
291
|
831
|
+
292</pre>
|
594
832
|
</td>
|
595
833
|
<td>
|
596
|
-
<pre class="code"><span class="info file"># File 'lib/mocha/configuration.rb', line
|
834
|
+
<pre class="code"><span class="info file"># File 'lib/mocha/configuration.rb', line 285</span>
|
597
835
|
|
598
836
|
<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'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
837
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_block_given?'>block_given?</span>
|
838
|
+
<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'>"</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'>"</span></span><span class='rparen'>)</span>
|
839
|
+
<span class='kw'>else</span>
|
840
|
+
<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'>"</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'>"</span></span><span class='rparen'>)</span>
|
841
|
+
<span class='kw'>end</span>
|
599
842
|
<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'>&</span><span class='id identifier rubyid_block'>block</span>
|
600
843
|
<span class='kw'>end</span></pre>
|
601
844
|
</td>
|
602
845
|
</tr>
|
603
846
|
</table>
|
847
|
+
</div>
|
848
|
+
|
849
|
+
</div>
|
850
|
+
|
851
|
+
<div id="instance_method_details" class="method_details_list">
|
852
|
+
<h2>Instance Method Details</h2>
|
853
|
+
|
854
|
+
|
855
|
+
<div class="method_details first">
|
856
|
+
<h3 class="signature first" id="display_matching_invocations_on_failure=-instance_method">
|
857
|
+
|
858
|
+
#<strong>display_matching_invocations_on_failure=</strong>(value) ⇒ <tt><span class='object_link'>Object</span></tt>
|
859
|
+
|
860
|
+
|
861
|
+
|
862
|
+
|
863
|
+
|
864
|
+
</h3><div class="docstring">
|
865
|
+
<div class="discussion">
|
866
|
+
|
867
|
+
<p>Display matching invocations alongside expectations on Mocha-related test failure.</p>
|
868
|
+
|
869
|
+
|
870
|
+
</div>
|
871
|
+
</div>
|
872
|
+
<div class="tags">
|
873
|
+
|
874
|
+
<div class="examples">
|
875
|
+
<p class="tag_title">Examples:</p>
|
876
|
+
|
877
|
+
|
878
|
+
<p class="example_title"><div class='inline'>
|
879
|
+
<p>Enable display of matching invocations</p>
|
880
|
+
</div></p>
|
881
|
+
|
882
|
+
<pre class="example code"><code>Mocha.configure do |c|
|
883
|
+
c.display_matching_invocations_on_failure = true
|
884
|
+
end
|
885
|
+
|
886
|
+
foo = mock('foo')
|
887
|
+
foo.expects(:bar)
|
888
|
+
foo.stubs(:baz).returns('baz').raises(RuntimeError).throws(:tag, 'value')
|
889
|
+
|
890
|
+
foo.baz(1, 2)
|
891
|
+
assert_raises(RuntimeError) { foo.baz(3, 4) }
|
892
|
+
assert_throws(:tag) { foo.baz(5, 6) }
|
893
|
+
|
894
|
+
not all expectations were satisfied
|
895
|
+
unsatisfied expectations:
|
896
|
+
- expected exactly once, invoked never: #<Mock:foo>.bar
|
897
|
+
satisfied expectations:
|
898
|
+
- allowed any number of times, invoked 3 times: #<Mock:foo>.baz(any_parameters)
|
899
|
+
- #<Mock:foo>.baz(1, 2) # => "baz"
|
900
|
+
- #<Mock:foo>.baz(3, 4) # => raised RuntimeError
|
901
|
+
- #<Mock:foo>.baz(5, 6) # => threw (:tag, "value")</code></pre>
|
902
|
+
|
903
|
+
</div>
|
904
|
+
<p class="tag_title">Parameters:</p>
|
905
|
+
<ul class="param">
|
906
|
+
|
907
|
+
<li>
|
908
|
+
|
909
|
+
<span class='name'>value</span>
|
910
|
+
|
911
|
+
|
912
|
+
<span class='type'>(<tt>Boolean</tt>)</span>
|
913
|
+
|
914
|
+
|
915
|
+
|
916
|
+
—
|
917
|
+
<div class='inline'>
|
918
|
+
<p><code>true</code> to enable display of matching invocations; disabled by default.</p>
|
919
|
+
</div>
|
920
|
+
|
921
|
+
</li>
|
922
|
+
|
923
|
+
</ul>
|
924
|
+
|
925
|
+
|
926
|
+
</div><table class="source_code">
|
927
|
+
<tr>
|
928
|
+
<td>
|
929
|
+
<pre class="lines">
|
930
|
+
|
931
|
+
|
932
|
+
241
|
933
|
+
242
|
934
|
+
243</pre>
|
935
|
+
</td>
|
936
|
+
<td>
|
937
|
+
<pre class="code"><span class="info file"># File 'lib/mocha/configuration.rb', line 241</span>
|
938
|
+
|
939
|
+
<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>
|
940
|
+
<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>
|
941
|
+
<span class='kw'>end</span></pre>
|
942
|
+
</td>
|
943
|
+
</tr>
|
944
|
+
</table>
|
945
|
+
</div>
|
946
|
+
|
947
|
+
<div class="method_details ">
|
948
|
+
<h3 class="signature " id="stubbing_method_on_nil=-instance_method">
|
949
|
+
|
950
|
+
#<strong>stubbing_method_on_nil=</strong>(value) ⇒ <tt><span class='object_link'>Object</span></tt>
|
951
|
+
|
952
|
+
|
953
|
+
|
954
|
+
|
955
|
+
|
956
|
+
</h3><div class="docstring">
|
957
|
+
<div class="discussion">
|
958
|
+
|
959
|
+
<p>Configure whether stubbing methods on the <code>nil</code> object is allowed.</p>
|
960
|
+
|
961
|
+
<p>This is usually done accidentally, but there might be rare cases where it is intended.</p>
|
962
|
+
|
963
|
+
<p>This option only works for Ruby < 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>
|
964
|
+
|
965
|
+
<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>
|
966
|
+
|
967
|
+
|
968
|
+
</div>
|
969
|
+
</div>
|
970
|
+
<div class="tags">
|
971
|
+
<p class="tag_title">Parameters:</p>
|
972
|
+
<ul class="param">
|
973
|
+
|
974
|
+
<li>
|
975
|
+
|
976
|
+
<span class='name'>value</span>
|
977
|
+
|
978
|
+
|
979
|
+
<span class='type'>(<tt>Symbol</tt>)</span>
|
980
|
+
|
981
|
+
|
982
|
+
|
983
|
+
—
|
984
|
+
<div class='inline'>
|
985
|
+
<p>one of <code>:allow</code>, <code>:warn</code>, <code>:prevent</code>.</p>
|
986
|
+
</div>
|
987
|
+
|
988
|
+
</li>
|
989
|
+
|
990
|
+
</ul>
|
991
|
+
|
992
|
+
|
993
|
+
</div><table class="source_code">
|
994
|
+
<tr>
|
995
|
+
<td>
|
996
|
+
<pre class="lines">
|
997
|
+
|
998
|
+
|
999
|
+
207
|
1000
|
+
208
|
1001
|
+
209</pre>
|
1002
|
+
</td>
|
1003
|
+
<td>
|
1004
|
+
<pre class="code"><span class="info file"># File 'lib/mocha/configuration.rb', line 207</span>
|
1005
|
+
|
1006
|
+
<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>
|
1007
|
+
<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>
|
1008
|
+
<span class='kw'>end</span></pre>
|
1009
|
+
</td>
|
1010
|
+
</tr>
|
1011
|
+
</table>
|
1012
|
+
</div>
|
1013
|
+
|
1014
|
+
<div class="method_details ">
|
1015
|
+
<h3 class="signature " id="stubbing_method_on_non_mock_object=-instance_method">
|
1016
|
+
|
1017
|
+
#<strong>stubbing_method_on_non_mock_object=</strong>(value) ⇒ <tt><span class='object_link'>Object</span></tt>
|
1018
|
+
|
1019
|
+
|
1020
|
+
|
1021
|
+
|
1022
|
+
|
1023
|
+
</h3><div class="docstring">
|
1024
|
+
<div class="discussion">
|
1025
|
+
|
1026
|
+
<p>Configure whether stubbing methods on non-mock objects is allowed.</p>
|
1027
|
+
|
1028
|
+
<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&#39;t like stubbing concrete classes">you don'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>
|
1029
|
+
|
1030
|
+
<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>
|
1031
|
+
|
1032
|
+
|
1033
|
+
</div>
|
1034
|
+
</div>
|
1035
|
+
<div class="tags">
|
1036
|
+
|
1037
|
+
<div class="examples">
|
1038
|
+
<p class="tag_title">Examples:</p>
|
1039
|
+
|
1040
|
+
|
1041
|
+
<p class="example_title"><div class='inline'>
|
1042
|
+
<p>Preventing stubbing of a method on a non-mock object</p>
|
1043
|
+
</div></p>
|
1044
|
+
|
1045
|
+
<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>
|
1046
|
+
<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>
|
1047
|
+
<span class='kw'>end</span>
|
1048
|
+
|
1049
|
+
<span class='kw'>class</span> <span class='const'>Example</span>
|
1050
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_example_method'>example_method</span><span class='semicolon'>;</span> <span class='kw'>end</span>
|
1051
|
+
<span class='kw'>end</span>
|
1052
|
+
|
1053
|
+
<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>
|
1054
|
+
<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>
|
1055
|
+
<span class='comment'># => Mocha::StubbingError: stubbing method on non-mock object:
|
1056
|
+
</span><span class='comment'># => #<Example:0x593620>.example_method</span></code></pre>
|
1057
|
+
|
1058
|
+
</div>
|
1059
|
+
<p class="tag_title">Parameters:</p>
|
1060
|
+
<ul class="param">
|
1061
|
+
|
1062
|
+
<li>
|
1063
|
+
|
1064
|
+
<span class='name'>value</span>
|
1065
|
+
|
1066
|
+
|
1067
|
+
<span class='type'>(<tt>Symbol</tt>)</span>
|
1068
|
+
|
1069
|
+
|
1070
|
+
|
1071
|
+
—
|
1072
|
+
<div class='inline'>
|
1073
|
+
<p>one of <code>:allow</code>, <code>:warn</code>, <code>:prevent</code>.</p>
|
1074
|
+
</div>
|
1075
|
+
|
1076
|
+
</li>
|
1077
|
+
|
1078
|
+
</ul>
|
1079
|
+
|
1080
|
+
|
1081
|
+
</div><table class="source_code">
|
1082
|
+
<tr>
|
1083
|
+
<td>
|
1084
|
+
<pre class="lines">
|
1085
|
+
|
1086
|
+
|
1087
|
+
119
|
1088
|
+
120
|
1089
|
+
121</pre>
|
1090
|
+
</td>
|
1091
|
+
<td>
|
1092
|
+
<pre class="code"><span class="info file"># File 'lib/mocha/configuration.rb', line 119</span>
|
1093
|
+
|
1094
|
+
<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>
|
1095
|
+
<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>
|
1096
|
+
<span class='kw'>end</span></pre>
|
1097
|
+
</td>
|
1098
|
+
</tr>
|
1099
|
+
</table>
|
1100
|
+
</div>
|
1101
|
+
|
1102
|
+
<div class="method_details ">
|
1103
|
+
<h3 class="signature " id="stubbing_method_unnecessarily=-instance_method">
|
1104
|
+
|
1105
|
+
#<strong>stubbing_method_unnecessarily=</strong>(value) ⇒ <tt><span class='object_link'>Object</span></tt>
|
1106
|
+
|
1107
|
+
|
1108
|
+
|
1109
|
+
|
1110
|
+
|
1111
|
+
</h3><div class="docstring">
|
1112
|
+
<div class="discussion">
|
1113
|
+
|
1114
|
+
<p>Configure whether stubbing methods unnecessarily is allowed.</p>
|
1115
|
+
|
1116
|
+
<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>
|
1117
|
+
|
1118
|
+
<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>
|
1119
|
+
|
1120
|
+
|
1121
|
+
</div>
|
1122
|
+
</div>
|
1123
|
+
<div class="tags">
|
1124
|
+
|
1125
|
+
<div class="examples">
|
1126
|
+
<p class="tag_title">Examples:</p>
|
1127
|
+
|
1128
|
+
|
1129
|
+
<p class="example_title"><div class='inline'>
|
1130
|
+
<p>Preventing unnecessary stubbing of a method</p>
|
1131
|
+
</div></p>
|
1132
|
+
|
1133
|
+
<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>
|
1134
|
+
<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>
|
1135
|
+
<span class='kw'>end</span>
|
1136
|
+
|
1137
|
+
<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'>'</span><span class='tstring_content'>example</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
1138
|
+
<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>
|
1139
|
+
<span class='comment'># => Mocha::StubbingError: stubbing method unnecessarily:
|
1140
|
+
</span><span class='comment'># => #<Mock:example>.unused_stub(any_parameters)</span></code></pre>
|
1141
|
+
|
1142
|
+
</div>
|
1143
|
+
<p class="tag_title">Parameters:</p>
|
1144
|
+
<ul class="param">
|
1145
|
+
|
1146
|
+
<li>
|
1147
|
+
|
1148
|
+
<span class='name'>value</span>
|
1149
|
+
|
1150
|
+
|
1151
|
+
<span class='type'>(<tt>Symbol</tt>)</span>
|
1152
|
+
|
1153
|
+
|
1154
|
+
|
1155
|
+
—
|
1156
|
+
<div class='inline'>
|
1157
|
+
<p>one of <code>:allow</code>, <code>:warn</code>, <code>:prevent</code>.</p>
|
1158
|
+
</div>
|
1159
|
+
|
1160
|
+
</li>
|
1161
|
+
|
1162
|
+
</ul>
|
1163
|
+
|
1164
|
+
|
1165
|
+
</div><table class="source_code">
|
1166
|
+
<tr>
|
1167
|
+
<td>
|
1168
|
+
<pre class="lines">
|
1169
|
+
|
1170
|
+
|
1171
|
+
86
|
1172
|
+
87
|
1173
|
+
88</pre>
|
1174
|
+
</td>
|
1175
|
+
<td>
|
1176
|
+
<pre class="code"><span class="info file"># File 'lib/mocha/configuration.rb', line 86</span>
|
1177
|
+
|
1178
|
+
<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>
|
1179
|
+
<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>
|
1180
|
+
<span class='kw'>end</span></pre>
|
1181
|
+
</td>
|
1182
|
+
</tr>
|
1183
|
+
</table>
|
1184
|
+
</div>
|
1185
|
+
|
1186
|
+
<div class="method_details ">
|
1187
|
+
<h3 class="signature " id="stubbing_non_existent_method=-instance_method">
|
1188
|
+
|
1189
|
+
#<strong>stubbing_non_existent_method=</strong>(value) ⇒ <tt><span class='object_link'>Object</span></tt>
|
1190
|
+
|
1191
|
+
|
1192
|
+
|
1193
|
+
|
1194
|
+
|
1195
|
+
</h3><div class="docstring">
|
1196
|
+
<div class="discussion">
|
1197
|
+
|
1198
|
+
<p>Configure whether stubbing of non-existent methods is allowed.</p>
|
1199
|
+
|
1200
|
+
<p>This is useful if you want to ensure that methods you'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>
|
1201
|
+
|
1202
|
+
<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>
|
1203
|
+
|
1204
|
+
|
1205
|
+
</div>
|
1206
|
+
</div>
|
1207
|
+
<div class="tags">
|
1208
|
+
|
1209
|
+
<div class="examples">
|
1210
|
+
<p class="tag_title">Examples:</p>
|
1211
|
+
|
1212
|
+
|
1213
|
+
<p class="example_title"><div class='inline'>
|
1214
|
+
<p>Preventing stubbing of a non-existent method</p>
|
1215
|
+
</div></p>
|
1216
|
+
|
1217
|
+
<pre class="example code"><code>
|
1218
|
+
<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>
|
1219
|
+
<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>
|
1220
|
+
<span class='kw'>end</span>
|
1221
|
+
|
1222
|
+
<span class='kw'>class</span> <span class='const'>Example</span>
|
1223
|
+
<span class='kw'>end</span>
|
1224
|
+
|
1225
|
+
<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>
|
1226
|
+
<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>
|
1227
|
+
<span class='comment'># => Mocha::StubbingError: stubbing non-existent method:
|
1228
|
+
</span><span class='comment'># => #<Example:0x593760>.method_that_doesnt_exist</span></code></pre>
|
1229
|
+
|
1230
|
+
</div>
|
1231
|
+
<p class="tag_title">Parameters:</p>
|
1232
|
+
<ul class="param">
|
1233
|
+
|
1234
|
+
<li>
|
1235
|
+
|
1236
|
+
<span class='name'>value</span>
|
1237
|
+
|
1238
|
+
|
1239
|
+
<span class='type'>(<tt>Symbol</tt>)</span>
|
1240
|
+
|
1241
|
+
|
1242
|
+
|
1243
|
+
—
|
1244
|
+
<div class='inline'>
|
1245
|
+
<p>one of <code>:allow</code>, <code>:warn</code>, <code>:prevent</code>.</p>
|
1246
|
+
</div>
|
1247
|
+
|
1248
|
+
</li>
|
1249
|
+
|
1250
|
+
</ul>
|
1251
|
+
|
1252
|
+
|
1253
|
+
</div><table class="source_code">
|
1254
|
+
<tr>
|
1255
|
+
<td>
|
1256
|
+
<pre class="lines">
|
1257
|
+
|
1258
|
+
|
1259
|
+
152
|
1260
|
+
153
|
1261
|
+
154</pre>
|
1262
|
+
</td>
|
1263
|
+
<td>
|
1264
|
+
<pre class="code"><span class="info file"># File 'lib/mocha/configuration.rb', line 152</span>
|
1265
|
+
|
1266
|
+
<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>
|
1267
|
+
<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>
|
1268
|
+
<span class='kw'>end</span></pre>
|
1269
|
+
</td>
|
1270
|
+
</tr>
|
1271
|
+
</table>
|
1272
|
+
</div>
|
1273
|
+
|
1274
|
+
<div class="method_details ">
|
1275
|
+
<h3 class="signature " id="stubbing_non_public_method=-instance_method">
|
1276
|
+
|
1277
|
+
#<strong>stubbing_non_public_method=</strong>(value) ⇒ <tt><span class='object_link'>Object</span></tt>
|
1278
|
+
|
1279
|
+
|
1280
|
+
|
1281
|
+
|
1282
|
+
|
1283
|
+
</h3><div class="docstring">
|
1284
|
+
<div class="discussion">
|
1285
|
+
|
1286
|
+
<p>Configure whether stubbing of non-public methods is allowed.</p>
|
1287
|
+
|
1288
|
+
<p>Many people think that it'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>
|
1289
|
+
|
1290
|
+
<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>
|
1291
|
+
|
1292
|
+
|
1293
|
+
</div>
|
1294
|
+
</div>
|
1295
|
+
<div class="tags">
|
1296
|
+
|
1297
|
+
<div class="examples">
|
1298
|
+
<p class="tag_title">Examples:</p>
|
1299
|
+
|
1300
|
+
|
1301
|
+
<p class="example_title"><div class='inline'>
|
1302
|
+
<p>Preventing stubbing of a non-public method</p>
|
1303
|
+
</div></p>
|
1304
|
+
|
1305
|
+
<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>
|
1306
|
+
<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>
|
1307
|
+
<span class='kw'>end</span>
|
1308
|
+
|
1309
|
+
<span class='kw'>class</span> <span class='const'>Example</span>
|
1310
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_internal_method'>internal_method</span><span class='semicolon'>;</span> <span class='kw'>end</span>
|
1311
|
+
<span class='id identifier rubyid_private'>private</span> <span class='symbol'>:internal_method</span>
|
1312
|
+
<span class='kw'>end</span>
|
1313
|
+
|
1314
|
+
<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>
|
1315
|
+
<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>
|
1316
|
+
<span class='comment'># => Mocha::StubbingError: stubbing non-public method:
|
1317
|
+
</span><span class='comment'># => #<Example:0x593530>.internal_method</span></code></pre>
|
1318
|
+
|
1319
|
+
</div>
|
1320
|
+
<p class="tag_title">Parameters:</p>
|
1321
|
+
<ul class="param">
|
1322
|
+
|
1323
|
+
<li>
|
1324
|
+
|
1325
|
+
<span class='name'>value</span>
|
1326
|
+
|
1327
|
+
|
1328
|
+
<span class='type'>(<tt>Symbol</tt>)</span>
|
1329
|
+
|
1330
|
+
|
1331
|
+
|
1332
|
+
—
|
1333
|
+
<div class='inline'>
|
1334
|
+
<p>one of <code>:allow</code>, <code>:warn</code>, <code>:prevent</code>.</p>
|
1335
|
+
</div>
|
1336
|
+
|
1337
|
+
</li>
|
1338
|
+
|
1339
|
+
</ul>
|
1340
|
+
|
1341
|
+
|
1342
|
+
</div><table class="source_code">
|
1343
|
+
<tr>
|
1344
|
+
<td>
|
1345
|
+
<pre class="lines">
|
1346
|
+
|
1347
|
+
|
1348
|
+
186
|
1349
|
+
187
|
1350
|
+
188</pre>
|
1351
|
+
</td>
|
1352
|
+
<td>
|
1353
|
+
<pre class="code"><span class="info file"># File 'lib/mocha/configuration.rb', line 186</span>
|
1354
|
+
|
1355
|
+
<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>
|
1356
|
+
<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>
|
1357
|
+
<span class='kw'>end</span></pre>
|
1358
|
+
</td>
|
1359
|
+
</tr>
|
1360
|
+
</table>
|
604
1361
|
</div>
|
605
1362
|
|
606
1363
|
</div>
|
@@ -616,9 +1373,9 @@ being returned to its original value at the end of the block.</p>
|
|
616
1373
|
</div>
|
617
1374
|
|
618
1375
|
<div id="footer">
|
619
|
-
Generated on
|
1376
|
+
Generated on Sun Nov 24 15:26:50 2019 by
|
620
1377
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
621
|
-
0.9.
|
1378
|
+
0.9.20 (ruby-2.6.5).
|
622
1379
|
</div>
|
623
1380
|
|
624
1381
|
</div>
|