mocha 1.9.0 → 1.11.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +1 -0
- data/.rubocop.yml +3 -0
- data/.rubocop_todo.yml +7 -30
- data/.yardopts +1 -0
- data/README.md +30 -11
- data/RELEASE.md +93 -0
- data/Rakefile +10 -7
- data/docs/CNAME +1 -0
- data/docs/Mocha.html +132 -5
- data/docs/Mocha/API.html +437 -206
- data/docs/Mocha/ClassMethods.html +13 -16
- data/docs/Mocha/Configuration.html +1126 -227
- data/docs/Mocha/Expectation.html +420 -267
- 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 +36 -14
- data/docs/file.RELEASE.html +126 -3
- data/docs/frames.html +1 -1
- data/docs/index.html +36 -14
- data/docs/method_list.html +117 -37
- 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 +120 -56
- data/lib/mocha/block_matcher.rb +31 -0
- data/lib/mocha/cardinality.rb +26 -11
- data/lib/mocha/class_methods.rb +17 -15
- data/lib/mocha/configuration.rb +351 -67
- data/lib/mocha/deprecation.rb +2 -1
- data/lib/mocha/detection/test_unit.rb +1 -3
- data/lib/mocha/exception_raiser.rb +2 -1
- data/lib/mocha/expectation.rb +102 -63
- 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 +77 -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 +25 -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/lib/mocha/yield_parameters.rb +5 -11
- data/mocha.gemspec +1 -3
- data/test/acceptance/acceptance_test_helper.rb +7 -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 +16 -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_built_with_first_argument_type_being_string_test.rb +98 -0
- data/test/acceptance/mock_test.rb +63 -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/multiple_yielding_test.rb +59 -0
- 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 +27 -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/acceptance/yielding_test.rb +80 -0
- 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 +115 -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
- data/test/unit/yield_parameters_test.rb +35 -53
- metadata +19 -34
- 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/multiple_yields.rb +0 -15
- data/lib/mocha/no_yields.rb +0 -5
- data/lib/mocha/parameter_matchers/object.rb +0 -15
- data/lib/mocha/single_yield.rb +0 -13
- 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
- data/test/unit/multiple_yields_test.rb +0 -16
- data/test/unit/no_yields_test.rb +0 -16
- data/test/unit/single_yield_test.rb +0 -16
@@ -6,7 +6,7 @@
|
|
6
6
|
<title>
|
7
7
|
Module: Mocha::ClassMethods
|
8
8
|
|
9
|
-
— Mocha 1.
|
9
|
+
— Mocha 1.11.1
|
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>
|
@@ -155,8 +154,7 @@ non-mock) objects.</p>
|
|
155
154
|
</h3><div class="docstring">
|
156
155
|
<div class="discussion">
|
157
156
|
|
158
|
-
<p>Returns a mock object which will detect calls to any instance of this
|
159
|
-
class.</p>
|
157
|
+
<p>Returns a mock object which will detect calls to any instance of this class.</p>
|
160
158
|
|
161
159
|
|
162
160
|
</div>
|
@@ -168,8 +166,7 @@ class.</p>
|
|
168
166
|
|
169
167
|
|
170
168
|
<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>
|
169
|
+
<p>Return false to invocation of <tt>Product#save</tt> for any instance of <code>Product</code>.</p>
|
173
170
|
</div></p>
|
174
171
|
|
175
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>
|
@@ -223,15 +220,15 @@ class.</p>
|
|
223
220
|
<pre class="lines">
|
224
221
|
|
225
222
|
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
223
|
+
45
|
224
|
+
46
|
225
|
+
47
|
226
|
+
48
|
227
|
+
49
|
228
|
+
50</pre>
|
232
229
|
</td>
|
233
230
|
<td>
|
234
|
-
<pre class="code"><span class="info file"># File 'lib/mocha/class_methods.rb', line
|
231
|
+
<pre class="code"><span class="info file"># File 'lib/mocha/class_methods.rb', line 45</span>
|
235
232
|
|
236
233
|
<span class='kw'>def</span> <span class='id identifier rubyid_any_instance'>any_instance</span>
|
237
234
|
<span class='kw'>if</span> <span class='id identifier rubyid_frozen?'>frozen?</span>
|
@@ -257,9 +254,9 @@ class.</p>
|
|
257
254
|
</div>
|
258
255
|
|
259
256
|
<div id="footer">
|
260
|
-
Generated on
|
257
|
+
Generated on Tue Dec 17 12:49:35 2019 by
|
261
258
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
262
|
-
0.9.
|
259
|
+
0.9.20 (ruby-2.6.5).
|
263
260
|
</div>
|
264
261
|
|
265
262
|
</div>
|
@@ -6,7 +6,7 @@
|
|
6
6
|
<title>
|
7
7
|
Class: Mocha::Configuration
|
8
8
|
|
9
|
-
— Mocha 1.
|
9
|
+
— Mocha 1.11.1
|
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,271 @@ 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
|
-
<
|
282
|
+
<ul class="summary">
|
242
283
|
|
243
|
-
<
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
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
|
+
|
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
|
+
|
253
307
|
|
254
|
-
|
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) ⇒ Object </a>
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
</span>
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
|
255
322
|
|
256
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>
|
257
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) ⇒ Object </a>
|
336
|
+
|
258
337
|
|
338
|
+
|
339
|
+
</span>
|
340
|
+
|
341
|
+
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
|
346
|
+
|
259
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>
|
260
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) ⇒ Object </a>
|
360
|
+
|
261
361
|
|
362
|
+
|
363
|
+
</span>
|
364
|
+
|
365
|
+
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
|
370
|
+
|
262
371
|
|
263
372
|
|
264
|
-
<
|
265
|
-
|
266
|
-
|
267
|
-
|
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>
|
268
378
|
|
269
|
-
<ul class="summary">
|
270
379
|
|
271
380
|
<li class="public ">
|
272
381
|
<span class="summary_signature">
|
273
382
|
|
274
|
-
<a href="#
|
383
|
+
<a href="#stubbing_method_unnecessarily=-instance_method" title="#stubbing_method_unnecessarily= (instance method)">#<strong>stubbing_method_unnecessarily=</strong>(value) ⇒ Object </a>
|
275
384
|
|
276
385
|
|
277
386
|
|
@@ -286,7 +395,7 @@ are restored when the block is exited.</p>
|
|
286
395
|
|
287
396
|
|
288
397
|
<span class="summary_desc"><div class='inline'>
|
289
|
-
<p>
|
398
|
+
<p>Configure whether stubbing methods unnecessarily is allowed.</p>
|
290
399
|
</div></span>
|
291
400
|
|
292
401
|
</li>
|
@@ -295,7 +404,7 @@ are restored when the block is exited.</p>
|
|
295
404
|
<li class="public ">
|
296
405
|
<span class="summary_signature">
|
297
406
|
|
298
|
-
<a href="#
|
407
|
+
<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
408
|
|
300
409
|
|
301
410
|
|
@@ -310,8 +419,7 @@ are restored when the block is exited.</p>
|
|
310
419
|
|
311
420
|
|
312
421
|
<span class="summary_desc"><div class='inline'>
|
313
|
-
<p>
|
314
|
-
attempted.</p>
|
422
|
+
<p>Configure whether stubbing of non-existent methods is allowed.</p>
|
315
423
|
</div></span>
|
316
424
|
|
317
425
|
</li>
|
@@ -320,40 +428,668 @@ attempted.</p>
|
|
320
428
|
<li class="public ">
|
321
429
|
<span class="summary_signature">
|
322
430
|
|
323
|
-
<a href="#
|
431
|
+
<a href="#stubbing_non_public_method=-instance_method" title="#stubbing_non_public_method= (instance method)">#<strong>stubbing_non_public_method=</strong>(value) ⇒ Object </a>
|
432
|
+
|
433
|
+
|
324
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) { ... } ⇒ <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
|
+
—
|
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'>&</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'>"</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>
|
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'>"</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>
|
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'>&</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) { ... } ⇒ <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
|
+
—
|
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) { ... } ⇒ <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
|
+
—
|
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'>&</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'>"</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>
|
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'>"</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>
|
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'>&</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) { ... } ⇒ <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
|
+
—
|
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'>&</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'>"</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>
|
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'>"</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>
|
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'>&</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) ⇒ <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('foo')
|
911
|
+
foo.expects(:bar)
|
912
|
+
foo.stubs(:baz).returns('baz').raises(RuntimeError).throws(:tag, 'value')
|
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: #<Mock:foo>.bar
|
921
|
+
satisfied expectations:
|
922
|
+
- allowed any number of times, invoked 3 times: #<Mock:foo>.baz(any_parameters)
|
923
|
+
- #<Mock:foo>.baz(1, 2) # => "baz"
|
924
|
+
- #<Mock:foo>.baz(3, 4) # => raised RuntimeError
|
925
|
+
- #<Mock:foo>.baz(5, 6) # => threw (:tag, "value")</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
|
+
—
|
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) ⇒ <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 # => #<Mock>
|
1010
|
+
|
1011
|
+
not all expectations were satisfied
|
1012
|
+
unsatisfied expectations:
|
1013
|
+
- expected exactly once, invoked never: #<Mock>.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'># => #<Mock>
|
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'># => 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'>'</span><span class='tstring_content'>foo</span><span class='tstring_end'>'</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'># => 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>
|
325
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'>'</span><span class='tstring_content'>foo</span><span class='tstring_end'>'</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'># => does *not* raise LocalJumpError when no block is supplied</span></code></pre>
|
326
1044
|
|
327
|
-
</
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
<span class="summary_desc"><div class='inline'>
|
338
|
-
<p>Warn if the specified <code>action</code> is attempted.</p>
|
339
|
-
</div></span>
|
1045
|
+
</div>
|
1046
|
+
<p class="tag_title">Parameters:</p>
|
1047
|
+
<ul class="param">
|
340
1048
|
|
341
|
-
|
342
|
-
|
1049
|
+
<li>
|
343
1050
|
|
344
|
-
|
1051
|
+
<span class='name'>value</span>
|
1052
|
+
|
1053
|
+
|
1054
|
+
<span class='type'>(<tt>Boolean</tt>)</span>
|
1055
|
+
|
1056
|
+
|
1057
|
+
|
1058
|
+
—
|
1059
|
+
<div class='inline'>
|
1060
|
+
<p><code>true</code> to reinstate undocumented behaviour; enabled by default.</p>
|
1061
|
+
</div>
|
1062
|
+
|
1063
|
+
</li>
|
345
1064
|
|
1065
|
+
</ul>
|
346
1066
|
|
347
1067
|
|
1068
|
+
</div><table class="source_code">
|
1069
|
+
<tr>
|
1070
|
+
<td>
|
1071
|
+
<pre class="lines">
|
348
1072
|
|
349
|
-
<div id="class_method_details" class="method_details_list">
|
350
|
-
<h2>Class Method Details</h2>
|
351
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>
|
352
1088
|
|
353
|
-
<div class="method_details
|
354
|
-
<h3 class="signature
|
1089
|
+
<div class="method_details ">
|
1090
|
+
<h3 class="signature " id="stubbing_method_on_nil=-instance_method">
|
355
1091
|
|
356
|
-
|
1092
|
+
#<strong>stubbing_method_on_nil=</strong>(value) ⇒ <tt><span class='object_link'>Object</span></tt>
|
357
1093
|
|
358
1094
|
|
359
1095
|
|
@@ -362,7 +1098,13 @@ attempted.</p>
|
|
362
1098
|
</h3><div class="docstring">
|
363
1099
|
<div class="discussion">
|
364
1100
|
|
365
|
-
<p>
|
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 < 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>
|
366
1108
|
|
367
1109
|
|
368
1110
|
</div>
|
@@ -373,7 +1115,7 @@ attempted.</p>
|
|
373
1115
|
|
374
1116
|
<li>
|
375
1117
|
|
376
|
-
<span class='name'>
|
1118
|
+
<span class='name'>value</span>
|
377
1119
|
|
378
1120
|
|
379
1121
|
<span class='type'>(<tt>Symbol</tt>)</span>
|
@@ -382,36 +1124,13 @@ attempted.</p>
|
|
382
1124
|
|
383
1125
|
—
|
384
1126
|
<div class='inline'>
|
385
|
-
<p>one of <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>
|
1127
|
+
<p>one of <code>:allow</code>, <code>:warn</code>, <code>:prevent</code>.</p>
|
390
1128
|
</div>
|
391
1129
|
|
392
1130
|
</li>
|
393
1131
|
|
394
1132
|
</ul>
|
395
1133
|
|
396
|
-
<p class="tag_title">Yields:</p>
|
397
|
-
<ul class="yield">
|
398
|
-
|
399
|
-
<li>
|
400
|
-
|
401
|
-
|
402
|
-
<span class='type'></span>
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
<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>
|
410
|
-
</div>
|
411
|
-
|
412
|
-
</li>
|
413
|
-
|
414
|
-
</ul>
|
415
1134
|
|
416
1135
|
</div><table class="source_code">
|
417
1136
|
<tr>
|
@@ -419,15 +1138,15 @@ being returned to its original value at the end of the block.</p>
|
|
419
1138
|
<pre class="lines">
|
420
1139
|
|
421
1140
|
|
422
|
-
|
423
|
-
|
424
|
-
|
1141
|
+
208
|
1142
|
+
209
|
1143
|
+
210</pre>
|
425
1144
|
</td>
|
426
1145
|
<td>
|
427
|
-
<pre class="code"><span class="info file"># File 'lib/mocha/configuration.rb', line
|
1146
|
+
<pre class="code"><span class="info file"># File 'lib/mocha/configuration.rb', line 208</span>
|
428
1147
|
|
429
|
-
<span class='kw'>def</span> <span class='id identifier
|
430
|
-
<span class='
|
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>
|
431
1150
|
<span class='kw'>end</span></pre>
|
432
1151
|
</td>
|
433
1152
|
</tr>
|
@@ -435,9 +1154,9 @@ being returned to its original value at the end of the block.</p>
|
|
435
1154
|
</div>
|
436
1155
|
|
437
1156
|
<div class="method_details ">
|
438
|
-
<h3 class="signature " id="
|
1157
|
+
<h3 class="signature " id="stubbing_method_on_non_mock_object=-instance_method">
|
439
1158
|
|
440
|
-
|
1159
|
+
#<strong>stubbing_method_on_non_mock_object=</strong>(value) ⇒ <tt><span class='object_link'>Object</span></tt>
|
441
1160
|
|
442
1161
|
|
443
1162
|
|
@@ -446,19 +1165,45 @@ being returned to its original value at the end of the block.</p>
|
|
446
1165
|
</h3><div class="docstring">
|
447
1166
|
<div class="discussion">
|
448
1167
|
|
449
|
-
<p>
|
450
|
-
|
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&#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>
|
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>
|
451
1173
|
|
452
1174
|
|
453
1175
|
</div>
|
454
1176
|
</div>
|
455
1177
|
<div class="tags">
|
456
|
-
|
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'># => Mocha::StubbingError: stubbing method on non-mock object:
|
1198
|
+
</span><span class='comment'># => #<Example:0x593620>.example_method</span></code></pre>
|
1199
|
+
|
1200
|
+
</div>
|
1201
|
+
<p class="tag_title">Parameters:</p>
|
457
1202
|
<ul class="param">
|
458
1203
|
|
459
1204
|
<li>
|
460
1205
|
|
461
|
-
<span class='name'>
|
1206
|
+
<span class='name'>value</span>
|
462
1207
|
|
463
1208
|
|
464
1209
|
<span class='type'>(<tt>Symbol</tt>)</span>
|
@@ -467,52 +1212,113 @@ attempted.</p>
|
|
467
1212
|
|
468
1213
|
—
|
469
1214
|
<div class='inline'>
|
470
|
-
<p>one of <code>:
|
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>
|
1215
|
+
<p>one of <code>:allow</code>, <code>:warn</code>, <code>:prevent</code>.</p>
|
475
1216
|
</div>
|
476
1217
|
|
477
1218
|
</li>
|
478
1219
|
|
479
1220
|
</ul>
|
480
1221
|
|
481
|
-
|
482
|
-
|
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) ⇒ <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'>'</span><span class='tstring_content'>example</span><span class='tstring_end'>'</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'># => Mocha::StubbingError: stubbing method unnecessarily:
|
1282
|
+
</span><span class='comment'># => #<Mock:example>.unused_stub(any_parameters)</span></code></pre>
|
1283
|
+
|
1284
|
+
</div>
|
1285
|
+
<p class="tag_title">Parameters:</p>
|
1286
|
+
<ul class="param">
|
483
1287
|
|
484
1288
|
<li>
|
485
1289
|
|
1290
|
+
<span class='name'>value</span>
|
486
1291
|
|
487
|
-
|
1292
|
+
|
1293
|
+
<span class='type'>(<tt>Symbol</tt>)</span>
|
488
1294
|
|
489
1295
|
|
490
1296
|
|
491
|
-
|
1297
|
+
—
|
492
1298
|
<div class='inline'>
|
493
|
-
<p>
|
494
|
-
being returned to its original value at the end of the block.</p>
|
1299
|
+
<p>one of <code>:allow</code>, <code>:warn</code>, <code>:prevent</code>.</p>
|
495
1300
|
</div>
|
496
1301
|
|
497
1302
|
</li>
|
498
1303
|
|
499
1304
|
</ul>
|
500
1305
|
|
1306
|
+
|
501
1307
|
</div><table class="source_code">
|
502
1308
|
<tr>
|
503
1309
|
<td>
|
504
1310
|
<pre class="lines">
|
505
1311
|
|
506
1312
|
|
507
|
-
|
508
|
-
|
509
|
-
|
1313
|
+
87
|
1314
|
+
88
|
1315
|
+
89</pre>
|
510
1316
|
</td>
|
511
1317
|
<td>
|
512
|
-
<pre class="code"><span class="info file"># File 'lib/mocha/configuration.rb', line
|
1318
|
+
<pre class="code"><span class="info file"># File 'lib/mocha/configuration.rb', line 87</span>
|
513
1319
|
|
514
|
-
<span class='kw'>def</span> <span class='id identifier
|
515
|
-
<span class='
|
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>
|
516
1322
|
<span class='kw'>end</span></pre>
|
517
1323
|
</td>
|
518
1324
|
</tr>
|
@@ -520,9 +1326,9 @@ being returned to its original value at the end of the block.</p>
|
|
520
1326
|
</div>
|
521
1327
|
|
522
1328
|
<div class="method_details ">
|
523
|
-
<h3 class="signature " id="
|
1329
|
+
<h3 class="signature " id="stubbing_non_existent_method=-instance_method">
|
524
1330
|
|
525
|
-
|
1331
|
+
#<strong>stubbing_non_existent_method=</strong>(value) ⇒ <tt><span class='object_link'>Object</span></tt>
|
526
1332
|
|
527
1333
|
|
528
1334
|
|
@@ -531,18 +1337,45 @@ being returned to its original value at the end of the block.</p>
|
|
531
1337
|
</h3><div class="docstring">
|
532
1338
|
<div class="discussion">
|
533
1339
|
|
534
|
-
<p>
|
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'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>
|
535
1345
|
|
536
1346
|
|
537
1347
|
</div>
|
538
1348
|
</div>
|
539
1349
|
<div class="tags">
|
540
|
-
|
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'># => Mocha::StubbingError: stubbing non-existent method:
|
1370
|
+
</span><span class='comment'># => #<Example:0x593760>.method_that_doesnt_exist</span></code></pre>
|
1371
|
+
|
1372
|
+
</div>
|
1373
|
+
<p class="tag_title">Parameters:</p>
|
541
1374
|
<ul class="param">
|
542
1375
|
|
543
1376
|
<li>
|
544
1377
|
|
545
|
-
<span class='name'>
|
1378
|
+
<span class='name'>value</span>
|
546
1379
|
|
547
1380
|
|
548
1381
|
<span class='type'>(<tt>Symbol</tt>)</span>
|
@@ -551,52 +1384,118 @@ being returned to its original value at the end of the block.</p>
|
|
551
1384
|
|
552
1385
|
—
|
553
1386
|
<div class='inline'>
|
554
|
-
<p>one of <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>
|
1387
|
+
<p>one of <code>:allow</code>, <code>:warn</code>, <code>:prevent</code>.</p>
|
559
1388
|
</div>
|
560
1389
|
|
561
1390
|
</li>
|
562
1391
|
|
563
1392
|
</ul>
|
564
1393
|
|
565
|
-
|
566
|
-
|
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) ⇒ <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'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'># => Mocha::StubbingError: stubbing non-public method:
|
1459
|
+
</span><span class='comment'># => #<Example:0x593530>.internal_method</span></code></pre>
|
1460
|
+
|
1461
|
+
</div>
|
1462
|
+
<p class="tag_title">Parameters:</p>
|
1463
|
+
<ul class="param">
|
567
1464
|
|
568
1465
|
<li>
|
569
1466
|
|
1467
|
+
<span class='name'>value</span>
|
570
1468
|
|
571
|
-
|
1469
|
+
|
1470
|
+
<span class='type'>(<tt>Symbol</tt>)</span>
|
572
1471
|
|
573
1472
|
|
574
1473
|
|
575
|
-
|
1474
|
+
—
|
576
1475
|
<div class='inline'>
|
577
|
-
<p>
|
578
|
-
being returned to its original value at the end of the block.</p>
|
1476
|
+
<p>one of <code>:allow</code>, <code>:warn</code>, <code>:prevent</code>.</p>
|
579
1477
|
</div>
|
580
1478
|
|
581
1479
|
</li>
|
582
1480
|
|
583
1481
|
</ul>
|
584
1482
|
|
1483
|
+
|
585
1484
|
</div><table class="source_code">
|
586
1485
|
<tr>
|
587
1486
|
<td>
|
588
1487
|
<pre class="lines">
|
589
1488
|
|
590
1489
|
|
591
|
-
|
592
|
-
|
593
|
-
|
1490
|
+
187
|
1491
|
+
188
|
1492
|
+
189</pre>
|
594
1493
|
</td>
|
595
1494
|
<td>
|
596
|
-
<pre class="code"><span class="info file"># File 'lib/mocha/configuration.rb', line
|
1495
|
+
<pre class="code"><span class="info file"># File 'lib/mocha/configuration.rb', line 187</span>
|
597
1496
|
|
598
|
-
<span class='kw'>def</span> <span class='id identifier
|
599
|
-
<span class='
|
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>
|
600
1499
|
<span class='kw'>end</span></pre>
|
601
1500
|
</td>
|
602
1501
|
</tr>
|
@@ -616,9 +1515,9 @@ being returned to its original value at the end of the block.</p>
|
|
616
1515
|
</div>
|
617
1516
|
|
618
1517
|
<div id="footer">
|
619
|
-
Generated on
|
1518
|
+
Generated on Tue Dec 17 12:49:37 2019 by
|
620
1519
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
621
|
-
0.9.
|
1520
|
+
0.9.20 (ruby-2.6.5).
|
622
1521
|
</div>
|
623
1522
|
|
624
1523
|
</div>
|