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
data/docs/Mocha/API.html
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
<title>
|
7
7
|
Module: Mocha::API
|
8
8
|
|
9
|
-
— Mocha 1.
|
9
|
+
— Mocha 1.11.1
|
10
10
|
|
11
11
|
</title>
|
12
12
|
|
@@ -96,14 +96,40 @@
|
|
96
96
|
<h2>Overview</h2><div class="docstring">
|
97
97
|
<div class="discussion">
|
98
98
|
|
99
|
-
<p>Methods added to <code>Test::Unit::TestCase</code>,
|
100
|
-
|
99
|
+
<p>Methods added to <code>Test::Unit::TestCase</code>, <code>MiniTest::Unit::TestCase</code> or equivalent. The mock creation methods are <span class='object_link'><a href="#mock-instance_method" title="Mocha::API#mock (method)">#mock</a></span>, <span class='object_link'><a href="#stub-instance_method" title="Mocha::API#stub (method)">#stub</a></span> and <span class='object_link'><a href="#stub_everything-instance_method" title="Mocha::API#stub_everything (method)">#stub_everything</a></span>, all of which return a #<span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span> which can be further modified by <span class='object_link'><a href="Mock.html#responds_like-instance_method" title="Mocha::Mock#responds_like (method)">Mock#responds_like</a></span> and <span class='object_link'><a href="Mock.html#responds_like_instance_of-instance_method" title="Mocha::Mock#responds_like_instance_of (method)">Mock#responds_like_instance_of</a></span> methods, both of which return a <span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span>, too, and can therefore, be chained to the original creation methods.</p>
|
100
|
+
|
101
|
+
<p><span class='object_link'><a href="Mock.html#responds_like-instance_method" title="Mocha::Mock#responds_like (method)">Mock#responds_like</a></span> and <span class='object_link'><a href="Mock.html#responds_like_instance_of-instance_method" title="Mocha::Mock#responds_like_instance_of (method)">Mock#responds_like_instance_of</a></span> force the mock to indicate what it is supposed to be mocking, thus making it a safer verifying mock. They check that the underlying <code>responder</code> will actually respond to the methods being stubbed, throwing a <code>NoMethodError</code> upon invocation otherwise.</p>
|
101
102
|
|
102
103
|
|
103
104
|
</div>
|
104
105
|
</div>
|
105
106
|
<div class="tags">
|
106
107
|
|
108
|
+
<div class="examples">
|
109
|
+
<p class="tag_title">Examples:</p>
|
110
|
+
|
111
|
+
|
112
|
+
<p class="example_title"><div class='inline'>
|
113
|
+
<p>Verifying mock using <span class='object_link'><a href="Mock.html#responds_like_instance_of-instance_method" title="Mocha::Mock#responds_like_instance_of (method)">Mock#responds_like_instance_of</a></span></p>
|
114
|
+
</div></p>
|
115
|
+
|
116
|
+
<pre class="example code"><code><span class='kw'>class</span> <span class='const'>Sheep</span>
|
117
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span>
|
118
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>some awkward code we don't want to call</span><span class='tstring_end'>"</span></span>
|
119
|
+
<span class='kw'>end</span>
|
120
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_chew'>chew</span><span class='lparen'>(</span><span class='id identifier rubyid_grass'>grass</span><span class='rparen'>)</span><span class='semicolon'>;</span> <span class='kw'>end</span>
|
121
|
+
<span class='kw'>end</span>
|
122
|
+
|
123
|
+
<span class='id identifier rubyid_sheep'>sheep</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'>sheep</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_responds_like_instance_of'>responds_like_instance_of</span><span class='lparen'>(</span><span class='const'>Sheep</span><span class='rparen'>)</span>
|
124
|
+
<span class='id identifier rubyid_sheep'>sheep</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:chew</span><span class='rparen'>)</span>
|
125
|
+
<span class='id identifier rubyid_sheep'>sheep</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:foo</span><span class='rparen'>)</span>
|
126
|
+
<span class='id identifier rubyid_sheep'>sheep</span><span class='period'>.</span><span class='id identifier rubyid_respond_to?'>respond_to?</span><span class='lparen'>(</span><span class='symbol'>:chew</span><span class='rparen'>)</span> <span class='comment'># => true
|
127
|
+
</span><span class='id identifier rubyid_sheep'>sheep</span><span class='period'>.</span><span class='id identifier rubyid_respond_to?'>respond_to?</span><span class='lparen'>(</span><span class='symbol'>:foo</span><span class='rparen'>)</span> <span class='comment'># => false
|
128
|
+
</span><span class='id identifier rubyid_sheep'>sheep</span><span class='period'>.</span><span class='id identifier rubyid_chew'>chew</span>
|
129
|
+
<span class='id identifier rubyid_sheep'>sheep</span><span class='period'>.</span><span class='id identifier rubyid_foo'>foo</span> <span class='comment'># => raises NoMethodError exception</span></code></pre>
|
130
|
+
|
131
|
+
</div>
|
132
|
+
|
107
133
|
|
108
134
|
</div>
|
109
135
|
|
@@ -123,7 +149,7 @@
|
|
123
149
|
<li class="public ">
|
124
150
|
<span class="summary_signature">
|
125
151
|
|
126
|
-
<a href="#mock-instance_method" title="#mock (instance method)">#<strong>mock</strong>(*arguments)
|
152
|
+
<a href="#mock-instance_method" title="#mock (instance method)">#<strong>mock</strong>(*arguments) ⇒ Mock </a>
|
127
153
|
|
128
154
|
|
129
155
|
|
@@ -162,8 +188,7 @@
|
|
162
188
|
|
163
189
|
|
164
190
|
<span class="summary_desc"><div class='inline'>
|
165
|
-
<p>Builds a new sequence which can be used to constrain the order in which
|
166
|
-
expectations can occur.</p>
|
191
|
+
<p>Builds a new sequence which can be used to constrain the order in which expectations can occur.</p>
|
167
192
|
</div></span>
|
168
193
|
|
169
194
|
</li>
|
@@ -187,8 +212,7 @@ expectations can occur.</p>
|
|
187
212
|
|
188
213
|
|
189
214
|
<span class="summary_desc"><div class='inline'>
|
190
|
-
<p>Builds a new state machine which can be used to constrain the order in
|
191
|
-
which expectations can occur.</p>
|
215
|
+
<p>Builds a new state machine which can be used to constrain the order in which expectations can occur.</p>
|
192
216
|
</div></span>
|
193
217
|
|
194
218
|
</li>
|
@@ -197,7 +221,7 @@ which expectations can occur.</p>
|
|
197
221
|
<li class="public ">
|
198
222
|
<span class="summary_signature">
|
199
223
|
|
200
|
-
<a href="#stub-instance_method" title="#stub (instance method)">#<strong>stub</strong>(*arguments)
|
224
|
+
<a href="#stub-instance_method" title="#stub (instance method)">#<strong>stub</strong>(*arguments) ⇒ Mock </a>
|
201
225
|
|
202
226
|
|
203
227
|
|
@@ -221,7 +245,7 @@ which expectations can occur.</p>
|
|
221
245
|
<li class="public ">
|
222
246
|
<span class="summary_signature">
|
223
247
|
|
224
|
-
<a href="#stub_everything-instance_method" title="#stub_everything (instance method)">#<strong>stub_everything</strong>(*arguments)
|
248
|
+
<a href="#stub_everything-instance_method" title="#stub_everything (instance method)">#<strong>stub_everything</strong>(*arguments) ⇒ Mock </a>
|
225
249
|
|
226
250
|
|
227
251
|
|
@@ -266,7 +290,7 @@ which expectations can occur.</p>
|
|
266
290
|
|
267
291
|
|
268
292
|
<h3 class="inherited">Methods included from <span class='object_link'><a href="ParameterMatchers.html" title="Mocha::ParameterMatchers (module)">ParameterMatchers</a></span></h3>
|
269
|
-
<p class="inherited"><span class='object_link'><a href="ParameterMatchers.html#Not-instance_method" title="Mocha::ParameterMatchers#Not (method)">#Not</a></span>, <span class='object_link'><a href="ParameterMatchers.html#all_of-instance_method" title="Mocha::ParameterMatchers#all_of (method)">#all_of</a></span>, <span class='object_link'><a href="ParameterMatchers.html#any_of-instance_method" title="Mocha::ParameterMatchers#any_of (method)">#any_of</a></span>, <span class='object_link'><a href="ParameterMatchers.html#any_parameters-instance_method" title="Mocha::ParameterMatchers#any_parameters (method)">#any_parameters</a></span>, <span class='object_link'><a href="ParameterMatchers.html#anything-instance_method" title="Mocha::ParameterMatchers#anything (method)">#anything</a></span>, <span class='object_link'><a href="ParameterMatchers.html#equals-instance_method" title="Mocha::ParameterMatchers#equals (method)">#equals</a></span>, <span class='object_link'><a href="ParameterMatchers.html#equivalent_uri-instance_method" title="Mocha::ParameterMatchers#equivalent_uri (method)">#equivalent_uri</a></span>, <span class='object_link'><a href="ParameterMatchers.html#has_entries-instance_method" title="Mocha::ParameterMatchers#has_entries (method)">#has_entries</a></span>, <span class='object_link'><a href="ParameterMatchers.html#has_entry-instance_method" title="Mocha::ParameterMatchers#has_entry (method)">#has_entry</a></span>, <span class='object_link'><a href="ParameterMatchers.html#
|
293
|
+
<p class="inherited"><span class='object_link'><a href="ParameterMatchers.html#Not-instance_method" title="Mocha::ParameterMatchers#Not (method)">#Not</a></span>, <span class='object_link'><a href="ParameterMatchers.html#all_of-instance_method" title="Mocha::ParameterMatchers#all_of (method)">#all_of</a></span>, <span class='object_link'><a href="ParameterMatchers.html#any_of-instance_method" title="Mocha::ParameterMatchers#any_of (method)">#any_of</a></span>, <span class='object_link'><a href="ParameterMatchers.html#any_parameters-instance_method" title="Mocha::ParameterMatchers#any_parameters (method)">#any_parameters</a></span>, <span class='object_link'><a href="ParameterMatchers.html#anything-instance_method" title="Mocha::ParameterMatchers#anything (method)">#anything</a></span>, <span class='object_link'><a href="ParameterMatchers.html#equals-instance_method" title="Mocha::ParameterMatchers#equals (method)">#equals</a></span>, <span class='object_link'><a href="ParameterMatchers.html#equivalent_uri-instance_method" title="Mocha::ParameterMatchers#equivalent_uri (method)">#equivalent_uri</a></span>, <span class='object_link'><a href="ParameterMatchers.html#has_entries-instance_method" title="Mocha::ParameterMatchers#has_entries (method)">#has_entries</a></span>, <span class='object_link'><a href="ParameterMatchers.html#has_entry-instance_method" title="Mocha::ParameterMatchers#has_entry (method)">#has_entry</a></span>, <span class='object_link'><a href="ParameterMatchers.html#has_key-instance_method" title="Mocha::ParameterMatchers#has_key (method)">#has_key</a></span>, <span class='object_link'><a href="ParameterMatchers.html#has_value-instance_method" title="Mocha::ParameterMatchers#has_value (method)">#has_value</a></span>, <span class='object_link'><a href="ParameterMatchers.html#includes-instance_method" title="Mocha::ParameterMatchers#includes (method)">#includes</a></span>, <span class='object_link'><a href="ParameterMatchers.html#instance_of-instance_method" title="Mocha::ParameterMatchers#instance_of (method)">#instance_of</a></span>, <span class='object_link'><a href="ParameterMatchers.html#is_a-instance_method" title="Mocha::ParameterMatchers#is_a (method)">#is_a</a></span>, <span class='object_link'><a href="ParameterMatchers.html#kind_of-instance_method" title="Mocha::ParameterMatchers#kind_of (method)">#kind_of</a></span>, <span class='object_link'><a href="ParameterMatchers.html#optionally-instance_method" title="Mocha::ParameterMatchers#optionally (method)">#optionally</a></span>, <span class='object_link'><a href="ParameterMatchers.html#regexp_matches-instance_method" title="Mocha::ParameterMatchers#regexp_matches (method)">#regexp_matches</a></span>, <span class='object_link'><a href="ParameterMatchers.html#responds_with-instance_method" title="Mocha::ParameterMatchers#responds_with (method)">#responds_with</a></span>, <span class='object_link'><a href="ParameterMatchers.html#yaml_equivalent-instance_method" title="Mocha::ParameterMatchers#yaml_equivalent (method)">#yaml_equivalent</a></span></p>
|
270
294
|
|
271
295
|
|
272
296
|
<div id="instance_method_details" class="method_details_list">
|
@@ -277,11 +301,11 @@ which expectations can occur.</p>
|
|
277
301
|
<h3 class="signature first" id="mock-instance_method">
|
278
302
|
|
279
303
|
|
280
|
-
<span class="overload">#<strong>mock</strong>(name
|
304
|
+
<span class="overload">#<strong>mock</strong>(name) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
281
305
|
|
282
|
-
<span class="overload">#<strong>mock</strong>(expected_methods_vs_return_values = {}
|
306
|
+
<span class="overload">#<strong>mock</strong>(expected_methods_vs_return_values = {}) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
283
307
|
|
284
|
-
<span class="overload">#<strong>mock</strong>(name, expected_methods_vs_return_values = {}
|
308
|
+
<span class="overload">#<strong>mock</strong>(name, expected_methods_vs_return_values = {}) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
285
309
|
|
286
310
|
|
287
311
|
|
@@ -293,6 +317,8 @@ which expectations can occur.</p>
|
|
293
317
|
|
294
318
|
<p>Builds a new mock object</p>
|
295
319
|
|
320
|
+
<p>rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity</p>
|
321
|
+
|
296
322
|
|
297
323
|
</div>
|
298
324
|
</div>
|
@@ -313,24 +339,30 @@ which expectations can occur.</p>
|
|
313
339
|
<span class='comment'># an error will be raised unless both Motor#start and Motor#stop have been called
|
314
340
|
</span><span class='kw'>end</span></code></pre>
|
315
341
|
|
342
|
+
</div>
|
343
|
+
|
344
|
+
<p class="tag_title">Overloads:</p>
|
345
|
+
<ul class="overload">
|
346
|
+
|
316
347
|
|
317
|
-
|
318
|
-
<
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
<pre class="example code"><code><span class='kw'>def</span> <span class='id identifier rubyid_test_motor_starts_and_stops'>test_motor_starts_and_stops</span>
|
323
|
-
<span class='id identifier rubyid_motor'>motor</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'>motor</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='kw'>do</span>
|
324
|
-
<span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:start</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_with'>with</span><span class='lparen'>(</span><span class='int'>100</span><span class='period'>.</span><span class='id identifier rubyid_rpm'>rpm</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_returns'>returns</span><span class='lparen'>(</span><span class='kw'>true</span><span class='rparen'>)</span>
|
325
|
-
<span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='symbol'>:stop</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_returns'>returns</span><span class='lparen'>(</span><span class='kw'>true</span><span class='rparen'>)</span>
|
326
|
-
<span class='kw'>end</span>
|
327
|
-
<span class='id identifier rubyid_assert'>assert</span> <span class='id identifier rubyid_motor'>motor</span><span class='period'>.</span><span class='id identifier rubyid_start'>start</span><span class='lparen'>(</span><span class='int'>100</span><span class='period'>.</span><span class='id identifier rubyid_rpm'>rpm</span><span class='rparen'>)</span>
|
328
|
-
<span class='id identifier rubyid_assert'>assert</span> <span class='id identifier rubyid_motor'>motor</span><span class='period'>.</span><span class='id identifier rubyid_stop'>stop</span>
|
329
|
-
<span class='comment'># an error will only be raised if Motor#start(100.rpm) has not been called
|
330
|
-
</span><span class='kw'>end</span></code></pre>
|
348
|
+
<li class="overload_item">
|
349
|
+
<span class="signature">#<strong>mock</strong>(name) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
350
|
+
<div class="docstring">
|
351
|
+
<div class="discussion">
|
331
352
|
|
353
|
+
<div class="note notetag">
|
354
|
+
<strong>Note:</strong>
|
355
|
+
<div class='inline'>
|
356
|
+
<p>Prior to v1.10.0 when <code>name</code> was a <code>Symbol</code>, this method returned an unnamed <code>Mock</code> that expected the method identified by <code>name</code>. This was undocumented behaviour and it will be removed in the future, but for the moment it can be reinstated using <span class='object_link'><a href="Configuration.html#reinstate_undocumented_behaviour_from_v1_9=-instance_method" title="Mocha::Configuration#reinstate_undocumented_behaviour_from_v1_9= (method)">Configuration#reinstate_undocumented_behaviour_from_v1_9=</a></span>.</p>
|
357
|
+
</div>
|
332
358
|
</div>
|
333
|
-
|
359
|
+
|
360
|
+
|
361
|
+
|
362
|
+
</div>
|
363
|
+
</div>
|
364
|
+
<div class="tags">
|
365
|
+
<p class="tag_title">Parameters:</p>
|
334
366
|
<ul class="param">
|
335
367
|
|
336
368
|
<li>
|
@@ -338,7 +370,7 @@ which expectations can occur.</p>
|
|
338
370
|
<span class='name'>name</span>
|
339
371
|
|
340
372
|
|
341
|
-
<span class='type'>(<tt>String</tt>)</span>
|
373
|
+
<span class='type'>(<tt>String</tt>, <tt>Symbol</tt>)</span>
|
342
374
|
|
343
375
|
|
344
376
|
|
@@ -349,6 +381,25 @@ which expectations can occur.</p>
|
|
349
381
|
|
350
382
|
</li>
|
351
383
|
|
384
|
+
</ul>
|
385
|
+
|
386
|
+
|
387
|
+
</div>
|
388
|
+
</li>
|
389
|
+
|
390
|
+
|
391
|
+
<li class="overload_item">
|
392
|
+
<span class="signature">#<strong>mock</strong>(expected_methods_vs_return_values = {}) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
393
|
+
<div class="docstring">
|
394
|
+
<div class="discussion">
|
395
|
+
|
396
|
+
|
397
|
+
</div>
|
398
|
+
</div>
|
399
|
+
<div class="tags">
|
400
|
+
<p class="tag_title">Parameters:</p>
|
401
|
+
<ul class="param">
|
402
|
+
|
352
403
|
<li>
|
353
404
|
|
354
405
|
<span class='name'>expected_methods_vs_return_values</span>
|
@@ -357,68 +408,77 @@ which expectations can occur.</p>
|
|
357
408
|
<span class='type'>(<tt>Hash</tt>)</span>
|
358
409
|
|
359
410
|
|
411
|
+
<em class="default">(defaults to: <tt>{}</tt>)</em>
|
412
|
+
|
360
413
|
|
361
414
|
—
|
362
415
|
<div class='inline'>
|
363
|
-
<p>expected method name symbols as keys and corresponding return values as
|
364
|
-
values - these expectations are setup as if <span class='object_link'><a href="Mock.html#expects-instance_method" title="Mocha::Mock#expects (method)">Mock#expects</a></span> were called
|
365
|
-
multiple times.</p>
|
416
|
+
<p>expected method name symbols as keys and corresponding return values as values - these expectations are setup as if <span class='object_link'><a href="Mock.html#expects-instance_method" title="Mocha::Mock#expects (method)">Mock#expects</a></span> were called multiple times.</p>
|
366
417
|
</div>
|
367
418
|
|
368
419
|
</li>
|
369
420
|
|
370
421
|
</ul>
|
371
422
|
|
372
|
-
|
373
|
-
<ul class="yield">
|
374
|
-
|
375
|
-
<li>
|
376
|
-
|
377
|
-
|
378
|
-
<span class='type'></span>
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
<div class='inline'>
|
384
|
-
<p>optional block to be evaluated in the context of the mock object instance,
|
385
|
-
giving an alternative way to setup stubbed methods.</p>
|
423
|
+
|
386
424
|
</div>
|
425
|
+
</li>
|
426
|
+
|
387
427
|
|
388
|
-
|
428
|
+
<li class="overload_item">
|
429
|
+
<span class="signature">#<strong>mock</strong>(name, expected_methods_vs_return_values = {}) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
430
|
+
<div class="docstring">
|
431
|
+
<div class="discussion">
|
432
|
+
|
433
|
+
|
434
|
+
</div>
|
435
|
+
</div>
|
436
|
+
<div class="tags">
|
437
|
+
<p class="tag_title">Parameters:</p>
|
438
|
+
<ul class="param">
|
389
439
|
|
390
440
|
<li>
|
391
441
|
|
442
|
+
<span class='name'>name</span>
|
443
|
+
|
392
444
|
|
393
|
-
<span class='type'
|
445
|
+
<span class='type'>(<tt>String</tt>, <tt>Symbol</tt>)</span>
|
394
446
|
|
395
447
|
|
396
448
|
|
397
|
-
|
449
|
+
—
|
398
450
|
<div class='inline'>
|
399
|
-
<p>
|
400
|
-
things like instance variables declared in the test will not be available
|
401
|
-
within the block.</p>
|
451
|
+
<p>identifies mock object in error messages.</p>
|
402
452
|
</div>
|
403
453
|
|
404
454
|
</li>
|
405
455
|
|
406
456
|
<li>
|
407
457
|
|
458
|
+
<span class='name'>expected_methods_vs_return_values</span>
|
459
|
+
|
460
|
+
|
461
|
+
<span class='type'>(<tt>Hash</tt>)</span>
|
408
462
|
|
409
|
-
<span class='type'></span>
|
410
463
|
|
464
|
+
<em class="default">(defaults to: <tt>{}</tt>)</em>
|
411
465
|
|
412
466
|
|
413
|
-
|
467
|
+
—
|
414
468
|
<div class='inline'>
|
415
|
-
<p>
|
416
|
-
receiver instead.</p>
|
469
|
+
<p>expected method name symbols as keys and corresponding return values as values - these expectations are setup as if <span class='object_link'><a href="Mock.html#expects-instance_method" title="Mocha::Mock#expects (method)">Mock#expects</a></span> were called multiple times.</p>
|
417
470
|
</div>
|
418
471
|
|
419
472
|
</li>
|
420
473
|
|
421
474
|
</ul>
|
475
|
+
|
476
|
+
|
477
|
+
</div>
|
478
|
+
</li>
|
479
|
+
|
480
|
+
</ul>
|
481
|
+
|
422
482
|
<p class="tag_title">Returns:</p>
|
423
483
|
<ul class="return">
|
424
484
|
|
@@ -444,21 +504,57 @@ receiver instead.</p>
|
|
444
504
|
<pre class="lines">
|
445
505
|
|
446
506
|
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
507
|
+
69
|
508
|
+
70
|
509
|
+
71
|
510
|
+
72
|
511
|
+
73
|
512
|
+
74
|
513
|
+
75
|
514
|
+
76
|
515
|
+
77
|
516
|
+
78
|
517
|
+
79
|
518
|
+
80
|
519
|
+
81
|
520
|
+
82
|
521
|
+
83
|
522
|
+
84
|
523
|
+
85
|
524
|
+
86
|
525
|
+
87
|
526
|
+
88
|
527
|
+
89
|
528
|
+
90
|
529
|
+
91
|
530
|
+
92
|
531
|
+
93</pre>
|
454
532
|
</td>
|
455
533
|
<td>
|
456
|
-
<pre class="code"><span class="info file"># File 'lib/mocha/api.rb', line
|
457
|
-
|
458
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_arguments'>arguments</span><span class='
|
459
|
-
<span class='
|
534
|
+
<pre class="code"><span class="info file"># File 'lib/mocha/api.rb', line 69</span>
|
535
|
+
|
536
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_arguments'>arguments</span><span class='rparen'>)</span>
|
537
|
+
<span class='kw'>if</span> <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_configuration'>configuration</span><span class='period'>.</span><span class='id identifier rubyid_reinstate_undocumented_behaviour_from_v1_9?'>reinstate_undocumented_behaviour_from_v1_9?</span>
|
538
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Symbol</span><span class='rparen'>)</span>
|
539
|
+
<span class='id identifier rubyid_method_name'>method_name</span> <span class='op'>=</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='lbracket'>[</span><span class='int'>0</span><span class='rbracket'>]</span>
|
540
|
+
<span class='const'>Deprecation</span><span class='period'>.</span><span class='id identifier rubyid_warning'>warning</span><span class='lparen'>(</span>
|
541
|
+
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Explicitly include `</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_method_name'>method_name</span><span class='embexpr_end'>}</span><span class='tstring_content'>` in Hash of expected methods vs return values,</span><span class='tstring_end'>"</span></span><span class='comma'>,</span>
|
542
|
+
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'> e.g. `mock(:</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_method_name'>method_name</span><span class='embexpr_end'>}</span><span class='tstring_content'> => nil)`.</span><span class='tstring_end'>"</span></span>
|
543
|
+
<span class='rparen'>)</span>
|
544
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='lbracket'>[</span><span class='int'>1</span><span class='rbracket'>]</span>
|
545
|
+
<span class='const'>Deprecation</span><span class='period'>.</span><span class='id identifier rubyid_warning'>warning</span><span class='lparen'>(</span>
|
546
|
+
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>In this case the 2nd argument for `mock(:#</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_method_name'>method_name</span><span class='embexpr_end'>}</span><span class='tstring_content'>, ...)` is ignored,</span><span class='tstring_end'>"</span></span><span class='comma'>,</span>
|
547
|
+
<span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'> but in the future a Hash of expected methods vs return values will be respected.</span><span class='tstring_end'>'</span></span>
|
548
|
+
<span class='rparen'>)</span>
|
549
|
+
<span class='kw'>end</span>
|
550
|
+
<span class='kw'>elsif</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>String</span><span class='rparen'>)</span>
|
551
|
+
<span class='id identifier rubyid_name'>name</span> <span class='op'>=</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_shift'>shift</span>
|
552
|
+
<span class='kw'>end</span>
|
553
|
+
<span class='kw'>elsif</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>String</span><span class='rparen'>)</span> <span class='op'>||</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Symbol</span><span class='rparen'>)</span>
|
554
|
+
<span class='id identifier rubyid_name'>name</span> <span class='op'>=</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_shift'>shift</span>
|
555
|
+
<span class='kw'>end</span>
|
460
556
|
<span class='id identifier rubyid_expectations'>expectations</span> <span class='op'>=</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_shift'>shift</span> <span class='op'>||</span> <span class='lbrace'>{</span><span class='rbrace'>}</span>
|
461
|
-
<span class='id identifier rubyid_mock'>mock</span> <span class='op'>=</span> <span class='id identifier rubyid_name'>name</span> <span class='op'>?</span> <span class='const'>Mockery</span><span class='period'>.</span><span class='id identifier rubyid_instance'>instance</span><span class='period'>.</span><span class='id identifier rubyid_named_mock'>named_mock</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='
|
557
|
+
<span class='id identifier rubyid_mock'>mock</span> <span class='op'>=</span> <span class='id identifier rubyid_name'>name</span> <span class='op'>?</span> <span class='const'>Mockery</span><span class='period'>.</span><span class='id identifier rubyid_instance'>instance</span><span class='period'>.</span><span class='id identifier rubyid_named_mock'>named_mock</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='const'>Mockery</span><span class='period'>.</span><span class='id identifier rubyid_instance'>instance</span><span class='period'>.</span><span class='id identifier rubyid_unnamed_mock'>unnamed_mock</span>
|
462
558
|
<span class='id identifier rubyid_mock'>mock</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='id identifier rubyid_expectations'>expectations</span><span class='rparen'>)</span>
|
463
559
|
<span class='id identifier rubyid_mock'>mock</span>
|
464
560
|
<span class='kw'>end</span></pre>
|
@@ -479,11 +575,9 @@ receiver instead.</p>
|
|
479
575
|
</h3><div class="docstring">
|
480
576
|
<div class="discussion">
|
481
577
|
|
482
|
-
<p>Builds a new sequence which can be used to constrain the order in which
|
483
|
-
expectations can occur.</p>
|
578
|
+
<p>Builds a new sequence which can be used to constrain the order in which expectations can occur.</p>
|
484
579
|
|
485
|
-
<p>Specify that an expected invocation must occur within a named <span class='object_link'><a href="Sequence.html" title="Mocha::Sequence (class)">Sequence</a></span> by
|
486
|
-
using <span class='object_link'><a href="Expectation.html#in_sequence-instance_method" title="Mocha::Expectation#in_sequence (method)">Expectation#in_sequence</a></span>.</p>
|
580
|
+
<p>Specify that an expected invocation must occur within a named <span class='object_link'><a href="Sequence.html" title="Mocha::Sequence (class)">Sequence</a></span> by using <span class='object_link'><a href="Expectation.html#in_sequence-instance_method" title="Mocha::Expectation#in_sequence (method)">Expectation#in_sequence</a></span>.</p>
|
487
581
|
|
488
582
|
|
489
583
|
</div>
|
@@ -540,12 +634,12 @@ using <span class='object_link'><a href="Expectation.html#in_sequence-instance_m
|
|
540
634
|
<pre class="lines">
|
541
635
|
|
542
636
|
|
543
|
-
|
544
|
-
|
545
|
-
|
637
|
+
208
|
638
|
+
209
|
639
|
+
210</pre>
|
546
640
|
</td>
|
547
641
|
<td>
|
548
|
-
<pre class="code"><span class="info file"># File 'lib/mocha/api.rb', line
|
642
|
+
<pre class="code"><span class="info file"># File 'lib/mocha/api.rb', line 208</span>
|
549
643
|
|
550
644
|
<span class='kw'>def</span> <span class='id identifier rubyid_sequence'>sequence</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span>
|
551
645
|
<span class='const'><span class='object_link'><a href="Sequence.html" title="Mocha::Sequence (class)">Sequence</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span>
|
@@ -567,17 +661,13 @@ using <span class='object_link'><a href="Expectation.html#in_sequence-instance_m
|
|
567
661
|
</h3><div class="docstring">
|
568
662
|
<div class="discussion">
|
569
663
|
|
570
|
-
<p>Builds a new state machine which can be used to constrain the order in
|
571
|
-
which expectations can occur.</p>
|
664
|
+
<p>Builds a new state machine which can be used to constrain the order in which expectations can occur.</p>
|
572
665
|
|
573
|
-
<p>Specify the initial state of the state machine by using
|
574
|
-
<span class='object_link'><a href="StateMachine.html#starts_as-instance_method" title="Mocha::StateMachine#starts_as (method)">StateMachine#starts_as</a></span>.</p>
|
666
|
+
<p>Specify the initial state of the state machine by using <span class='object_link'><a href="StateMachine.html#starts_as-instance_method" title="Mocha::StateMachine#starts_as (method)">StateMachine#starts_as</a></span>.</p>
|
575
667
|
|
576
|
-
<p>Specify that an expected invocation should change the state of the state
|
577
|
-
machine by using <span class='object_link'><a href="Expectation.html#then-instance_method" title="Mocha::Expectation#then (method)">Expectation#then</a></span>.</p>
|
668
|
+
<p>Specify that an expected invocation should change the state of the state machine by using <span class='object_link'><a href="Expectation.html#then-instance_method" title="Mocha::Expectation#then (method)">Expectation#then</a></span>.</p>
|
578
669
|
|
579
|
-
<p>Specify that an expected invocation should be constrained to occur within a
|
580
|
-
particular <code>state</code> by using <span class='object_link'><a href="Expectation.html#when-instance_method" title="Mocha::Expectation#when (method)">Expectation#when</a></span>.</p>
|
670
|
+
<p>Specify that an expected invocation should be constrained to occur within a particular <code>state</code> by using <span class='object_link'><a href="Expectation.html#when-instance_method" title="Mocha::Expectation#when (method)">Expectation#when</a></span>.</p>
|
581
671
|
|
582
672
|
<p>A test can contain multiple state machines.</p>
|
583
673
|
|
@@ -643,12 +733,12 @@ particular <code>state</code> by using <span class='object_link'><a href="Expect
|
|
643
733
|
<pre class="lines">
|
644
734
|
|
645
735
|
|
646
|
-
|
647
|
-
|
648
|
-
|
736
|
+
238
|
737
|
+
239
|
738
|
+
240</pre>
|
649
739
|
</td>
|
650
740
|
<td>
|
651
|
-
<pre class="code"><span class="info file"># File 'lib/mocha/api.rb', line
|
741
|
+
<pre class="code"><span class="info file"># File 'lib/mocha/api.rb', line 238</span>
|
652
742
|
|
653
743
|
<span class='kw'>def</span> <span class='id identifier rubyid_states'>states</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span>
|
654
744
|
<span class='const'>Mockery</span><span class='period'>.</span><span class='id identifier rubyid_instance'>instance</span><span class='period'>.</span><span class='id identifier rubyid_new_state_machine'>new_state_machine</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span>
|
@@ -662,11 +752,11 @@ particular <code>state</code> by using <span class='object_link'><a href="Expect
|
|
662
752
|
<h3 class="signature " id="stub-instance_method">
|
663
753
|
|
664
754
|
|
665
|
-
<span class="overload">#<strong>stub</strong>(name
|
755
|
+
<span class="overload">#<strong>stub</strong>(name) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
666
756
|
|
667
|
-
<span class="overload">#<strong>stub</strong>(stubbed_methods_vs_return_values = {}
|
757
|
+
<span class="overload">#<strong>stub</strong>(stubbed_methods_vs_return_values = {}) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
668
758
|
|
669
|
-
<span class="overload">#<strong>stub</strong>(name, stubbed_methods_vs_return_values = {}
|
759
|
+
<span class="overload">#<strong>stub</strong>(name, stubbed_methods_vs_return_values = {}) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
670
760
|
|
671
761
|
|
672
762
|
|
@@ -678,6 +768,8 @@ particular <code>state</code> by using <span class='object_link'><a href="Expect
|
|
678
768
|
|
679
769
|
<p>Builds a new mock object</p>
|
680
770
|
|
771
|
+
<p>rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity</p>
|
772
|
+
|
681
773
|
|
682
774
|
</div>
|
683
775
|
</div>
|
@@ -698,24 +790,30 @@ particular <code>state</code> by using <span class='object_link'><a href="Expect
|
|
698
790
|
<span class='comment'># an error will not be raised even if either Motor#start or Motor#stop has not been called
|
699
791
|
</span><span class='kw'>end</span></code></pre>
|
700
792
|
|
793
|
+
</div>
|
794
|
+
|
795
|
+
<p class="tag_title">Overloads:</p>
|
796
|
+
<ul class="overload">
|
797
|
+
|
701
798
|
|
702
|
-
|
703
|
-
<
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
<pre class="example code"><code><span class='kw'>def</span> <span class='id identifier rubyid_test_motor_starts_and_stops'>test_motor_starts_and_stops</span>
|
708
|
-
<span class='id identifier rubyid_motor'>motor</span> <span class='op'>=</span> <span class='id identifier rubyid_stub'>stub</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>motor</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='kw'>do</span>
|
709
|
-
<span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:start</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_with'>with</span><span class='lparen'>(</span><span class='int'>100</span><span class='period'>.</span><span class='id identifier rubyid_rpm'>rpm</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_returns'>returns</span><span class='lparen'>(</span><span class='kw'>true</span><span class='rparen'>)</span>
|
710
|
-
<span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='symbol'>:stop</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_returns'>returns</span><span class='lparen'>(</span><span class='kw'>true</span><span class='rparen'>)</span>
|
711
|
-
<span class='kw'>end</span>
|
712
|
-
<span class='id identifier rubyid_assert'>assert</span> <span class='id identifier rubyid_motor'>motor</span><span class='period'>.</span><span class='id identifier rubyid_start'>start</span><span class='lparen'>(</span><span class='int'>100</span><span class='period'>.</span><span class='id identifier rubyid_rpm'>rpm</span><span class='rparen'>)</span>
|
713
|
-
<span class='id identifier rubyid_assert'>assert</span> <span class='id identifier rubyid_motor'>motor</span><span class='period'>.</span><span class='id identifier rubyid_stop'>stop</span>
|
714
|
-
<span class='comment'># an error will only be raised if Motor#start(100.rpm) has not been called
|
715
|
-
</span><span class='kw'>end</span></code></pre>
|
799
|
+
<li class="overload_item">
|
800
|
+
<span class="signature">#<strong>stub</strong>(name) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
801
|
+
<div class="docstring">
|
802
|
+
<div class="discussion">
|
716
803
|
|
804
|
+
<div class="note notetag">
|
805
|
+
<strong>Note:</strong>
|
806
|
+
<div class='inline'>
|
807
|
+
<p>Prior to v1.10.0 when <code>name</code> was a <code>Symbol</code>, this method returned an unnamed <code>Mock</code> that stubbed the method identified by <code>name</code>. This was undocumented behaviour and it will be removed in the future, but for the moment it can be reinstated using <span class='object_link'><a href="Configuration.html#reinstate_undocumented_behaviour_from_v1_9=-instance_method" title="Mocha::Configuration#reinstate_undocumented_behaviour_from_v1_9= (method)">Configuration#reinstate_undocumented_behaviour_from_v1_9=</a></span>.</p>
|
808
|
+
</div>
|
717
809
|
</div>
|
718
|
-
|
810
|
+
|
811
|
+
|
812
|
+
|
813
|
+
</div>
|
814
|
+
</div>
|
815
|
+
<div class="tags">
|
816
|
+
<p class="tag_title">Parameters:</p>
|
719
817
|
<ul class="param">
|
720
818
|
|
721
819
|
<li>
|
@@ -723,7 +821,7 @@ particular <code>state</code> by using <span class='object_link'><a href="Expect
|
|
723
821
|
<span class='name'>name</span>
|
724
822
|
|
725
823
|
|
726
|
-
<span class='type'>(<tt>String</tt>)</span>
|
824
|
+
<span class='type'>(<tt>String</tt>, <tt>Symbol</tt>)</span>
|
727
825
|
|
728
826
|
|
729
827
|
|
@@ -734,6 +832,25 @@ particular <code>state</code> by using <span class='object_link'><a href="Expect
|
|
734
832
|
|
735
833
|
</li>
|
736
834
|
|
835
|
+
</ul>
|
836
|
+
|
837
|
+
|
838
|
+
</div>
|
839
|
+
</li>
|
840
|
+
|
841
|
+
|
842
|
+
<li class="overload_item">
|
843
|
+
<span class="signature">#<strong>stub</strong>(stubbed_methods_vs_return_values = {}) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
844
|
+
<div class="docstring">
|
845
|
+
<div class="discussion">
|
846
|
+
|
847
|
+
|
848
|
+
</div>
|
849
|
+
</div>
|
850
|
+
<div class="tags">
|
851
|
+
<p class="tag_title">Parameters:</p>
|
852
|
+
<ul class="param">
|
853
|
+
|
737
854
|
<li>
|
738
855
|
|
739
856
|
<span class='name'>stubbed_methods_vs_return_values</span>
|
@@ -742,68 +859,59 @@ particular <code>state</code> by using <span class='object_link'><a href="Expect
|
|
742
859
|
<span class='type'>(<tt>Hash</tt>)</span>
|
743
860
|
|
744
861
|
|
862
|
+
<em class="default">(defaults to: <tt>{}</tt>)</em>
|
863
|
+
|
745
864
|
|
746
865
|
—
|
747
866
|
<div class='inline'>
|
748
|
-
<p>stubbed method name symbols as keys and corresponding return values as
|
749
|
-
values - these stubbed methods are setup as if <span class='object_link'><a href="Mock.html#stubs-instance_method" title="Mocha::Mock#stubs (method)">Mock#stubs</a></span> were called
|
750
|
-
multiple times.</p>
|
867
|
+
<p>stubbed method name symbols as keys and corresponding return values as values - these stubbed methods are setup as if <span class='object_link'><a href="Mock.html#stubs-instance_method" title="Mocha::Mock#stubs (method)">Mock#stubs</a></span> were called multiple times.</p>
|
751
868
|
</div>
|
752
869
|
|
753
870
|
</li>
|
754
871
|
|
755
872
|
</ul>
|
756
873
|
|
757
|
-
|
758
|
-
<ul class="yield">
|
759
|
-
|
760
|
-
<li>
|
761
|
-
|
762
|
-
|
763
|
-
<span class='type'></span>
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
<div class='inline'>
|
769
|
-
<p>optional block to be evaluated in the context of the mock object instance,
|
770
|
-
giving an alternative way to setup stubbed methods.</p>
|
874
|
+
|
771
875
|
</div>
|
876
|
+
</li>
|
877
|
+
|
772
878
|
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
<div class='inline'>
|
784
|
-
<p>note that the block is evaulated by calling Mock#instance_eval and so
|
785
|
-
things like instance variables declared in the test will not be available
|
786
|
-
within the block.</p>
|
879
|
+
<li class="overload_item">
|
880
|
+
<span class="signature">#<strong>stub</strong>(name, stubbed_methods_vs_return_values = {}) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
881
|
+
<div class="docstring">
|
882
|
+
<div class="discussion">
|
883
|
+
|
884
|
+
|
885
|
+
</div>
|
787
886
|
</div>
|
788
|
-
|
789
|
-
|
887
|
+
<div class="tags">
|
888
|
+
<p class="tag_title">Parameters:</p>
|
889
|
+
<ul class="param">
|
790
890
|
|
791
891
|
<li>
|
792
892
|
|
893
|
+
<span class='name'>name</span>
|
793
894
|
|
794
|
-
<span class='type'></span>
|
795
895
|
|
896
|
+
<span class='type'>(<tt>String</tt>, <tt>Symbol</tt>)</span>
|
796
897
|
|
797
898
|
|
798
|
-
|
899
|
+
|
900
|
+
—
|
799
901
|
<div class='inline'>
|
800
|
-
<p>
|
801
|
-
receiver instead.</p>
|
902
|
+
<p>identifies mock object in error messages.</p>
|
802
903
|
</div>
|
803
904
|
|
804
905
|
</li>
|
805
906
|
|
806
907
|
</ul>
|
908
|
+
|
909
|
+
|
910
|
+
</div>
|
911
|
+
</li>
|
912
|
+
|
913
|
+
</ul>
|
914
|
+
|
807
915
|
<p class="tag_title">Returns:</p>
|
808
916
|
<ul class="return">
|
809
917
|
|
@@ -829,21 +937,57 @@ receiver instead.</p>
|
|
829
937
|
<pre class="lines">
|
830
938
|
|
831
939
|
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
940
|
+
116
|
941
|
+
117
|
942
|
+
118
|
943
|
+
119
|
944
|
+
120
|
945
|
+
121
|
946
|
+
122
|
947
|
+
123
|
948
|
+
124
|
949
|
+
125
|
950
|
+
126
|
951
|
+
127
|
952
|
+
128
|
953
|
+
129
|
954
|
+
130
|
955
|
+
131
|
956
|
+
132
|
957
|
+
133
|
958
|
+
134
|
959
|
+
135
|
960
|
+
136
|
961
|
+
137
|
962
|
+
138
|
963
|
+
139
|
964
|
+
140</pre>
|
839
965
|
</td>
|
840
966
|
<td>
|
841
|
-
<pre class="code"><span class="info file"># File 'lib/mocha/api.rb', line
|
842
|
-
|
843
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_stub'>stub</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_arguments'>arguments</span><span class='
|
844
|
-
<span class='
|
967
|
+
<pre class="code"><span class="info file"># File 'lib/mocha/api.rb', line 116</span>
|
968
|
+
|
969
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_stub'>stub</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_arguments'>arguments</span><span class='rparen'>)</span>
|
970
|
+
<span class='kw'>if</span> <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_configuration'>configuration</span><span class='period'>.</span><span class='id identifier rubyid_reinstate_undocumented_behaviour_from_v1_9?'>reinstate_undocumented_behaviour_from_v1_9?</span>
|
971
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Symbol</span><span class='rparen'>)</span>
|
972
|
+
<span class='id identifier rubyid_method_name'>method_name</span> <span class='op'>=</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='lbracket'>[</span><span class='int'>0</span><span class='rbracket'>]</span>
|
973
|
+
<span class='const'>Deprecation</span><span class='period'>.</span><span class='id identifier rubyid_warning'>warning</span><span class='lparen'>(</span>
|
974
|
+
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Explicitly include `</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_method_name'>method_name</span><span class='embexpr_end'>}</span><span class='tstring_content'>` in Hash of stubbed methods vs return values,</span><span class='tstring_end'>"</span></span><span class='comma'>,</span>
|
975
|
+
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'> e.g. `stub(:</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_method_name'>method_name</span><span class='embexpr_end'>}</span><span class='tstring_content'> => nil)`.</span><span class='tstring_end'>"</span></span>
|
976
|
+
<span class='rparen'>)</span>
|
977
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='lbracket'>[</span><span class='int'>1</span><span class='rbracket'>]</span>
|
978
|
+
<span class='const'>Deprecation</span><span class='period'>.</span><span class='id identifier rubyid_warning'>warning</span><span class='lparen'>(</span>
|
979
|
+
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>In this case the 2nd argument for `stub(:#</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_method_name'>method_name</span><span class='embexpr_end'>}</span><span class='tstring_content'>, ...)` is ignored,</span><span class='tstring_end'>"</span></span><span class='comma'>,</span>
|
980
|
+
<span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'> but in the future a Hash of stubbed methods vs return values will be respected.</span><span class='tstring_end'>'</span></span>
|
981
|
+
<span class='rparen'>)</span>
|
982
|
+
<span class='kw'>end</span>
|
983
|
+
<span class='kw'>elsif</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>String</span><span class='rparen'>)</span>
|
984
|
+
<span class='id identifier rubyid_name'>name</span> <span class='op'>=</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_shift'>shift</span>
|
985
|
+
<span class='kw'>end</span>
|
986
|
+
<span class='kw'>elsif</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>String</span><span class='rparen'>)</span> <span class='op'>||</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Symbol</span><span class='rparen'>)</span>
|
987
|
+
<span class='id identifier rubyid_name'>name</span> <span class='op'>=</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_shift'>shift</span>
|
988
|
+
<span class='kw'>end</span>
|
845
989
|
<span class='id identifier rubyid_expectations'>expectations</span> <span class='op'>=</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_shift'>shift</span> <span class='op'>||</span> <span class='lbrace'>{</span><span class='rbrace'>}</span>
|
846
|
-
<span class='id identifier rubyid_stub'>stub</span> <span class='op'>=</span> <span class='id identifier rubyid_name'>name</span> <span class='op'>?</span> <span class='const'>Mockery</span><span class='period'>.</span><span class='id identifier rubyid_instance'>instance</span><span class='period'>.</span><span class='id identifier rubyid_named_mock'>named_mock</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='
|
990
|
+
<span class='id identifier rubyid_stub'>stub</span> <span class='op'>=</span> <span class='id identifier rubyid_name'>name</span> <span class='op'>?</span> <span class='const'>Mockery</span><span class='period'>.</span><span class='id identifier rubyid_instance'>instance</span><span class='period'>.</span><span class='id identifier rubyid_named_mock'>named_mock</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='const'>Mockery</span><span class='period'>.</span><span class='id identifier rubyid_instance'>instance</span><span class='period'>.</span><span class='id identifier rubyid_unnamed_mock'>unnamed_mock</span>
|
847
991
|
<span class='id identifier rubyid_stub'>stub</span><span class='period'>.</span><span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='id identifier rubyid_expectations'>expectations</span><span class='rparen'>)</span>
|
848
992
|
<span class='id identifier rubyid_stub'>stub</span>
|
849
993
|
<span class='kw'>end</span></pre>
|
@@ -856,11 +1000,11 @@ receiver instead.</p>
|
|
856
1000
|
<h3 class="signature " id="stub_everything-instance_method">
|
857
1001
|
|
858
1002
|
|
859
|
-
<span class="overload">#<strong>stub_everything</strong>(name
|
1003
|
+
<span class="overload">#<strong>stub_everything</strong>(name) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
860
1004
|
|
861
|
-
<span class="overload">#<strong>stub_everything</strong>(stubbed_methods_vs_return_values = {}
|
1005
|
+
<span class="overload">#<strong>stub_everything</strong>(stubbed_methods_vs_return_values = {}) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
862
1006
|
|
863
|
-
<span class="overload">#<strong>stub_everything</strong>(name, stubbed_methods_vs_return_values = {}
|
1007
|
+
<span class="overload">#<strong>stub_everything</strong>(name, stubbed_methods_vs_return_values = {}) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
864
1008
|
|
865
1009
|
|
866
1010
|
|
@@ -870,8 +1014,9 @@ receiver instead.</p>
|
|
870
1014
|
</h3><div class="docstring">
|
871
1015
|
<div class="discussion">
|
872
1016
|
|
873
|
-
<p>Builds a mock object that accepts calls to any method. By default it will
|
874
|
-
|
1017
|
+
<p>Builds a mock object that accepts calls to any method. By default it will return <code>nil</code> for any method call.</p>
|
1018
|
+
|
1019
|
+
<p>rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity</p>
|
875
1020
|
|
876
1021
|
|
877
1022
|
</div>
|
@@ -894,7 +1039,29 @@ return <code>nil</code> for any method call.</p>
|
|
894
1039
|
<span class='kw'>end</span></code></pre>
|
895
1040
|
|
896
1041
|
</div>
|
897
|
-
|
1042
|
+
|
1043
|
+
<p class="tag_title">Overloads:</p>
|
1044
|
+
<ul class="overload">
|
1045
|
+
|
1046
|
+
|
1047
|
+
<li class="overload_item">
|
1048
|
+
<span class="signature">#<strong>stub_everything</strong>(name) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
1049
|
+
<div class="docstring">
|
1050
|
+
<div class="discussion">
|
1051
|
+
|
1052
|
+
<div class="note notetag">
|
1053
|
+
<strong>Note:</strong>
|
1054
|
+
<div class='inline'>
|
1055
|
+
<p>Prior to v1.10.0 when <code>name</code> was a <code>Symbol</code>, this method returned an unnamed <code>Mock</code> that stubbed the method identified by <code>name</code>. This was undocumented behaviour and it will be removed in the future, but for the moment it can be reinstated using <span class='object_link'><a href="Configuration.html#reinstate_undocumented_behaviour_from_v1_9=-instance_method" title="Mocha::Configuration#reinstate_undocumented_behaviour_from_v1_9= (method)">Configuration#reinstate_undocumented_behaviour_from_v1_9=</a></span>.</p>
|
1056
|
+
</div>
|
1057
|
+
</div>
|
1058
|
+
|
1059
|
+
|
1060
|
+
|
1061
|
+
</div>
|
1062
|
+
</div>
|
1063
|
+
<div class="tags">
|
1064
|
+
<p class="tag_title">Parameters:</p>
|
898
1065
|
<ul class="param">
|
899
1066
|
|
900
1067
|
<li>
|
@@ -902,7 +1069,7 @@ return <code>nil</code> for any method call.</p>
|
|
902
1069
|
<span class='name'>name</span>
|
903
1070
|
|
904
1071
|
|
905
|
-
<span class='type'>(<tt>String</tt>)</span>
|
1072
|
+
<span class='type'>(<tt>String</tt>, <tt>Symbol</tt>)</span>
|
906
1073
|
|
907
1074
|
|
908
1075
|
|
@@ -913,6 +1080,25 @@ return <code>nil</code> for any method call.</p>
|
|
913
1080
|
|
914
1081
|
</li>
|
915
1082
|
|
1083
|
+
</ul>
|
1084
|
+
|
1085
|
+
|
1086
|
+
</div>
|
1087
|
+
</li>
|
1088
|
+
|
1089
|
+
|
1090
|
+
<li class="overload_item">
|
1091
|
+
<span class="signature">#<strong>stub_everything</strong>(stubbed_methods_vs_return_values = {}) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
1092
|
+
<div class="docstring">
|
1093
|
+
<div class="discussion">
|
1094
|
+
|
1095
|
+
|
1096
|
+
</div>
|
1097
|
+
</div>
|
1098
|
+
<div class="tags">
|
1099
|
+
<p class="tag_title">Parameters:</p>
|
1100
|
+
<ul class="param">
|
1101
|
+
|
916
1102
|
<li>
|
917
1103
|
|
918
1104
|
<span class='name'>stubbed_methods_vs_return_values</span>
|
@@ -921,68 +1107,77 @@ return <code>nil</code> for any method call.</p>
|
|
921
1107
|
<span class='type'>(<tt>Hash</tt>)</span>
|
922
1108
|
|
923
1109
|
|
1110
|
+
<em class="default">(defaults to: <tt>{}</tt>)</em>
|
1111
|
+
|
924
1112
|
|
925
1113
|
—
|
926
1114
|
<div class='inline'>
|
927
|
-
<p>stubbed method name symbols as keys and corresponding return values as
|
928
|
-
values - these stubbed methods are setup as if <span class='object_link'><a href="Mock.html#stubs-instance_method" title="Mocha::Mock#stubs (method)">Mock#stubs</a></span> were called
|
929
|
-
multiple times.</p>
|
1115
|
+
<p>stubbed method name symbols as keys and corresponding return values as values - these stubbed methods are setup as if <span class='object_link'><a href="Mock.html#stubs-instance_method" title="Mocha::Mock#stubs (method)">Mock#stubs</a></span> were called multiple times.</p>
|
930
1116
|
</div>
|
931
1117
|
|
932
1118
|
</li>
|
933
1119
|
|
934
1120
|
</ul>
|
935
1121
|
|
936
|
-
|
937
|
-
<ul class="yield">
|
938
|
-
|
939
|
-
<li>
|
940
|
-
|
941
|
-
|
942
|
-
<span class='type'></span>
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
<div class='inline'>
|
948
|
-
<p>optional block to be evaluated in the context of the mock object instance,
|
949
|
-
giving an alternative way to setup stubbed methods.</p>
|
1122
|
+
|
950
1123
|
</div>
|
1124
|
+
</li>
|
1125
|
+
|
951
1126
|
|
952
|
-
|
1127
|
+
<li class="overload_item">
|
1128
|
+
<span class="signature">#<strong>stub_everything</strong>(name, stubbed_methods_vs_return_values = {}) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
1129
|
+
<div class="docstring">
|
1130
|
+
<div class="discussion">
|
1131
|
+
|
1132
|
+
|
1133
|
+
</div>
|
1134
|
+
</div>
|
1135
|
+
<div class="tags">
|
1136
|
+
<p class="tag_title">Parameters:</p>
|
1137
|
+
<ul class="param">
|
953
1138
|
|
954
1139
|
<li>
|
955
1140
|
|
1141
|
+
<span class='name'>name</span>
|
1142
|
+
|
956
1143
|
|
957
|
-
<span class='type'
|
1144
|
+
<span class='type'>(<tt>String</tt>, <tt>Symbol</tt>)</span>
|
958
1145
|
|
959
1146
|
|
960
1147
|
|
961
|
-
|
1148
|
+
—
|
962
1149
|
<div class='inline'>
|
963
|
-
<p>
|
964
|
-
things like instance variables declared in the test will not be available
|
965
|
-
within the block.</p>
|
1150
|
+
<p>identifies mock object in error messages.</p>
|
966
1151
|
</div>
|
967
1152
|
|
968
1153
|
</li>
|
969
1154
|
|
970
1155
|
<li>
|
971
1156
|
|
1157
|
+
<span class='name'>stubbed_methods_vs_return_values</span>
|
1158
|
+
|
1159
|
+
|
1160
|
+
<span class='type'>(<tt>Hash</tt>)</span>
|
972
1161
|
|
973
|
-
<span class='type'></span>
|
974
1162
|
|
1163
|
+
<em class="default">(defaults to: <tt>{}</tt>)</em>
|
975
1164
|
|
976
1165
|
|
977
|
-
|
1166
|
+
—
|
978
1167
|
<div class='inline'>
|
979
|
-
<p>
|
980
|
-
receiver instead.</p>
|
1168
|
+
<p>stubbed method name symbols as keys and corresponding return values as values - these stubbed methods are setup as if <span class='object_link'><a href="Mock.html#stubs-instance_method" title="Mocha::Mock#stubs (method)">Mock#stubs</a></span> were called multiple times.</p>
|
981
1169
|
</div>
|
982
1170
|
|
983
1171
|
</li>
|
984
1172
|
|
985
1173
|
</ul>
|
1174
|
+
|
1175
|
+
|
1176
|
+
</div>
|
1177
|
+
</li>
|
1178
|
+
|
1179
|
+
</ul>
|
1180
|
+
|
986
1181
|
<p class="tag_title">Returns:</p>
|
987
1182
|
<ul class="return">
|
988
1183
|
|
@@ -1008,22 +1203,58 @@ receiver instead.</p>
|
|
1008
1203
|
<pre class="lines">
|
1009
1204
|
|
1010
1205
|
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1206
|
+
164
|
1207
|
+
165
|
1208
|
+
166
|
1209
|
+
167
|
1210
|
+
168
|
1211
|
+
169
|
1212
|
+
170
|
1213
|
+
171
|
1214
|
+
172
|
1215
|
+
173
|
1216
|
+
174
|
1217
|
+
175
|
1218
|
+
176
|
1219
|
+
177
|
1220
|
+
178
|
1221
|
+
179
|
1222
|
+
180
|
1223
|
+
181
|
1224
|
+
182
|
1225
|
+
183
|
1226
|
+
184
|
1227
|
+
185
|
1228
|
+
186
|
1229
|
+
187
|
1230
|
+
188
|
1231
|
+
189</pre>
|
1019
1232
|
</td>
|
1020
1233
|
<td>
|
1021
|
-
<pre class="code"><span class="info file"># File 'lib/mocha/api.rb', line
|
1022
|
-
|
1023
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_stub_everything'>stub_everything</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_arguments'>arguments</span><span class='
|
1024
|
-
<span class='
|
1234
|
+
<pre class="code"><span class="info file"># File 'lib/mocha/api.rb', line 164</span>
|
1235
|
+
|
1236
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_stub_everything'>stub_everything</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_arguments'>arguments</span><span class='rparen'>)</span>
|
1237
|
+
<span class='kw'>if</span> <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_configuration'>configuration</span><span class='period'>.</span><span class='id identifier rubyid_reinstate_undocumented_behaviour_from_v1_9?'>reinstate_undocumented_behaviour_from_v1_9?</span>
|
1238
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Symbol</span><span class='rparen'>)</span>
|
1239
|
+
<span class='id identifier rubyid_method_name'>method_name</span> <span class='op'>=</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='lbracket'>[</span><span class='int'>0</span><span class='rbracket'>]</span>
|
1240
|
+
<span class='const'>Deprecation</span><span class='period'>.</span><span class='id identifier rubyid_warning'>warning</span><span class='lparen'>(</span>
|
1241
|
+
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Explicitly include `</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_method_name'>method_name</span><span class='embexpr_end'>}</span><span class='tstring_content'>` in Hash of stubbed methods vs return values,</span><span class='tstring_end'>"</span></span><span class='comma'>,</span>
|
1242
|
+
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'> e.g. `stub_everything(:</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_method_name'>method_name</span><span class='embexpr_end'>}</span><span class='tstring_content'> => nil)`.</span><span class='tstring_end'>"</span></span>
|
1243
|
+
<span class='rparen'>)</span>
|
1244
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='lbracket'>[</span><span class='int'>1</span><span class='rbracket'>]</span>
|
1245
|
+
<span class='const'>Deprecation</span><span class='period'>.</span><span class='id identifier rubyid_warning'>warning</span><span class='lparen'>(</span>
|
1246
|
+
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>In this case the 2nd argument for `stub_everything(:#</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_method_name'>method_name</span><span class='embexpr_end'>}</span><span class='tstring_content'>, ...)` is ignored,</span><span class='tstring_end'>"</span></span><span class='comma'>,</span>
|
1247
|
+
<span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'> but in the future a Hash of stubbed methods vs return values will be respected.</span><span class='tstring_end'>'</span></span>
|
1248
|
+
<span class='rparen'>)</span>
|
1249
|
+
<span class='kw'>end</span>
|
1250
|
+
<span class='kw'>elsif</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>String</span><span class='rparen'>)</span>
|
1251
|
+
<span class='id identifier rubyid_name'>name</span> <span class='op'>=</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_shift'>shift</span>
|
1252
|
+
<span class='kw'>end</span>
|
1253
|
+
<span class='kw'>elsif</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>String</span><span class='rparen'>)</span> <span class='op'>||</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Symbol</span><span class='rparen'>)</span>
|
1254
|
+
<span class='id identifier rubyid_name'>name</span> <span class='op'>=</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_shift'>shift</span>
|
1255
|
+
<span class='kw'>end</span>
|
1025
1256
|
<span class='id identifier rubyid_expectations'>expectations</span> <span class='op'>=</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_shift'>shift</span> <span class='op'>||</span> <span class='lbrace'>{</span><span class='rbrace'>}</span>
|
1026
|
-
<span class='id identifier rubyid_stub'>stub</span> <span class='op'>=</span> <span class='id identifier rubyid_name'>name</span> <span class='op'>?</span> <span class='const'>Mockery</span><span class='period'>.</span><span class='id identifier rubyid_instance'>instance</span><span class='period'>.</span><span class='id identifier rubyid_named_mock'>named_mock</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='
|
1257
|
+
<span class='id identifier rubyid_stub'>stub</span> <span class='op'>=</span> <span class='id identifier rubyid_name'>name</span> <span class='op'>?</span> <span class='const'>Mockery</span><span class='period'>.</span><span class='id identifier rubyid_instance'>instance</span><span class='period'>.</span><span class='id identifier rubyid_named_mock'>named_mock</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='const'>Mockery</span><span class='period'>.</span><span class='id identifier rubyid_instance'>instance</span><span class='period'>.</span><span class='id identifier rubyid_unnamed_mock'>unnamed_mock</span>
|
1027
1258
|
<span class='id identifier rubyid_stub'>stub</span><span class='period'>.</span><span class='id identifier rubyid_stub_everything'>stub_everything</span>
|
1028
1259
|
<span class='id identifier rubyid_stub'>stub</span><span class='period'>.</span><span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='id identifier rubyid_expectations'>expectations</span><span class='rparen'>)</span>
|
1029
1260
|
<span class='id identifier rubyid_stub'>stub</span>
|
@@ -1046,9 +1277,9 @@ receiver instead.</p>
|
|
1046
1277
|
</div>
|
1047
1278
|
|
1048
1279
|
<div id="footer">
|
1049
|
-
Generated on
|
1280
|
+
Generated on Tue Dec 17 12:49:35 2019 by
|
1050
1281
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
1051
|
-
0.9.
|
1282
|
+
0.9.20 (ruby-2.6.5).
|
1052
1283
|
</div>
|
1053
1284
|
|
1054
1285
|
</div>
|