mocha 1.10.2 → 1.13.0
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/.yardopts +1 -0
- data/CONTRIBUTING.md +1 -1
- data/README.md +28 -30
- data/RELEASE.md +87 -0
- data/Rakefile +7 -5
- data/lib/mocha/api.rb +2 -3
- data/lib/mocha/block_matcher.rb +31 -0
- data/lib/mocha/cardinality.rb +30 -27
- data/lib/mocha/configuration.rb +2 -2
- data/lib/mocha/expectation.rb +71 -30
- data/lib/mocha/inspect.rb +6 -4
- data/lib/mocha/invocation.rb +9 -5
- data/lib/mocha/mock.rb +41 -15
- data/lib/mocha/mockery.rb +17 -27
- data/lib/mocha/parameter_matchers.rb +1 -0
- data/lib/mocha/parameter_matchers/has_entries.rb +2 -3
- data/lib/mocha/parameter_matchers/has_entry.rb +24 -16
- data/lib/mocha/parameter_matchers/has_key.rb +2 -3
- data/lib/mocha/parameter_matchers/has_keys.rb +53 -0
- data/lib/mocha/parameter_matchers/has_value.rb +2 -3
- data/lib/mocha/parameter_matchers/is_a.rb +2 -3
- data/lib/mocha/parameter_matchers/not.rb +2 -3
- data/lib/mocha/state_machine.rb +31 -40
- data/lib/mocha/stubbed_method.rb +4 -6
- data/lib/mocha/version.rb +1 -1
- data/lib/mocha/yield_parameters.rb +5 -11
- data/mocha.gemspec +13 -7
- metadata +8 -210
- data/bin/build-matrix +0 -82
- data/docs/CNAME +0 -1
- data/docs/Mocha.html +0 -254
- data/docs/Mocha/API.html +0 -1287
- data/docs/Mocha/ClassMethods.html +0 -264
- data/docs/Mocha/Configuration.html +0 -1525
- data/docs/Mocha/Expectation.html +0 -2654
- data/docs/Mocha/ExpectationError.html +0 -152
- data/docs/Mocha/ExpectationErrorFactory.html +0 -260
- data/docs/Mocha/Hooks.html +0 -370
- data/docs/Mocha/Integration.html +0 -125
- data/docs/Mocha/Integration/MiniTest.html +0 -123
- data/docs/Mocha/Integration/MiniTest/Adapter.html +0 -164
- data/docs/Mocha/Integration/TestUnit.html +0 -123
- data/docs/Mocha/Integration/TestUnit/Adapter.html +0 -164
- data/docs/Mocha/Mock.html +0 -1237
- data/docs/Mocha/ObjectMethods.html +0 -765
- data/docs/Mocha/ParameterMatchers.html +0 -2961
- data/docs/Mocha/ParameterMatchers/AllOf.html +0 -153
- data/docs/Mocha/ParameterMatchers/AnyOf.html +0 -153
- data/docs/Mocha/ParameterMatchers/AnyParameters.html +0 -153
- data/docs/Mocha/ParameterMatchers/Anything.html +0 -153
- data/docs/Mocha/ParameterMatchers/Base.html +0 -441
- data/docs/Mocha/ParameterMatchers/Equals.html +0 -153
- data/docs/Mocha/ParameterMatchers/EquivalentUri.html +0 -153
- data/docs/Mocha/ParameterMatchers/HasEntries.html +0 -153
- data/docs/Mocha/ParameterMatchers/HasEntry.html +0 -153
- data/docs/Mocha/ParameterMatchers/HasKey.html +0 -153
- data/docs/Mocha/ParameterMatchers/HasValue.html +0 -153
- data/docs/Mocha/ParameterMatchers/Includes.html +0 -153
- data/docs/Mocha/ParameterMatchers/InstanceOf.html +0 -153
- data/docs/Mocha/ParameterMatchers/IsA.html +0 -153
- data/docs/Mocha/ParameterMatchers/KindOf.html +0 -153
- data/docs/Mocha/ParameterMatchers/Not.html +0 -153
- data/docs/Mocha/ParameterMatchers/Optionally.html +0 -153
- data/docs/Mocha/ParameterMatchers/RegexpMatches.html +0 -153
- data/docs/Mocha/ParameterMatchers/RespondsWith.html +0 -153
- data/docs/Mocha/ParameterMatchers/YamlEquivalent.html +0 -153
- data/docs/Mocha/Sequence.html +0 -149
- data/docs/Mocha/StateMachine.html +0 -527
- data/docs/Mocha/StateMachine/State.html +0 -140
- data/docs/Mocha/StateMachine/StatePredicate.html +0 -140
- data/docs/Mocha/StubbingError.html +0 -150
- data/docs/_index.html +0 -519
- data/docs/class_list.html +0 -51
- data/docs/css/common.css +0 -1
- data/docs/css/full_list.css +0 -58
- data/docs/css/style.css +0 -496
- data/docs/file.COPYING.html +0 -81
- data/docs/file.MIT-LICENSE.html +0 -85
- data/docs/file.README.html +0 -448
- data/docs/file.RELEASE.html +0 -974
- data/docs/file_list.html +0 -71
- data/docs/frames.html +0 -17
- data/docs/index.html +0 -448
- data/docs/js/app.js +0 -303
- data/docs/js/full_list.js +0 -216
- data/docs/js/jquery.js +0 -4
- data/docs/method_list.html +0 -635
- data/docs/top-level-namespace.html +0 -118
- data/gemfiles/Gemfile.minitest.1.3.0 +0 -7
- data/gemfiles/Gemfile.minitest.1.4.0 +0 -7
- data/gemfiles/Gemfile.minitest.1.4.1 +0 -7
- data/gemfiles/Gemfile.minitest.1.4.2 +0 -7
- data/gemfiles/Gemfile.minitest.2.0.0 +0 -7
- data/gemfiles/Gemfile.minitest.2.0.1 +0 -7
- data/gemfiles/Gemfile.minitest.2.11.0 +0 -7
- data/gemfiles/Gemfile.minitest.2.11.2 +0 -7
- data/gemfiles/Gemfile.minitest.2.3.0 +0 -7
- data/gemfiles/Gemfile.minitest.5.11.3 +0 -7
- data/gemfiles/Gemfile.test-unit.2.0.0 +0 -7
- data/gemfiles/Gemfile.test-unit.2.0.1 +0 -7
- data/gemfiles/Gemfile.test-unit.2.0.3 +0 -7
- data/lib/mocha/multiple_yields.rb +0 -15
- data/lib/mocha/no_yields.rb +0 -5
- data/lib/mocha/pretty_parameters.rb +0 -24
- data/lib/mocha/single_yield.rb +0 -13
- data/test/acceptance/acceptance_test_helper.rb +0 -41
- data/test/acceptance/bug_18914_test.rb +0 -37
- data/test/acceptance/bug_21465_test.rb +0 -31
- data/test/acceptance/bug_21563_test.rb +0 -22
- data/test/acceptance/display_matching_invocations_alongside_expectations_test.rb +0 -69
- data/test/acceptance/exception_rescue_test.rb +0 -53
- data/test/acceptance/expectations_on_multiple_methods_test.rb +0 -55
- data/test/acceptance/expected_invocation_count_test.rb +0 -229
- data/test/acceptance/failure_messages_test.rb +0 -61
- data/test/acceptance/issue_272_test.rb +0 -50
- data/test/acceptance/issue_65_test.rb +0 -64
- data/test/acceptance/issue_70_test.rb +0 -53
- data/test/acceptance/mocha_example_test.rb +0 -96
- data/test/acceptance/mocha_test_result_test.rb +0 -83
- data/test/acceptance/mock_built_with_first_argument_type_being_string_test.rb +0 -99
- data/test/acceptance/mock_test.rb +0 -139
- data/test/acceptance/mocked_methods_dispatch_test.rb +0 -75
- data/test/acceptance/multiple_expectations_failure_message_test.rb +0 -66
- data/test/acceptance/optional_parameters_test.rb +0 -67
- data/test/acceptance/parameter_matcher_test.rb +0 -299
- data/test/acceptance/partial_mocks_test.rb +0 -44
- data/test/acceptance/prepend_test.rb +0 -86
- data/test/acceptance/prevent_use_of_mocha_outside_test_test.rb +0 -76
- data/test/acceptance/raise_exception_test.rb +0 -36
- data/test/acceptance/return_value_test.rb +0 -49
- data/test/acceptance/sequence_test.rb +0 -189
- data/test/acceptance/states_test.rb +0 -71
- data/test/acceptance/stub_any_instance_method_defined_on_superclass_test.rb +0 -64
- data/test/acceptance/stub_any_instance_method_test.rb +0 -301
- data/test/acceptance/stub_class_method_defined_on_active_record_association_proxy_test.rb +0 -105
- data/test/acceptance/stub_class_method_defined_on_class_test.rb +0 -78
- data/test/acceptance/stub_class_method_defined_on_module_test.rb +0 -73
- data/test/acceptance/stub_class_method_defined_on_superclass_test.rb +0 -144
- data/test/acceptance/stub_everything_test.rb +0 -53
- data/test/acceptance/stub_instance_method_defined_on_active_record_association_proxy_test.rb +0 -91
- data/test/acceptance/stub_instance_method_defined_on_class_and_aliased_test.rb +0 -67
- data/test/acceptance/stub_instance_method_defined_on_class_test.rb +0 -67
- data/test/acceptance/stub_instance_method_defined_on_kernel_module_test.rb +0 -136
- data/test/acceptance/stub_instance_method_defined_on_module_test.rb +0 -76
- data/test/acceptance/stub_instance_method_defined_on_object_class_test.rb +0 -75
- data/test/acceptance/stub_instance_method_defined_on_singleton_class_test.rb +0 -67
- data/test/acceptance/stub_instance_method_defined_on_superclass_test.rb +0 -70
- data/test/acceptance/stub_method_defined_on_module_and_aliased_test.rb +0 -38
- data/test/acceptance/stub_module_method_test.rb +0 -200
- data/test/acceptance/stub_test.rb +0 -49
- data/test/acceptance/stubba_example_test.rb +0 -93
- data/test/acceptance/stubba_test_result_test.rb +0 -71
- data/test/acceptance/stubbing_error_backtrace_test.rb +0 -63
- data/test/acceptance/stubbing_frozen_object_test.rb +0 -88
- data/test/acceptance/stubbing_method_accepting_block_parameter_test.rb +0 -52
- data/test/acceptance/stubbing_method_unnecessarily_test.rb +0 -63
- data/test/acceptance/stubbing_nil_test.rb +0 -60
- data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +0 -157
- data/test/acceptance/stubbing_non_existent_class_method_test.rb +0 -157
- data/test/acceptance/stubbing_non_existent_instance_method_test.rb +0 -145
- data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +0 -128
- data/test/acceptance/stubbing_non_public_class_method_test.rb +0 -163
- data/test/acceptance/stubbing_non_public_instance_method_test.rb +0 -141
- data/test/acceptance/stubbing_on_non_mock_object_test.rb +0 -70
- data/test/acceptance/stubbing_same_class_method_on_parent_and_child_classes_test.rb +0 -33
- data/test/acceptance/throw_test.rb +0 -42
- data/test/acceptance/unexpected_invocation_test.rb +0 -23
- data/test/acceptance/unstubbing_test.rb +0 -194
- data/test/assertions.rb +0 -8
- data/test/deprecation_disabler.rb +0 -15
- data/test/execution_point.rb +0 -36
- data/test/integration/mini_test_test.rb +0 -8
- data/test/integration/shared_tests.rb +0 -178
- data/test/integration/test_unit_test.rb +0 -8
- data/test/method_definer.rb +0 -16
- data/test/mini_test_result.rb +0 -96
- data/test/minitest_result.rb +0 -48
- data/test/simple_counter.rb +0 -11
- data/test/test_helper.rb +0 -58
- data/test/test_runner.rb +0 -58
- data/test/test_unit_result.rb +0 -22
- data/test/unit/any_instance_method_test.rb +0 -175
- data/test/unit/array_inspect_test.rb +0 -14
- data/test/unit/backtrace_filter_test.rb +0 -17
- data/test/unit/cardinality_test.rb +0 -72
- data/test/unit/central_test.rb +0 -98
- data/test/unit/change_state_side_effect_test.rb +0 -37
- data/test/unit/class_methods_test.rb +0 -69
- data/test/unit/configuration_test.rb +0 -37
- data/test/unit/date_time_inspect_test.rb +0 -19
- data/test/unit/exception_raiser_test.rb +0 -45
- data/test/unit/expectation_list_test.rb +0 -82
- data/test/unit/expectation_test.rb +0 -492
- data/test/unit/hash_inspect_test.rb +0 -14
- data/test/unit/hooks_test.rb +0 -35
- data/test/unit/in_state_ordering_constraint_test.rb +0 -39
- data/test/unit/instance_method_test.rb +0 -282
- data/test/unit/method_matcher_test.rb +0 -26
- data/test/unit/mock_test.rb +0 -372
- data/test/unit/mockery_test.rb +0 -171
- data/test/unit/module_methods_test.rb +0 -16
- data/test/unit/multiple_yields_test.rb +0 -16
- data/test/unit/no_yields_test.rb +0 -16
- data/test/unit/object_inspect_test.rb +0 -60
- data/test/unit/object_methods_test.rb +0 -63
- data/test/unit/parameter_matchers/all_of_test.rb +0 -24
- data/test/unit/parameter_matchers/any_of_test.rb +0 -24
- data/test/unit/parameter_matchers/anything_test.rb +0 -19
- data/test/unit/parameter_matchers/equals_test.rb +0 -23
- data/test/unit/parameter_matchers/equivalent_uri_test.rb +0 -41
- data/test/unit/parameter_matchers/has_entries_test.rb +0 -51
- data/test/unit/parameter_matchers/has_entry_test.rb +0 -128
- data/test/unit/parameter_matchers/has_key_test.rb +0 -54
- data/test/unit/parameter_matchers/has_value_test.rb +0 -55
- data/test/unit/parameter_matchers/includes_test.rb +0 -106
- data/test/unit/parameter_matchers/instance_of_test.rb +0 -23
- data/test/unit/parameter_matchers/is_a_test.rb +0 -23
- data/test/unit/parameter_matchers/kind_of_test.rb +0 -23
- data/test/unit/parameter_matchers/not_test.rb +0 -24
- data/test/unit/parameter_matchers/regexp_matches_test.rb +0 -45
- data/test/unit/parameter_matchers/responds_with_test.rb +0 -38
- data/test/unit/parameter_matchers/stub_matcher.rb +0 -23
- data/test/unit/parameter_matchers/yaml_equivalent_test.rb +0 -23
- data/test/unit/parameters_matcher_test.rb +0 -119
- data/test/unit/receivers_test.rb +0 -96
- data/test/unit/return_values_test.rb +0 -66
- data/test/unit/sequence_test.rb +0 -100
- data/test/unit/single_return_value_test.rb +0 -17
- data/test/unit/single_yield_test.rb +0 -16
- data/test/unit/state_machine_test.rb +0 -96
- data/test/unit/string_inspect_test.rb +0 -9
- data/test/unit/thrower_test.rb +0 -23
- data/test/unit/yield_parameters_test.rb +0 -91
@@ -1,164 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<meta charset="utf-8">
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
-
<title>
|
7
|
-
Module: Mocha::Integration::TestUnit::Adapter
|
8
|
-
|
9
|
-
— Mocha 1.10.2
|
10
|
-
|
11
|
-
</title>
|
12
|
-
|
13
|
-
<link rel="stylesheet" href="../../../css/style.css" type="text/css" charset="utf-8" />
|
14
|
-
|
15
|
-
<link rel="stylesheet" href="../../../css/common.css" type="text/css" charset="utf-8" />
|
16
|
-
|
17
|
-
<script type="text/javascript" charset="utf-8">
|
18
|
-
pathId = "Mocha::Integration::TestUnit::Adapter";
|
19
|
-
relpath = '../../../';
|
20
|
-
</script>
|
21
|
-
|
22
|
-
|
23
|
-
<script type="text/javascript" charset="utf-8" src="../../../js/jquery.js"></script>
|
24
|
-
|
25
|
-
<script type="text/javascript" charset="utf-8" src="../../../js/app.js"></script>
|
26
|
-
|
27
|
-
|
28
|
-
</head>
|
29
|
-
<body>
|
30
|
-
<div class="nav_wrap">
|
31
|
-
<iframe id="nav" src="../../../class_list.html?1"></iframe>
|
32
|
-
<div id="resizer"></div>
|
33
|
-
</div>
|
34
|
-
|
35
|
-
<div id="main" tabindex="-1">
|
36
|
-
<div id="header">
|
37
|
-
<div id="menu">
|
38
|
-
|
39
|
-
<a href="../../../_index.html">Index (A)</a> »
|
40
|
-
<span class='title'><span class='object_link'><a href="../../../Mocha.html" title="Mocha (module)">Mocha</a></span></span> » <span class='title'><span class='object_link'><a href="../../Integration.html" title="Mocha::Integration (module)">Integration</a></span></span> » <span class='title'><span class='object_link'><a href="../TestUnit.html" title="Mocha::Integration::TestUnit (module)">TestUnit</a></span></span>
|
41
|
-
»
|
42
|
-
<span class="title">Adapter</span>
|
43
|
-
|
44
|
-
</div>
|
45
|
-
|
46
|
-
<div id="search">
|
47
|
-
|
48
|
-
<a class="full_list_link" id="class_list_link"
|
49
|
-
href="../../../class_list.html">
|
50
|
-
|
51
|
-
<svg width="24" height="24">
|
52
|
-
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
53
|
-
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
54
|
-
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
55
|
-
</svg>
|
56
|
-
</a>
|
57
|
-
|
58
|
-
</div>
|
59
|
-
<div class="clear"></div>
|
60
|
-
</div>
|
61
|
-
|
62
|
-
<div id="content"><h1>Module: Mocha::Integration::TestUnit::Adapter
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
</h1>
|
67
|
-
<div class="box_info">
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
<dl>
|
75
|
-
<dt>Includes:</dt>
|
76
|
-
<dd><span class='object_link'><a href="../../API.html" title="Mocha::API (module)">API</a></span></dd>
|
77
|
-
</dl>
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
<dl>
|
85
|
-
<dt>Defined in:</dt>
|
86
|
-
<dd>lib/mocha/integration/test_unit/adapter.rb</dd>
|
87
|
-
</dl>
|
88
|
-
|
89
|
-
</div>
|
90
|
-
|
91
|
-
<h2>Overview</h2><div class="docstring">
|
92
|
-
<div class="discussion">
|
93
|
-
|
94
|
-
<p>Integrates Mocha into recent versions of Test::Unit.</p>
|
95
|
-
|
96
|
-
<p>See the source code for an example of how to integrate Mocha into a test library.</p>
|
97
|
-
|
98
|
-
|
99
|
-
</div>
|
100
|
-
</div>
|
101
|
-
<div class="tags">
|
102
|
-
|
103
|
-
|
104
|
-
</div>
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
<h2>Method Summary</h2>
|
119
|
-
|
120
|
-
<h3 class="inherited">Methods included from <span class='object_link'><a href="../../API.html" title="Mocha::API (module)">API</a></span></h3>
|
121
|
-
<p class="inherited"><span class='object_link'><a href="../../API.html#mock-instance_method" title="Mocha::API#mock (method)">#mock</a></span>, <span class='object_link'><a href="../../API.html#sequence-instance_method" title="Mocha::API#sequence (method)">#sequence</a></span>, <span class='object_link'><a href="../../API.html#states-instance_method" title="Mocha::API#states (method)">#states</a></span>, <span class='object_link'><a href="../../API.html#stub-instance_method" title="Mocha::API#stub (method)">#stub</a></span>, <span class='object_link'><a href="../../API.html#stub_everything-instance_method" title="Mocha::API#stub_everything (method)">#stub_everything</a></span></p>
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
<h3 class="inherited">Methods included from <span class='object_link'><a href="../../Hooks.html" title="Mocha::Hooks (module)">Hooks</a></span></h3>
|
132
|
-
<p class="inherited"><span class='object_link'><a href="../../Hooks.html#mocha_setup-instance_method" title="Mocha::Hooks#mocha_setup (method)">#mocha_setup</a></span>, <span class='object_link'><a href="../../Hooks.html#mocha_teardown-instance_method" title="Mocha::Hooks#mocha_teardown (method)">#mocha_teardown</a></span>, <span class='object_link'><a href="../../Hooks.html#mocha_verify-instance_method" title="Mocha::Hooks#mocha_verify (method)">#mocha_verify</a></span></p>
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
<h3 class="inherited">Methods included from <span class='object_link'><a href="../../ParameterMatchers.html" title="Mocha::ParameterMatchers (module)">ParameterMatchers</a></span></h3>
|
143
|
-
<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>
|
144
|
-
|
145
|
-
|
146
|
-
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-625523-7"></script>
|
147
|
-
<script>
|
148
|
-
window.dataLayer = window.dataLayer || [];
|
149
|
-
function gtag(){dataLayer.push(arguments);}
|
150
|
-
gtag('js', new Date());
|
151
|
-
|
152
|
-
gtag('config', 'UA-625523-7');
|
153
|
-
</script>
|
154
|
-
</div>
|
155
|
-
|
156
|
-
<div id="footer">
|
157
|
-
Generated on Thu Dec 12 10:57:47 2019 by
|
158
|
-
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
159
|
-
0.9.20 (ruby-2.6.5).
|
160
|
-
</div>
|
161
|
-
|
162
|
-
</div>
|
163
|
-
</body>
|
164
|
-
</html>
|
data/docs/Mocha/Mock.html
DELETED
@@ -1,1237 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<meta charset="utf-8">
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
-
<title>
|
7
|
-
Class: Mocha::Mock
|
8
|
-
|
9
|
-
— Mocha 1.10.2
|
10
|
-
|
11
|
-
</title>
|
12
|
-
|
13
|
-
<link rel="stylesheet" href="../css/style.css" type="text/css" charset="utf-8" />
|
14
|
-
|
15
|
-
<link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8" />
|
16
|
-
|
17
|
-
<script type="text/javascript" charset="utf-8">
|
18
|
-
pathId = "Mocha::Mock";
|
19
|
-
relpath = '../';
|
20
|
-
</script>
|
21
|
-
|
22
|
-
|
23
|
-
<script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
|
24
|
-
|
25
|
-
<script type="text/javascript" charset="utf-8" src="../js/app.js"></script>
|
26
|
-
|
27
|
-
|
28
|
-
</head>
|
29
|
-
<body>
|
30
|
-
<div class="nav_wrap">
|
31
|
-
<iframe id="nav" src="../class_list.html?1"></iframe>
|
32
|
-
<div id="resizer"></div>
|
33
|
-
</div>
|
34
|
-
|
35
|
-
<div id="main" tabindex="-1">
|
36
|
-
<div id="header">
|
37
|
-
<div id="menu">
|
38
|
-
|
39
|
-
<a href="../_index.html">Index (M)</a> »
|
40
|
-
<span class='title'><span class='object_link'><a href="../Mocha.html" title="Mocha (module)">Mocha</a></span></span>
|
41
|
-
»
|
42
|
-
<span class="title">Mock</span>
|
43
|
-
|
44
|
-
</div>
|
45
|
-
|
46
|
-
<div id="search">
|
47
|
-
|
48
|
-
<a class="full_list_link" id="class_list_link"
|
49
|
-
href="../class_list.html">
|
50
|
-
|
51
|
-
<svg width="24" height="24">
|
52
|
-
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
53
|
-
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
54
|
-
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
55
|
-
</svg>
|
56
|
-
</a>
|
57
|
-
|
58
|
-
</div>
|
59
|
-
<div class="clear"></div>
|
60
|
-
</div>
|
61
|
-
|
62
|
-
<div id="content"><h1>Class: Mocha::Mock
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
</h1>
|
67
|
-
<div class="box_info">
|
68
|
-
|
69
|
-
<dl>
|
70
|
-
<dt>Inherits:</dt>
|
71
|
-
<dd>
|
72
|
-
<span class="inheritName"><span class='object_link'>Object</span></span>
|
73
|
-
|
74
|
-
<ul class="fullTree">
|
75
|
-
<li><span class='object_link'>Object</span></li>
|
76
|
-
|
77
|
-
<li class="next">Mocha::Mock</li>
|
78
|
-
|
79
|
-
</ul>
|
80
|
-
<a href="#" class="inheritanceTree">show all</a>
|
81
|
-
|
82
|
-
</dd>
|
83
|
-
</dl>
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
<dl>
|
96
|
-
<dt>Defined in:</dt>
|
97
|
-
<dd>lib/mocha/mock.rb</dd>
|
98
|
-
</dl>
|
99
|
-
|
100
|
-
</div>
|
101
|
-
|
102
|
-
<h2>Overview</h2><div class="docstring">
|
103
|
-
<div class="discussion">
|
104
|
-
|
105
|
-
<p>Traditional mock object.</p>
|
106
|
-
|
107
|
-
<p><span class='object_link'><a href="#expects-instance_method" title="Mocha::Mock#expects (method)">#expects</a></span> and <span class='object_link'><a href="#stubs-instance_method" title="Mocha::Mock#stubs (method)">#stubs</a></span> return an <span class='object_link'><a href="Expectation.html" title="Mocha::Expectation (class)">Expectation</a></span> which can be further modified by methods on <span class='object_link'><a href="Expectation.html" title="Mocha::Expectation (class)">Expectation</a></span>.</p>
|
108
|
-
|
109
|
-
<p><span class='object_link'><a href="#responds_like-instance_method" title="Mocha::Mock#responds_like (method)">#responds_like</a></span> and <span class='object_link'><a href="#responds_like_instance_of-instance_method" title="Mocha::Mock#responds_like_instance_of (method)">#responds_like_instance_of</a></span> both return a <span class='object_link'><a href="" title="Mocha::Mock (class)">Mock</a></span>, and can therefore, be chained to the original creation methods in <span class='object_link'><a href="API.html" title="Mocha::API (module)">API</a></span>. They 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>
|
110
|
-
|
111
|
-
<p>Stubs and expectations are basically the same thing. A stub is just an expectation of zero or more invocations. The <span class='object_link'><a href="#stubs-instance_method" title="Mocha::Mock#stubs (method)">#stubs</a></span> method is syntactic sugar to make the intent of the test more explicit.</p>
|
112
|
-
|
113
|
-
<p>When a method is invoked on a mock object, the mock object searches through its expectations from newest to oldest to find one that matches the invocation. After the invocation, the matching expectation might stop matching further invocations. For example, an <tt>expects(:foo).once</tt> expectation only matches once and will be ignored on future invocations while an <tt>expects(:foo).at_least_once</tt> expectation will always be matched against invocations.</p>
|
114
|
-
|
115
|
-
<p>This scheme allows you to:</p>
|
116
|
-
<ul><li>
|
117
|
-
<p>Set up default stubs in your the <code>setup</code> method of your test class and override some of those stubs in individual tests.</p>
|
118
|
-
</li><li>
|
119
|
-
<p>Set up different <code>once</code> expectations for the same method with different action per invocation. However, it's better to use the <span class='object_link'><a href="Expectation.html#returns-instance_method" title="Mocha::Expectation#returns (method)">Expectation#returns</a></span> method with multiple arguments to do this, as described below.</p>
|
120
|
-
</li></ul>
|
121
|
-
|
122
|
-
<p>However, there are some possible “gotchas” caused by this scheme:</p>
|
123
|
-
<ul><li>
|
124
|
-
<p>if you create an expectation and then a stub for the same method, the stub will always override the expectation and the expectation will never be met.</p>
|
125
|
-
</li><li>
|
126
|
-
<p>if you create a stub and then an expectation for the same method, the expectation will match, and when it stops matching the stub will be used instead, possibly masking test failures.</p>
|
127
|
-
</li><li>
|
128
|
-
<p>if you create different expectations for the same method, they will be invoked in the opposite order than that in which they were specified, rather than the same order.</p>
|
129
|
-
</li></ul>
|
130
|
-
|
131
|
-
<p>The best thing to do is not set up multiple expectations and stubs for the same method with exactly the same matchers. Instead, use the <span class='object_link'><a href="Expectation.html#returns-instance_method" title="Mocha::Expectation#returns (method)">Expectation#returns</a></span> method with multiple arguments to create multiple actions for a method. You can also chain multiple calls to <span class='object_link'><a href="Expectation.html#returns-instance_method" title="Mocha::Expectation#returns (method)">Expectation#returns</a></span> and <span class='object_link'><a href="Expectation.html#raises-instance_method" title="Mocha::Expectation#raises (method)">Expectation#raises</a></span> (along with syntactic sugar <span class='object_link'><a href="Expectation.html#then-instance_method" title="Mocha::Expectation#then (method)">Expectation#then</a></span> if desired).</p>
|
132
|
-
|
133
|
-
<p>If you want to specify more complex ordering or order invocations across different mock objects, use the <span class='object_link'><a href="Expectation.html#in_sequence-instance_method" title="Mocha::Expectation#in_sequence (method)">Expectation#in_sequence</a></span> method to explicitly define a total or partial ordering of invocations.</p>
|
134
|
-
|
135
|
-
|
136
|
-
</div>
|
137
|
-
</div>
|
138
|
-
<div class="tags">
|
139
|
-
|
140
|
-
<div class="examples">
|
141
|
-
<p class="tag_title">Examples:</p>
|
142
|
-
|
143
|
-
|
144
|
-
<pre class="example code"><code><span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='rparen'>)</span>
|
145
|
-
<span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='symbol'>:expected_method</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_returns'>returns</span><span class='lparen'>(</span><span class='int'>1</span><span class='comma'>,</span> <span class='int'>2</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_then'>then</span><span class='period'>.</span><span class='id identifier rubyid_raises'>raises</span><span class='lparen'>(</span><span class='const'>Exception</span><span class='rparen'>)</span>
|
146
|
-
<span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span> <span class='comment'># => 1
|
147
|
-
</span><span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span> <span class='comment'># => 2
|
148
|
-
</span><span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span> <span class='comment'># => raises exception of class Exception1</span></code></pre>
|
149
|
-
|
150
|
-
</div>
|
151
|
-
|
152
|
-
|
153
|
-
</div>
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
<h2>
|
162
|
-
Instance Method Summary
|
163
|
-
<small><a href="#" class="summary_toggle">collapse</a></small>
|
164
|
-
</h2>
|
165
|
-
|
166
|
-
<ul class="summary">
|
167
|
-
|
168
|
-
<li class="public ">
|
169
|
-
<span class="summary_signature">
|
170
|
-
|
171
|
-
<a href="#expects-instance_method" title="#expects (instance method)">#<strong>expects</strong>(method_name_or_hash, backtrace = nil) ⇒ Expectation </a>
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
(also: #__expects__)
|
176
|
-
|
177
|
-
</span>
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
<span class="summary_desc"><div class='inline'>
|
188
|
-
<p>Adds an expectation that the specified method must be called exactly once with any parameters.</p>
|
189
|
-
</div></span>
|
190
|
-
|
191
|
-
</li>
|
192
|
-
|
193
|
-
|
194
|
-
<li class="public ">
|
195
|
-
<span class="summary_signature">
|
196
|
-
|
197
|
-
<a href="#respond_to%3F-instance_method" title="#respond_to? (instance method)">#<strong>respond_to?</strong>(symbol, include_private = false) ⇒ Boolean </a>
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
</span>
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
<span class="summary_desc"><div class='inline'></div></span>
|
212
|
-
|
213
|
-
</li>
|
214
|
-
|
215
|
-
|
216
|
-
<li class="public ">
|
217
|
-
<span class="summary_signature">
|
218
|
-
|
219
|
-
<a href="#responds_like-instance_method" title="#responds_like (instance method)">#<strong>responds_like</strong>(responder) ⇒ Mock </a>
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
(also: #quacks_like)
|
224
|
-
|
225
|
-
</span>
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
<span class="summary_desc"><div class='inline'>
|
236
|
-
<p>Constrains the <span class='object_link'><a href="" title="Mocha::Mock (class)">Mock</a></span> instance so that it can only expect or stub methods to which <code>responder</code> responds.</p>
|
237
|
-
</div></span>
|
238
|
-
|
239
|
-
</li>
|
240
|
-
|
241
|
-
|
242
|
-
<li class="public ">
|
243
|
-
<span class="summary_signature">
|
244
|
-
|
245
|
-
<a href="#responds_like_instance_of-instance_method" title="#responds_like_instance_of (instance method)">#<strong>responds_like_instance_of</strong>(responder_class) ⇒ Mock </a>
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
(also: #quacks_like_instance_of)
|
250
|
-
|
251
|
-
</span>
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
<span class="summary_desc"><div class='inline'>
|
262
|
-
<p>Constrains the <span class='object_link'><a href="" title="Mocha::Mock (class)">Mock</a></span> instance so that it can only expect or stub methods to which an instance of the <code>responder_class</code> responds.</p>
|
263
|
-
</div></span>
|
264
|
-
|
265
|
-
</li>
|
266
|
-
|
267
|
-
|
268
|
-
<li class="public ">
|
269
|
-
<span class="summary_signature">
|
270
|
-
|
271
|
-
<a href="#stubs-instance_method" title="#stubs (instance method)">#<strong>stubs</strong>(method_name_or_hash, backtrace = nil) ⇒ Expectation </a>
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
(also: #__stubs__)
|
276
|
-
|
277
|
-
</span>
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
<span class="summary_desc"><div class='inline'>
|
288
|
-
<p>Adds an expectation that the specified method may be called any number of times with any parameters.</p>
|
289
|
-
</div></span>
|
290
|
-
|
291
|
-
</li>
|
292
|
-
|
293
|
-
|
294
|
-
<li class="public ">
|
295
|
-
<span class="summary_signature">
|
296
|
-
|
297
|
-
<a href="#unstub-instance_method" title="#unstub (instance method)">#<strong>unstub</strong>(*method_names) ⇒ Object </a>
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
</span>
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
<span class="summary_desc"><div class='inline'>
|
312
|
-
<p>Removes the specified stubbed methods (added by calls to <span class='object_link'><a href="#expects-instance_method" title="Mocha::Mock#expects (method)">#expects</a></span> or <span class='object_link'><a href="#stubs-instance_method" title="Mocha::Mock#stubs (method)">#stubs</a></span>) and all expectations associated with them.</p>
|
313
|
-
</div></span>
|
314
|
-
|
315
|
-
</li>
|
316
|
-
|
317
|
-
|
318
|
-
</ul>
|
319
|
-
|
320
|
-
|
321
|
-
<div id="method_missing_details" class="method_details_list">
|
322
|
-
<h2>Dynamic Method Handling</h2>
|
323
|
-
<p class="notice this">
|
324
|
-
This class handles dynamic methods through the <tt>method_missing</tt> method
|
325
|
-
|
326
|
-
</p>
|
327
|
-
|
328
|
-
<div class="method_details first">
|
329
|
-
<h3 class="signature first" id="method_missing-instance_method">
|
330
|
-
|
331
|
-
#<strong>method_missing</strong>(symbol, *arguments, &block) ⇒ <tt><span class='object_link'>Object</span></tt>
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
</h3><div class="docstring">
|
338
|
-
<div class="discussion">
|
339
|
-
|
340
|
-
<p>rubocop:disable Style/MethodMissingSuper,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity</p>
|
341
|
-
|
342
|
-
|
343
|
-
</div>
|
344
|
-
</div>
|
345
|
-
<div class="tags">
|
346
|
-
|
347
|
-
|
348
|
-
</div><table class="source_code">
|
349
|
-
<tr>
|
350
|
-
<td>
|
351
|
-
<pre class="lines">
|
352
|
-
|
353
|
-
|
354
|
-
309
|
355
|
-
310
|
356
|
-
311
|
357
|
-
312
|
358
|
-
313
|
359
|
-
314
|
360
|
-
315
|
361
|
-
316
|
362
|
-
317
|
363
|
-
318
|
364
|
-
319
|
365
|
-
320
|
366
|
-
321
|
367
|
-
322
|
368
|
-
323
|
369
|
-
324
|
370
|
-
325
|
371
|
-
326</pre>
|
372
|
-
</td>
|
373
|
-
<td>
|
374
|
-
<pre class="code"><span class="info file"># File 'lib/mocha/mock.rb', line 309</span>
|
375
|
-
|
376
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_method_missing'>method_missing</span><span class='lparen'>(</span><span class='id identifier rubyid_symbol'>symbol</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_arguments'>arguments</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
377
|
-
<span class='kw'>if</span> <span class='ivar'>@responder</span> <span class='op'>&&</span> <span class='op'>!</span><span class='ivar'>@responder</span><span class='period'>.</span><span class='id identifier rubyid_respond_to?'>respond_to?</span><span class='lparen'>(</span><span class='id identifier rubyid_symbol'>symbol</span><span class='rparen'>)</span>
|
378
|
-
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>NoMethodError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>undefined method `</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_symbol'>symbol</span><span class='embexpr_end'>}</span><span class='tstring_content'>' for </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_mocha_inspect'>mocha_inspect</span><span class='embexpr_end'>}</span><span class='tstring_content'> which responds like </span><span class='embexpr_beg'>#{</span><span class='ivar'>@responder</span><span class='period'>.</span><span class='id identifier rubyid_mocha_inspect'>mocha_inspect</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span>
|
379
|
-
<span class='kw'>end</span>
|
380
|
-
<span class='id identifier rubyid_invocation'>invocation</span> <span class='op'>=</span> <span class='const'>Invocation</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='kw'>self</span><span class='comma'>,</span> <span class='id identifier rubyid_symbol'>symbol</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_arguments'>arguments</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
381
|
-
<span class='kw'>if</span> <span class='lparen'>(</span><span class='id identifier rubyid_matching_expectation_allowing_invocation'>matching_expectation_allowing_invocation</span> <span class='op'>=</span> <span class='id identifier rubyid_all_expectations'>all_expectations</span><span class='period'>.</span><span class='id identifier rubyid_match_allowing_invocation'>match_allowing_invocation</span><span class='lparen'>(</span><span class='id identifier rubyid_invocation'>invocation</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
382
|
-
<span class='id identifier rubyid_matching_expectation_allowing_invocation'>matching_expectation_allowing_invocation</span><span class='period'>.</span><span class='id identifier rubyid_invoke'>invoke</span><span class='lparen'>(</span><span class='id identifier rubyid_invocation'>invocation</span><span class='rparen'>)</span>
|
383
|
-
<span class='kw'>elsif</span> <span class='lparen'>(</span><span class='id identifier rubyid_matching_expectation'>matching_expectation</span> <span class='op'>=</span> <span class='id identifier rubyid_all_expectations'>all_expectations</span><span class='period'>.</span><span class='id identifier rubyid_match'>match</span><span class='lparen'>(</span><span class='id identifier rubyid_invocation'>invocation</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='op'>||</span> <span class='lparen'>(</span><span class='op'>!</span><span class='id identifier rubyid_matching_expectation'>matching_expectation</span> <span class='op'>&&</span> <span class='op'>!</span><span class='ivar'>@everything_stubbed</span><span class='rparen'>)</span>
|
384
|
-
<span class='kw'>if</span> <span class='ivar'>@unexpected_invocation</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
|
385
|
-
<span class='ivar'>@unexpected_invocation</span> <span class='op'>=</span> <span class='id identifier rubyid_invocation'>invocation</span>
|
386
|
-
<span class='id identifier rubyid_matching_expectation'>matching_expectation</span><span class='period'>.</span><span class='id identifier rubyid_invoke'>invoke</span><span class='lparen'>(</span><span class='id identifier rubyid_invocation'>invocation</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_matching_expectation'>matching_expectation</span>
|
387
|
-
<span class='id identifier rubyid_message'>message</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='ivar'>@unexpected_invocation</span><span class='period'>.</span><span class='id identifier rubyid_call_description'>call_description</span><span class='embexpr_end'>}</span><span class='tstring_content'>\n</span><span class='embexpr_beg'>#{</span><span class='ivar'>@mockery</span><span class='period'>.</span><span class='id identifier rubyid_mocha_inspect'>mocha_inspect</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span>
|
388
|
-
<span class='kw'>else</span>
|
389
|
-
<span class='id identifier rubyid_message'>message</span> <span class='op'>=</span> <span class='ivar'>@unexpected_invocation</span><span class='period'>.</span><span class='id identifier rubyid_short_call_description'>short_call_description</span>
|
390
|
-
<span class='kw'>end</span>
|
391
|
-
<span class='id identifier rubyid_raise'>raise</span> <span class='const'><span class='object_link'><a href="ExpectationErrorFactory.html" title="Mocha::ExpectationErrorFactory (class)">ExpectationErrorFactory</a></span></span><span class='period'>.</span><span class='id identifier rubyid_build'>build</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>unexpected invocation: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_message'>message</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='id identifier rubyid_caller'>caller</span><span class='rparen'>)</span>
|
392
|
-
<span class='kw'>end</span>
|
393
|
-
<span class='kw'>end</span></pre>
|
394
|
-
</td>
|
395
|
-
</tr>
|
396
|
-
</table>
|
397
|
-
</div>
|
398
|
-
|
399
|
-
</div>
|
400
|
-
|
401
|
-
|
402
|
-
<div id="instance_method_details" class="method_details_list">
|
403
|
-
<h2>Instance Method Details</h2>
|
404
|
-
|
405
|
-
|
406
|
-
<div class="method_details first">
|
407
|
-
<h3 class="signature first" id="expects-instance_method">
|
408
|
-
|
409
|
-
|
410
|
-
<span class="overload">#<strong>expects</strong>(method_name) ⇒ <tt><span class='object_link'><a href="Expectation.html" title="Mocha::Expectation (class)">Expectation</a></span></tt> </span>
|
411
|
-
|
412
|
-
<span class="overload">#<strong>expects</strong>(expected_methods_vs_return_values) ⇒ <tt><span class='object_link'><a href="Expectation.html" title="Mocha::Expectation (class)">Expectation</a></span></tt> </span>
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
<span class="aliases">Also known as:
|
418
|
-
<span class="names"><span id='__expects__-instance_method'>__expects__</span></span>
|
419
|
-
</span>
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
</h3><div class="docstring">
|
424
|
-
<div class="discussion">
|
425
|
-
|
426
|
-
<p>Adds an expectation that the specified method must be called exactly once with any parameters.</p>
|
427
|
-
|
428
|
-
|
429
|
-
</div>
|
430
|
-
</div>
|
431
|
-
<div class="tags">
|
432
|
-
|
433
|
-
<div class="examples">
|
434
|
-
<p class="tag_title">Examples:</p>
|
435
|
-
|
436
|
-
|
437
|
-
<p class="example_title"><div class='inline'>
|
438
|
-
<p>Expected method invoked once so no error raised</p>
|
439
|
-
</div></p>
|
440
|
-
|
441
|
-
<pre class="example code"><code><span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='rparen'>)</span>
|
442
|
-
<span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:expected_method</span><span class='rparen'>)</span>
|
443
|
-
<span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span></code></pre>
|
444
|
-
|
445
|
-
|
446
|
-
<p class="example_title"><div class='inline'>
|
447
|
-
<p>Expected method not invoked so error raised</p>
|
448
|
-
</div></p>
|
449
|
-
|
450
|
-
<pre class="example code"><code><span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='rparen'>)</span>
|
451
|
-
<span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:expected_method</span><span class='rparen'>)</span>
|
452
|
-
<span class='comment'># error raised when test completes, because expected_method not called exactly once</span></code></pre>
|
453
|
-
|
454
|
-
|
455
|
-
<p class="example_title"><div class='inline'>
|
456
|
-
<p>Expected method invoked twice so error raised</p>
|
457
|
-
</div></p>
|
458
|
-
|
459
|
-
<pre class="example code"><code><span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='rparen'>)</span>
|
460
|
-
<span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:expected_method</span><span class='rparen'>)</span>
|
461
|
-
<span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span>
|
462
|
-
<span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span> <span class='comment'># => error raised when expected method invoked second time</span></code></pre>
|
463
|
-
|
464
|
-
|
465
|
-
<p class="example_title"><div class='inline'>
|
466
|
-
<p>Setup multiple expectations using <code>expected_methods_vs_return_values</code>.</p>
|
467
|
-
</div></p>
|
468
|
-
|
469
|
-
<pre class="example code"><code><span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='rparen'>)</span>
|
470
|
-
<span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:expected_method_one</span> <span class='op'>=></span> <span class='symbol'>:result_one</span><span class='comma'>,</span> <span class='symbol'>:expected_method_two</span> <span class='op'>=></span> <span class='symbol'>:result_two</span><span class='rparen'>)</span>
|
471
|
-
|
472
|
-
<span class='comment'># is exactly equivalent to
|
473
|
-
</span>
|
474
|
-
<span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='rparen'>)</span>
|
475
|
-
<span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:expected_method_one</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_returns'>returns</span><span class='lparen'>(</span><span class='symbol'>:result_one</span><span class='rparen'>)</span>
|
476
|
-
<span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:expected_method_two</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_returns'>returns</span><span class='lparen'>(</span><span class='symbol'>:result_two</span><span class='rparen'>)</span></code></pre>
|
477
|
-
|
478
|
-
</div>
|
479
|
-
|
480
|
-
<p class="tag_title">Overloads:</p>
|
481
|
-
<ul class="overload">
|
482
|
-
|
483
|
-
|
484
|
-
<li class="overload_item">
|
485
|
-
<span class="signature">#<strong>expects</strong>(method_name) ⇒ <tt><span class='object_link'><a href="Expectation.html" title="Mocha::Expectation (class)">Expectation</a></span></tt> </span>
|
486
|
-
<div class="docstring">
|
487
|
-
<div class="discussion">
|
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'>method_name</span>
|
499
|
-
|
500
|
-
|
501
|
-
<span class='type'>(<tt>Symbol</tt>, <tt>String</tt>)</span>
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
—
|
506
|
-
<div class='inline'>
|
507
|
-
<p>name of expected method</p>
|
508
|
-
</div>
|
509
|
-
|
510
|
-
</li>
|
511
|
-
|
512
|
-
</ul>
|
513
|
-
|
514
|
-
|
515
|
-
</div>
|
516
|
-
</li>
|
517
|
-
|
518
|
-
|
519
|
-
<li class="overload_item">
|
520
|
-
<span class="signature">#<strong>expects</strong>(expected_methods_vs_return_values) ⇒ <tt><span class='object_link'><a href="Expectation.html" title="Mocha::Expectation (class)">Expectation</a></span></tt> </span>
|
521
|
-
<div class="docstring">
|
522
|
-
<div class="discussion">
|
523
|
-
|
524
|
-
|
525
|
-
</div>
|
526
|
-
</div>
|
527
|
-
<div class="tags">
|
528
|
-
<p class="tag_title">Parameters:</p>
|
529
|
-
<ul class="param">
|
530
|
-
|
531
|
-
<li>
|
532
|
-
|
533
|
-
<span class='name'>expected_methods_vs_return_values</span>
|
534
|
-
|
535
|
-
|
536
|
-
<span class='type'>(<tt>Hash</tt>)</span>
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
—
|
541
|
-
<div class='inline'>
|
542
|
-
<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="#expects-instance_method" title="Mocha::Mock#expects (method)">#expects</a></span> were called multiple times.</p>
|
543
|
-
</div>
|
544
|
-
|
545
|
-
</li>
|
546
|
-
|
547
|
-
</ul>
|
548
|
-
|
549
|
-
|
550
|
-
</div>
|
551
|
-
</li>
|
552
|
-
|
553
|
-
</ul>
|
554
|
-
|
555
|
-
<p class="tag_title">Returns:</p>
|
556
|
-
<ul class="return">
|
557
|
-
|
558
|
-
<li>
|
559
|
-
|
560
|
-
|
561
|
-
<span class='type'>(<tt><span class='object_link'><a href="Expectation.html" title="Mocha::Expectation (class)">Expectation</a></span></tt>)</span>
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
—
|
566
|
-
<div class='inline'>
|
567
|
-
<p>last-built expectation which can be further modified by methods on <span class='object_link'><a href="Expectation.html" title="Mocha::Expectation (class)">Expectation</a></span>.</p>
|
568
|
-
</div>
|
569
|
-
|
570
|
-
</li>
|
571
|
-
|
572
|
-
</ul>
|
573
|
-
|
574
|
-
</div><table class="source_code">
|
575
|
-
<tr>
|
576
|
-
<td>
|
577
|
-
<pre class="lines">
|
578
|
-
|
579
|
-
|
580
|
-
111
|
581
|
-
112
|
582
|
-
113
|
583
|
-
114
|
584
|
-
115
|
585
|
-
116
|
586
|
-
117
|
587
|
-
118
|
588
|
-
119
|
589
|
-
120</pre>
|
590
|
-
</td>
|
591
|
-
<td>
|
592
|
-
<pre class="code"><span class="info file"># File 'lib/mocha/mock.rb', line 111</span>
|
593
|
-
|
594
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='id identifier rubyid_method_name_or_hash'>method_name_or_hash</span><span class='comma'>,</span> <span class='id identifier rubyid_backtrace'>backtrace</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
595
|
-
<span class='id identifier rubyid_iterator'>iterator</span> <span class='op'>=</span> <span class='const'>ArgumentIterator</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_method_name_or_hash'>method_name_or_hash</span><span class='rparen'>)</span>
|
596
|
-
<span class='id identifier rubyid_iterator'>iterator</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='op'>|</span>
|
597
|
-
<span class='id identifier rubyid_method_name'>method_name</span> <span class='op'>=</span> <span class='id identifier rubyid_args'>args</span><span class='period'>.</span><span class='id identifier rubyid_shift'>shift</span>
|
598
|
-
<span class='id identifier rubyid_ensure_method_not_already_defined'>ensure_method_not_already_defined</span><span class='lparen'>(</span><span class='id identifier rubyid_method_name'>method_name</span><span class='rparen'>)</span>
|
599
|
-
<span class='id identifier rubyid_expectation'>expectation</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="Expectation.html" title="Mocha::Expectation (class)">Expectation</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='kw'>self</span><span class='comma'>,</span> <span class='id identifier rubyid_method_name'>method_name</span><span class='comma'>,</span> <span class='id identifier rubyid_backtrace'>backtrace</span><span class='rparen'>)</span>
|
600
|
-
<span class='id identifier rubyid_expectation'>expectation</span><span class='period'>.</span><span class='id identifier rubyid_returns'>returns</span><span class='lparen'>(</span><span class='id identifier rubyid_args'>args</span><span class='period'>.</span><span class='id identifier rubyid_shift'>shift</span><span class='rparen'>)</span> <span class='kw'>unless</span> <span class='id identifier rubyid_args'>args</span><span class='period'>.</span><span class='id identifier rubyid_empty?'>empty?</span>
|
601
|
-
<span class='ivar'>@expectations</span><span class='period'>.</span><span class='id identifier rubyid_add'>add</span><span class='lparen'>(</span><span class='id identifier rubyid_expectation'>expectation</span><span class='rparen'>)</span>
|
602
|
-
<span class='kw'>end</span>
|
603
|
-
<span class='kw'>end</span></pre>
|
604
|
-
</td>
|
605
|
-
</tr>
|
606
|
-
</table>
|
607
|
-
</div>
|
608
|
-
|
609
|
-
<div class="method_details ">
|
610
|
-
<h3 class="signature " id="respond_to?-instance_method">
|
611
|
-
|
612
|
-
#<strong>respond_to?</strong>(symbol, include_private = false) ⇒ <tt>Boolean</tt>
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
</h3><div class="docstring">
|
619
|
-
<div class="discussion">
|
620
|
-
|
621
|
-
|
622
|
-
</div>
|
623
|
-
</div>
|
624
|
-
<div class="tags">
|
625
|
-
|
626
|
-
<p class="tag_title">Returns:</p>
|
627
|
-
<ul class="return">
|
628
|
-
|
629
|
-
<li>
|
630
|
-
|
631
|
-
|
632
|
-
<span class='type'>(<tt>Boolean</tt>)</span>
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
</li>
|
637
|
-
|
638
|
-
</ul>
|
639
|
-
|
640
|
-
</div><table class="source_code">
|
641
|
-
<tr>
|
642
|
-
<td>
|
643
|
-
<pre class="lines">
|
644
|
-
|
645
|
-
|
646
|
-
344
|
647
|
-
345
|
648
|
-
346</pre>
|
649
|
-
</td>
|
650
|
-
<td>
|
651
|
-
<pre class="code"><span class="info file"># File 'lib/mocha/mock.rb', line 344</span>
|
652
|
-
|
653
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_respond_to?'>respond_to?</span><span class='lparen'>(</span><span class='id identifier rubyid_symbol'>symbol</span><span class='comma'>,</span> <span class='id identifier rubyid_include_private'>include_private</span> <span class='op'>=</span> <span class='kw'>false</span><span class='rparen'>)</span>
|
654
|
-
<span class='id identifier rubyid_respond_to_missing?'>respond_to_missing?</span><span class='lparen'>(</span><span class='id identifier rubyid_symbol'>symbol</span><span class='comma'>,</span> <span class='id identifier rubyid_include_private'>include_private</span><span class='rparen'>)</span>
|
655
|
-
<span class='kw'>end</span></pre>
|
656
|
-
</td>
|
657
|
-
</tr>
|
658
|
-
</table>
|
659
|
-
</div>
|
660
|
-
|
661
|
-
<div class="method_details ">
|
662
|
-
<h3 class="signature " id="responds_like-instance_method">
|
663
|
-
|
664
|
-
#<strong>responds_like</strong>(responder) ⇒ <tt><span class='object_link'><a href="" title="Mocha::Mock (class)">Mock</a></span></tt>
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
<span class="aliases">Also known as:
|
669
|
-
<span class="names"><span id='quacks_like-instance_method'>quacks_like</span></span>
|
670
|
-
</span>
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
</h3><div class="docstring">
|
675
|
-
<div class="discussion">
|
676
|
-
|
677
|
-
<p>Constrains the <span class='object_link'><a href="" title="Mocha::Mock (class)">Mocha::Mock</a></span> instance so that it can only expect or stub methods to which <code>responder</code> responds. The constraint is only applied at method invocation time.</p>
|
678
|
-
|
679
|
-
<p>A <code>NoMethodError</code> will be raised if the <code>responder</code> does not <code>#respond_to?</code> a method invocation (even if the method has been expected or stubbed).</p>
|
680
|
-
|
681
|
-
<p>The <span class='object_link'><a href="" title="Mocha::Mock (class)">Mocha::Mock</a></span> instance will delegate its <code>#respond_to?</code> method to the <code>responder</code>.</p>
|
682
|
-
|
683
|
-
<p>Note that the methods on <code>responder</code> are never actually invoked.</p>
|
684
|
-
|
685
|
-
|
686
|
-
</div>
|
687
|
-
</div>
|
688
|
-
<div class="tags">
|
689
|
-
|
690
|
-
<div class="examples">
|
691
|
-
<p class="tag_title">Examples:</p>
|
692
|
-
|
693
|
-
|
694
|
-
<p class="example_title"><div class='inline'>
|
695
|
-
<p>Normal mocking</p>
|
696
|
-
</div></p>
|
697
|
-
|
698
|
-
<pre class="example code"><code><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>
|
699
|
-
<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>
|
700
|
-
<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>
|
701
|
-
<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
|
702
|
-
</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'># => true
|
703
|
-
</span><span class='id identifier rubyid_sheep'>sheep</span><span class='period'>.</span><span class='id identifier rubyid_chew'>chew</span>
|
704
|
-
<span class='id identifier rubyid_sheep'>sheep</span><span class='period'>.</span><span class='id identifier rubyid_foo'>foo</span>
|
705
|
-
<span class='comment'># no error raised</span></code></pre>
|
706
|
-
|
707
|
-
|
708
|
-
<p class="example_title"><div class='inline'>
|
709
|
-
<p>Using <span class='object_link'><a href="#responds_like-instance_method" title="Mocha::Mock#responds_like (method)">#responds_like</a></span> with an instance method</p>
|
710
|
-
</div></p>
|
711
|
-
|
712
|
-
<pre class="example code"><code><span class='kw'>class</span> <span class='const'>Sheep</span>
|
713
|
-
<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>
|
714
|
-
<span class='kw'>end</span>
|
715
|
-
|
716
|
-
<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>
|
717
|
-
<span class='id identifier rubyid_sheep'>sheep</span><span class='period'>.</span><span class='id identifier rubyid_responds_like'>responds_like</span><span class='lparen'>(</span><span class='const'>Sheep</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='rparen'>)</span>
|
718
|
-
<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>
|
719
|
-
<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>
|
720
|
-
<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
|
721
|
-
</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
|
722
|
-
</span><span class='id identifier rubyid_sheep'>sheep</span><span class='period'>.</span><span class='id identifier rubyid_chew'>chew</span>
|
723
|
-
<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>
|
724
|
-
|
725
|
-
|
726
|
-
<p class="example_title"><div class='inline'>
|
727
|
-
<p>Using <span class='object_link'><a href="#responds_like-instance_method" title="Mocha::Mock#responds_like (method)">#responds_like</a></span> with a class method</p>
|
728
|
-
</div></p>
|
729
|
-
|
730
|
-
<pre class="example code"><code><span class='kw'>class</span> <span class='const'>Sheep</span>
|
731
|
-
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_number_of_legs'>number_of_legs</span><span class='semicolon'>;</span> <span class='kw'>end</span>
|
732
|
-
<span class='kw'>end</span>
|
733
|
-
|
734
|
-
<span class='id identifier rubyid_sheep_class'>sheep_class</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_class</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
735
|
-
<span class='id identifier rubyid_sheep_class'>sheep_class</span><span class='period'>.</span><span class='id identifier rubyid_responds_like'>responds_like</span><span class='lparen'>(</span><span class='const'>Sheep</span><span class='rparen'>)</span>
|
736
|
-
<span class='id identifier rubyid_sheep_class'>sheep_class</span><span class='period'>.</span><span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='symbol'>:number_of_legs</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_returns'>returns</span><span class='lparen'>(</span><span class='int'>4</span><span class='rparen'>)</span>
|
737
|
-
<span class='id identifier rubyid_sheep_class'>sheep_class</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>
|
738
|
-
<span class='id identifier rubyid_sheep_class'>sheep_class</span><span class='period'>.</span><span class='id identifier rubyid_respond_to?'>respond_to?</span><span class='lparen'>(</span><span class='symbol'>:number_of_legs</span><span class='rparen'>)</span> <span class='comment'># => true
|
739
|
-
</span><span class='id identifier rubyid_sheep_class'>sheep_class</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
|
740
|
-
</span><span class='id identifier rubyid_sheep_class'>sheep_class</span><span class='period'>.</span><span class='id identifier rubyid_number_of_legs'>number_of_legs</span> <span class='comment'># => 4
|
741
|
-
</span><span class='id identifier rubyid_sheep_class'>sheep_class</span><span class='period'>.</span><span class='id identifier rubyid_foo'>foo</span> <span class='comment'># => raises NoMethodError exception</span></code></pre>
|
742
|
-
|
743
|
-
</div>
|
744
|
-
<p class="tag_title">Parameters:</p>
|
745
|
-
<ul class="param">
|
746
|
-
|
747
|
-
<li>
|
748
|
-
|
749
|
-
<span class='name'>responder</span>
|
750
|
-
|
751
|
-
|
752
|
-
<span class='type'>(<tt><span class='object_link'>Object</span></tt>, <tt>#respond_to?</tt>)</span>
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
—
|
757
|
-
<div class='inline'>
|
758
|
-
<p>an object used to determine whether <span class='object_link'><a href="" title="Mocha::Mock (class)">Mocha::Mock</a></span> instance should <code>#respond_to?</code> to an invocation.</p>
|
759
|
-
</div>
|
760
|
-
|
761
|
-
</li>
|
762
|
-
|
763
|
-
</ul>
|
764
|
-
|
765
|
-
<p class="tag_title">Returns:</p>
|
766
|
-
<ul class="return">
|
767
|
-
|
768
|
-
<li>
|
769
|
-
|
770
|
-
|
771
|
-
<span class='type'>(<tt><span class='object_link'><a href="" title="Mocha::Mock (class)">Mock</a></span></tt>)</span>
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
—
|
776
|
-
<div class='inline'>
|
777
|
-
<p>the same <span class='object_link'><a href="" title="Mocha::Mock (class)">Mocha::Mock</a></span> instance, thereby allowing invocations of other <span class='object_link'><a href="" title="Mocha::Mock (class)">Mocha::Mock</a></span> methods to be chained.</p>
|
778
|
-
</div>
|
779
|
-
|
780
|
-
</li>
|
781
|
-
|
782
|
-
</ul>
|
783
|
-
|
784
|
-
<p class="tag_title">See Also:</p>
|
785
|
-
<ul class="see">
|
786
|
-
|
787
|
-
<li><span class='object_link'><a href="#responds_like_instance_of-instance_method" title="Mocha::Mock#responds_like_instance_of (method)">#responds_like_instance_of</a></span></li>
|
788
|
-
|
789
|
-
</ul>
|
790
|
-
|
791
|
-
</div><table class="source_code">
|
792
|
-
<tr>
|
793
|
-
<td>
|
794
|
-
<pre class="lines">
|
795
|
-
|
796
|
-
|
797
|
-
232
|
798
|
-
233
|
799
|
-
234
|
800
|
-
235</pre>
|
801
|
-
</td>
|
802
|
-
<td>
|
803
|
-
<pre class="code"><span class="info file"># File 'lib/mocha/mock.rb', line 232</span>
|
804
|
-
|
805
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_responds_like'>responds_like</span><span class='lparen'>(</span><span class='id identifier rubyid_responder'>responder</span><span class='rparen'>)</span>
|
806
|
-
<span class='ivar'>@responder</span> <span class='op'>=</span> <span class='id identifier rubyid_responder'>responder</span>
|
807
|
-
<span class='kw'>self</span>
|
808
|
-
<span class='kw'>end</span></pre>
|
809
|
-
</td>
|
810
|
-
</tr>
|
811
|
-
</table>
|
812
|
-
</div>
|
813
|
-
|
814
|
-
<div class="method_details ">
|
815
|
-
<h3 class="signature " id="responds_like_instance_of-instance_method">
|
816
|
-
|
817
|
-
#<strong>responds_like_instance_of</strong>(responder_class) ⇒ <tt><span class='object_link'><a href="" title="Mocha::Mock (class)">Mock</a></span></tt>
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
<span class="aliases">Also known as:
|
822
|
-
<span class="names"><span id='quacks_like_instance_of-instance_method'>quacks_like_instance_of</span></span>
|
823
|
-
</span>
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
</h3><div class="docstring">
|
828
|
-
<div class="discussion">
|
829
|
-
|
830
|
-
<p>Constrains the <span class='object_link'><a href="" title="Mocha::Mock (class)">Mocha::Mock</a></span> instance so that it can only expect or stub methods to which an instance of the <code>responder_class</code> responds. The constraint is only applied at method invocation time. Note that the responder instance is instantiated using <tt>Class#allocate</tt>.</p>
|
831
|
-
|
832
|
-
<p>A <code>NoMethodError</code> will be raised if the responder instance does not <code>#respond_to?</code> a method invocation (even if the method has been expected or stubbed).</p>
|
833
|
-
|
834
|
-
<p>The <span class='object_link'><a href="" title="Mocha::Mock (class)">Mocha::Mock</a></span> instance will delegate its <code>#respond_to?</code> method to the responder instance.</p>
|
835
|
-
|
836
|
-
<p>Note that the methods on the responder instance are never actually invoked.</p>
|
837
|
-
|
838
|
-
|
839
|
-
</div>
|
840
|
-
</div>
|
841
|
-
<div class="tags">
|
842
|
-
|
843
|
-
<div class="examples">
|
844
|
-
<p class="tag_title">Examples:</p>
|
845
|
-
|
846
|
-
|
847
|
-
<p class="example_title"><div class='inline'>
|
848
|
-
<p>Using <span class='object_link'><a href="#responds_like_instance_of-instance_method" title="Mocha::Mock#responds_like_instance_of (method)">#responds_like_instance_of</a></span></p>
|
849
|
-
</div></p>
|
850
|
-
|
851
|
-
<pre class="example code"><code><span class='kw'>class</span> <span class='const'>Sheep</span>
|
852
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span>
|
853
|
-
<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>
|
854
|
-
<span class='kw'>end</span>
|
855
|
-
<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>
|
856
|
-
<span class='kw'>end</span>
|
857
|
-
|
858
|
-
<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>
|
859
|
-
<span class='id identifier rubyid_sheep'>sheep</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>
|
860
|
-
<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>
|
861
|
-
<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>
|
862
|
-
<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
|
863
|
-
</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
|
864
|
-
</span><span class='id identifier rubyid_sheep'>sheep</span><span class='period'>.</span><span class='id identifier rubyid_chew'>chew</span>
|
865
|
-
<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>
|
866
|
-
|
867
|
-
</div>
|
868
|
-
<p class="tag_title">Parameters:</p>
|
869
|
-
<ul class="param">
|
870
|
-
|
871
|
-
<li>
|
872
|
-
|
873
|
-
<span class='name'>responder_class</span>
|
874
|
-
|
875
|
-
|
876
|
-
<span class='type'>(<tt>Class</tt>)</span>
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
—
|
881
|
-
<div class='inline'>
|
882
|
-
<p>a class used to determine whether <span class='object_link'><a href="" title="Mocha::Mock (class)">Mocha::Mock</a></span> instance should <code>#respond_to?</code> to an invocation.</p>
|
883
|
-
</div>
|
884
|
-
|
885
|
-
</li>
|
886
|
-
|
887
|
-
</ul>
|
888
|
-
|
889
|
-
<p class="tag_title">Returns:</p>
|
890
|
-
<ul class="return">
|
891
|
-
|
892
|
-
<li>
|
893
|
-
|
894
|
-
|
895
|
-
<span class='type'>(<tt><span class='object_link'><a href="" title="Mocha::Mock (class)">Mock</a></span></tt>)</span>
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
—
|
900
|
-
<div class='inline'>
|
901
|
-
<p>the same <span class='object_link'><a href="" title="Mocha::Mock (class)">Mocha::Mock</a></span> instance, thereby allowing invocations of other <span class='object_link'><a href="" title="Mocha::Mock (class)">Mocha::Mock</a></span> methods to be chained.</p>
|
902
|
-
</div>
|
903
|
-
|
904
|
-
</li>
|
905
|
-
|
906
|
-
</ul>
|
907
|
-
|
908
|
-
<p class="tag_title">See Also:</p>
|
909
|
-
<ul class="see">
|
910
|
-
|
911
|
-
<li><span class='object_link'><a href="#responds_like-instance_method" title="Mocha::Mock#responds_like (method)">#responds_like</a></span></li>
|
912
|
-
|
913
|
-
</ul>
|
914
|
-
|
915
|
-
</div><table class="source_code">
|
916
|
-
<tr>
|
917
|
-
<td>
|
918
|
-
<pre class="lines">
|
919
|
-
|
920
|
-
|
921
|
-
265
|
922
|
-
266
|
923
|
-
267</pre>
|
924
|
-
</td>
|
925
|
-
<td>
|
926
|
-
<pre class="code"><span class="info file"># File 'lib/mocha/mock.rb', line 265</span>
|
927
|
-
|
928
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_responds_like_instance_of'>responds_like_instance_of</span><span class='lparen'>(</span><span class='id identifier rubyid_responder_class'>responder_class</span><span class='rparen'>)</span>
|
929
|
-
<span class='id identifier rubyid_responds_like'>responds_like</span><span class='lparen'>(</span><span class='id identifier rubyid_responder_class'>responder_class</span><span class='period'>.</span><span class='id identifier rubyid_allocate'>allocate</span><span class='rparen'>)</span>
|
930
|
-
<span class='kw'>end</span></pre>
|
931
|
-
</td>
|
932
|
-
</tr>
|
933
|
-
</table>
|
934
|
-
</div>
|
935
|
-
|
936
|
-
<div class="method_details ">
|
937
|
-
<h3 class="signature " id="stubs-instance_method">
|
938
|
-
|
939
|
-
|
940
|
-
<span class="overload">#<strong>stubs</strong>(method_name) ⇒ <tt><span class='object_link'><a href="Expectation.html" title="Mocha::Expectation (class)">Expectation</a></span></tt> </span>
|
941
|
-
|
942
|
-
<span class="overload">#<strong>stubs</strong>(stubbed_methods_vs_return_values) ⇒ <tt><span class='object_link'><a href="Expectation.html" title="Mocha::Expectation (class)">Expectation</a></span></tt> </span>
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
<span class="aliases">Also known as:
|
948
|
-
<span class="names"><span id='__stubs__-instance_method'>__stubs__</span></span>
|
949
|
-
</span>
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
</h3><div class="docstring">
|
954
|
-
<div class="discussion">
|
955
|
-
|
956
|
-
<p>Adds an expectation that the specified method may be called any number of times with any parameters.</p>
|
957
|
-
|
958
|
-
|
959
|
-
</div>
|
960
|
-
</div>
|
961
|
-
<div class="tags">
|
962
|
-
|
963
|
-
<div class="examples">
|
964
|
-
<p class="tag_title">Examples:</p>
|
965
|
-
|
966
|
-
|
967
|
-
<p class="example_title"><div class='inline'>
|
968
|
-
<p>No error raised however many times stubbed method is invoked</p>
|
969
|
-
</div></p>
|
970
|
-
|
971
|
-
<pre class="example code"><code><span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='rparen'>)</span>
|
972
|
-
<span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='symbol'>:stubbed_method</span><span class='rparen'>)</span>
|
973
|
-
<span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_stubbed_method'>stubbed_method</span>
|
974
|
-
<span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_stubbed_method'>stubbed_method</span>
|
975
|
-
<span class='comment'># no error raised</span></code></pre>
|
976
|
-
|
977
|
-
|
978
|
-
<p class="example_title"><div class='inline'>
|
979
|
-
<p>Setup multiple expectations using <code>stubbed_methods_vs_return_values</code>.</p>
|
980
|
-
</div></p>
|
981
|
-
|
982
|
-
<pre class="example code"><code><span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='rparen'>)</span>
|
983
|
-
<span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='symbol'>:stubbed_method_one</span> <span class='op'>=></span> <span class='symbol'>:result_one</span><span class='comma'>,</span> <span class='symbol'>:stubbed_method_two</span> <span class='op'>=></span> <span class='symbol'>:result_two</span><span class='rparen'>)</span>
|
984
|
-
|
985
|
-
<span class='comment'># is exactly equivalent to
|
986
|
-
</span>
|
987
|
-
<span class='id identifier rubyid_object'>object</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='rparen'>)</span>
|
988
|
-
<span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='symbol'>:stubbed_method_one</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_returns'>returns</span><span class='lparen'>(</span><span class='symbol'>:result_one</span><span class='rparen'>)</span>
|
989
|
-
<span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='symbol'>:stubbed_method_two</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_returns'>returns</span><span class='lparen'>(</span><span class='symbol'>:result_two</span><span class='rparen'>)</span></code></pre>
|
990
|
-
|
991
|
-
</div>
|
992
|
-
|
993
|
-
<p class="tag_title">Overloads:</p>
|
994
|
-
<ul class="overload">
|
995
|
-
|
996
|
-
|
997
|
-
<li class="overload_item">
|
998
|
-
<span class="signature">#<strong>stubs</strong>(method_name) ⇒ <tt><span class='object_link'><a href="Expectation.html" title="Mocha::Expectation (class)">Expectation</a></span></tt> </span>
|
999
|
-
<div class="docstring">
|
1000
|
-
<div class="discussion">
|
1001
|
-
|
1002
|
-
|
1003
|
-
</div>
|
1004
|
-
</div>
|
1005
|
-
<div class="tags">
|
1006
|
-
<p class="tag_title">Parameters:</p>
|
1007
|
-
<ul class="param">
|
1008
|
-
|
1009
|
-
<li>
|
1010
|
-
|
1011
|
-
<span class='name'>method_name</span>
|
1012
|
-
|
1013
|
-
|
1014
|
-
<span class='type'>(<tt>Symbol</tt>, <tt>String</tt>)</span>
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1018
|
-
—
|
1019
|
-
<div class='inline'>
|
1020
|
-
<p>name of stubbed method</p>
|
1021
|
-
</div>
|
1022
|
-
|
1023
|
-
</li>
|
1024
|
-
|
1025
|
-
</ul>
|
1026
|
-
|
1027
|
-
|
1028
|
-
</div>
|
1029
|
-
</li>
|
1030
|
-
|
1031
|
-
|
1032
|
-
<li class="overload_item">
|
1033
|
-
<span class="signature">#<strong>stubs</strong>(stubbed_methods_vs_return_values) ⇒ <tt><span class='object_link'><a href="Expectation.html" title="Mocha::Expectation (class)">Expectation</a></span></tt> </span>
|
1034
|
-
<div class="docstring">
|
1035
|
-
<div class="discussion">
|
1036
|
-
|
1037
|
-
|
1038
|
-
</div>
|
1039
|
-
</div>
|
1040
|
-
<div class="tags">
|
1041
|
-
<p class="tag_title">Parameters:</p>
|
1042
|
-
<ul class="param">
|
1043
|
-
|
1044
|
-
<li>
|
1045
|
-
|
1046
|
-
<span class='name'>stubbed_methods_vs_return_values</span>
|
1047
|
-
|
1048
|
-
|
1049
|
-
<span class='type'>(<tt>Hash</tt>)</span>
|
1050
|
-
|
1051
|
-
|
1052
|
-
|
1053
|
-
—
|
1054
|
-
<div class='inline'>
|
1055
|
-
<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="#stubs-instance_method" title="Mocha::Mock#stubs (method)">#stubs</a></span> were called multiple times.</p>
|
1056
|
-
</div>
|
1057
|
-
|
1058
|
-
</li>
|
1059
|
-
|
1060
|
-
</ul>
|
1061
|
-
|
1062
|
-
|
1063
|
-
</div>
|
1064
|
-
</li>
|
1065
|
-
|
1066
|
-
</ul>
|
1067
|
-
|
1068
|
-
<p class="tag_title">Returns:</p>
|
1069
|
-
<ul class="return">
|
1070
|
-
|
1071
|
-
<li>
|
1072
|
-
|
1073
|
-
|
1074
|
-
<span class='type'>(<tt><span class='object_link'><a href="Expectation.html" title="Mocha::Expectation (class)">Expectation</a></span></tt>)</span>
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
—
|
1079
|
-
<div class='inline'>
|
1080
|
-
<p>last-built expectation which can be further modified by methods on <span class='object_link'><a href="Expectation.html" title="Mocha::Expectation (class)">Expectation</a></span>.</p>
|
1081
|
-
</div>
|
1082
|
-
|
1083
|
-
</li>
|
1084
|
-
|
1085
|
-
</ul>
|
1086
|
-
|
1087
|
-
</div><table class="source_code">
|
1088
|
-
<tr>
|
1089
|
-
<td>
|
1090
|
-
<pre class="lines">
|
1091
|
-
|
1092
|
-
|
1093
|
-
147
|
1094
|
-
148
|
1095
|
-
149
|
1096
|
-
150
|
1097
|
-
151
|
1098
|
-
152
|
1099
|
-
153
|
1100
|
-
154
|
1101
|
-
155
|
1102
|
-
156
|
1103
|
-
157</pre>
|
1104
|
-
</td>
|
1105
|
-
<td>
|
1106
|
-
<pre class="code"><span class="info file"># File 'lib/mocha/mock.rb', line 147</span>
|
1107
|
-
|
1108
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='id identifier rubyid_method_name_or_hash'>method_name_or_hash</span><span class='comma'>,</span> <span class='id identifier rubyid_backtrace'>backtrace</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
1109
|
-
<span class='id identifier rubyid_iterator'>iterator</span> <span class='op'>=</span> <span class='const'>ArgumentIterator</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_method_name_or_hash'>method_name_or_hash</span><span class='rparen'>)</span>
|
1110
|
-
<span class='id identifier rubyid_iterator'>iterator</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='op'>|</span>
|
1111
|
-
<span class='id identifier rubyid_method_name'>method_name</span> <span class='op'>=</span> <span class='id identifier rubyid_args'>args</span><span class='period'>.</span><span class='id identifier rubyid_shift'>shift</span>
|
1112
|
-
<span class='id identifier rubyid_ensure_method_not_already_defined'>ensure_method_not_already_defined</span><span class='lparen'>(</span><span class='id identifier rubyid_method_name'>method_name</span><span class='rparen'>)</span>
|
1113
|
-
<span class='id identifier rubyid_expectation'>expectation</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="Expectation.html" title="Mocha::Expectation (class)">Expectation</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='kw'>self</span><span class='comma'>,</span> <span class='id identifier rubyid_method_name'>method_name</span><span class='comma'>,</span> <span class='id identifier rubyid_backtrace'>backtrace</span><span class='rparen'>)</span>
|
1114
|
-
<span class='id identifier rubyid_expectation'>expectation</span><span class='period'>.</span><span class='id identifier rubyid_at_least'>at_least</span><span class='lparen'>(</span><span class='int'>0</span><span class='rparen'>)</span>
|
1115
|
-
<span class='id identifier rubyid_expectation'>expectation</span><span class='period'>.</span><span class='id identifier rubyid_returns'>returns</span><span class='lparen'>(</span><span class='id identifier rubyid_args'>args</span><span class='period'>.</span><span class='id identifier rubyid_shift'>shift</span><span class='rparen'>)</span> <span class='kw'>unless</span> <span class='id identifier rubyid_args'>args</span><span class='period'>.</span><span class='id identifier rubyid_empty?'>empty?</span>
|
1116
|
-
<span class='ivar'>@expectations</span><span class='period'>.</span><span class='id identifier rubyid_add'>add</span><span class='lparen'>(</span><span class='id identifier rubyid_expectation'>expectation</span><span class='rparen'>)</span>
|
1117
|
-
<span class='kw'>end</span>
|
1118
|
-
<span class='kw'>end</span></pre>
|
1119
|
-
</td>
|
1120
|
-
</tr>
|
1121
|
-
</table>
|
1122
|
-
</div>
|
1123
|
-
|
1124
|
-
<div class="method_details ">
|
1125
|
-
<h3 class="signature " id="unstub-instance_method">
|
1126
|
-
|
1127
|
-
#<strong>unstub</strong>(*method_names) ⇒ <tt><span class='object_link'>Object</span></tt>
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
1131
|
-
|
1132
|
-
|
1133
|
-
</h3><div class="docstring">
|
1134
|
-
<div class="discussion">
|
1135
|
-
|
1136
|
-
<p>Removes the specified stubbed methods (added by calls to <span class='object_link'><a href="#expects-instance_method" title="Mocha::Mock#expects (method)">#expects</a></span> or <span class='object_link'><a href="#stubs-instance_method" title="Mocha::Mock#stubs (method)">#stubs</a></span>) and all expectations associated with them.</p>
|
1137
|
-
|
1138
|
-
|
1139
|
-
</div>
|
1140
|
-
</div>
|
1141
|
-
<div class="tags">
|
1142
|
-
|
1143
|
-
<div class="examples">
|
1144
|
-
<p class="tag_title">Examples:</p>
|
1145
|
-
|
1146
|
-
|
1147
|
-
<p class="example_title"><div class='inline'>
|
1148
|
-
<p>Invoking an unstubbed method causes error to be raised</p>
|
1149
|
-
</div></p>
|
1150
|
-
|
1151
|
-
<pre class="example code"><code>object = mock('mock') do
|
1152
|
-
object.stubs(:stubbed_method).returns(:result_one)
|
1153
|
-
object.stubbed_method # => :result_one
|
1154
|
-
object.unstub(:stubbed_method)
|
1155
|
-
object.stubbed_method # => unexpected invocation: #<Mock:mock>.stubbed_method()</code></pre>
|
1156
|
-
|
1157
|
-
|
1158
|
-
<p class="example_title"><div class='inline'>
|
1159
|
-
<p>Unstubbing multiple methods.</p>
|
1160
|
-
</div></p>
|
1161
|
-
|
1162
|
-
<pre class="example code"><code><span class='id identifier rubyid_multiplier'>multiplier</span><span class='period'>.</span><span class='id identifier rubyid_unstub'>unstub</span><span class='lparen'>(</span><span class='symbol'>:double</span><span class='comma'>,</span> <span class='symbol'>:triple</span><span class='rparen'>)</span>
|
1163
|
-
|
1164
|
-
<span class='comment'># exactly equivalent to
|
1165
|
-
</span>
|
1166
|
-
<span class='id identifier rubyid_multiplier'>multiplier</span><span class='period'>.</span><span class='id identifier rubyid_unstub'>unstub</span><span class='lparen'>(</span><span class='symbol'>:double</span><span class='rparen'>)</span>
|
1167
|
-
<span class='id identifier rubyid_multiplier'>multiplier</span><span class='period'>.</span><span class='id identifier rubyid_unstub'>unstub</span><span class='lparen'>(</span><span class='symbol'>:triple</span><span class='rparen'>)</span></code></pre>
|
1168
|
-
|
1169
|
-
</div>
|
1170
|
-
<p class="tag_title">Parameters:</p>
|
1171
|
-
<ul class="param">
|
1172
|
-
|
1173
|
-
<li>
|
1174
|
-
|
1175
|
-
<span class='name'>method_names</span>
|
1176
|
-
|
1177
|
-
|
1178
|
-
<span class='type'>(<tt>Array<Symbol></tt>)</span>
|
1179
|
-
|
1180
|
-
|
1181
|
-
|
1182
|
-
—
|
1183
|
-
<div class='inline'>
|
1184
|
-
<p>names of methods to unstub.</p>
|
1185
|
-
</div>
|
1186
|
-
|
1187
|
-
</li>
|
1188
|
-
|
1189
|
-
</ul>
|
1190
|
-
|
1191
|
-
|
1192
|
-
</div><table class="source_code">
|
1193
|
-
<tr>
|
1194
|
-
<td>
|
1195
|
-
<pre class="lines">
|
1196
|
-
|
1197
|
-
|
1198
|
-
177
|
1199
|
-
178
|
1200
|
-
179
|
1201
|
-
180
|
1202
|
-
181</pre>
|
1203
|
-
</td>
|
1204
|
-
<td>
|
1205
|
-
<pre class="code"><span class="info file"># File 'lib/mocha/mock.rb', line 177</span>
|
1206
|
-
|
1207
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_unstub'>unstub</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_method_names'>method_names</span><span class='rparen'>)</span>
|
1208
|
-
<span class='id identifier rubyid_method_names'>method_names</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_method_name'>method_name</span><span class='op'>|</span>
|
1209
|
-
<span class='ivar'>@expectations</span><span class='period'>.</span><span class='id identifier rubyid_remove_all_matching_method'>remove_all_matching_method</span><span class='lparen'>(</span><span class='id identifier rubyid_method_name'>method_name</span><span class='rparen'>)</span>
|
1210
|
-
<span class='kw'>end</span>
|
1211
|
-
<span class='kw'>end</span></pre>
|
1212
|
-
</td>
|
1213
|
-
</tr>
|
1214
|
-
</table>
|
1215
|
-
</div>
|
1216
|
-
|
1217
|
-
</div>
|
1218
|
-
|
1219
|
-
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-625523-7"></script>
|
1220
|
-
<script>
|
1221
|
-
window.dataLayer = window.dataLayer || [];
|
1222
|
-
function gtag(){dataLayer.push(arguments);}
|
1223
|
-
gtag('js', new Date());
|
1224
|
-
|
1225
|
-
gtag('config', 'UA-625523-7');
|
1226
|
-
</script>
|
1227
|
-
</div>
|
1228
|
-
|
1229
|
-
<div id="footer">
|
1230
|
-
Generated on Thu Dec 12 10:57:47 2019 by
|
1231
|
-
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
1232
|
-
0.9.20 (ruby-2.6.5).
|
1233
|
-
</div>
|
1234
|
-
|
1235
|
-
</div>
|
1236
|
-
</body>
|
1237
|
-
</html>
|