mocha 1.8.0 → 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/.rubocop.yml +3 -0
- data/.rubocop_todo.yml +7 -30
- data/.yardopts +1 -0
- data/CONTRIBUTING.md +1 -1
- data/README.md +56 -31
- data/RELEASE.md +166 -0
- data/Rakefile +15 -7
- data/init.rb +1 -3
- data/lib/mocha/any_instance_method.rb +11 -53
- data/lib/mocha/api.rb +119 -56
- data/lib/mocha/block_matcher.rb +31 -0
- data/lib/mocha/cardinality.rb +52 -34
- data/lib/mocha/class_methods.rb +17 -15
- data/lib/mocha/configuration.rb +351 -67
- data/lib/mocha/deprecation.rb +2 -1
- data/lib/mocha/detection/test_unit.rb +1 -3
- data/lib/mocha/exception_raiser.rb +2 -1
- data/lib/mocha/expectation.rb +120 -81
- data/lib/mocha/expectation_error.rb +1 -3
- data/lib/mocha/expectation_list.rb +6 -6
- data/lib/mocha/inspect.rb +30 -26
- data/lib/mocha/instance_method.rb +19 -2
- data/lib/mocha/integration/mini_test.rb +7 -0
- data/lib/mocha/integration/test_unit.rb +7 -0
- data/lib/mocha/integration.rb +1 -3
- data/lib/mocha/invocation.rb +77 -0
- data/lib/mocha/macos_version.rb +5 -0
- data/lib/mocha/minitest.rb +6 -1
- data/lib/mocha/mock.rb +80 -39
- data/lib/mocha/mockery.rb +34 -80
- data/lib/mocha/names.rb +1 -1
- data/lib/mocha/object_methods.rb +13 -19
- data/lib/mocha/parameter_matchers/all_of.rb +1 -1
- data/lib/mocha/parameter_matchers/any_of.rb +1 -1
- data/lib/mocha/parameter_matchers/equivalent_uri.rb +0 -9
- data/lib/mocha/parameter_matchers/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/includes.rb +2 -0
- data/lib/mocha/parameter_matchers/instance_methods.rb +18 -0
- data/lib/mocha/parameter_matchers/is_a.rb +2 -3
- data/lib/mocha/parameter_matchers/not.rb +2 -3
- data/lib/mocha/parameter_matchers.rb +2 -1
- data/lib/mocha/raised_exception.rb +11 -0
- data/lib/mocha/return_values.rb +3 -3
- data/lib/mocha/setup.rb +5 -0
- data/lib/mocha/single_return_value.rb +2 -1
- data/lib/mocha/singleton_class.rb +9 -0
- data/lib/mocha/state_machine.rb +31 -40
- data/lib/mocha/stubbed_method.rb +125 -0
- data/lib/mocha/test_unit.rb +6 -1
- data/lib/mocha/thrower.rb +2 -1
- data/lib/mocha/thrown_object.rb +12 -0
- data/lib/mocha/version.rb +1 -1
- data/lib/mocha/yield_parameters.rb +5 -11
- data/lib/mocha.rb +8 -0
- data/mocha.gemspec +14 -10
- metadata +16 -233
- data/bin/build-matrix +0 -83
- data/docs/CNAME +0 -1
- data/docs/Mocha/API.html +0 -1056
- data/docs/Mocha/ClassMethods.html +0 -267
- data/docs/Mocha/Configuration.html +0 -626
- data/docs/Mocha/Expectation.html +0 -2709
- data/docs/Mocha/ExpectationError.html +0 -157
- data/docs/Mocha/ExpectationErrorFactory.html +0 -269
- data/docs/Mocha/Hooks.html +0 -385
- data/docs/Mocha/Integration/MiniTest/Adapter.html +0 -165
- data/docs/Mocha/Integration/MiniTest.html +0 -123
- data/docs/Mocha/Integration/TestUnit/Adapter.html +0 -165
- data/docs/Mocha/Integration/TestUnit.html +0 -123
- data/docs/Mocha/Integration.html +0 -125
- data/docs/Mocha/Mock.html +0 -1197
- data/docs/Mocha/ObjectMethods.html +0 -712
- data/docs/Mocha/ParameterMatchers/AllOf.html +0 -154
- data/docs/Mocha/ParameterMatchers/AnyOf.html +0 -154
- data/docs/Mocha/ParameterMatchers/AnyParameters.html +0 -153
- data/docs/Mocha/ParameterMatchers/Anything.html +0 -153
- data/docs/Mocha/ParameterMatchers/Base.html +0 -448
- data/docs/Mocha/ParameterMatchers/Equals.html +0 -154
- data/docs/Mocha/ParameterMatchers/EquivalentUri.html +0 -153
- data/docs/Mocha/ParameterMatchers/HasEntries.html +0 -154
- data/docs/Mocha/ParameterMatchers/HasEntry.html +0 -154
- data/docs/Mocha/ParameterMatchers/HasKey.html +0 -154
- data/docs/Mocha/ParameterMatchers/HasValue.html +0 -154
- data/docs/Mocha/ParameterMatchers/Includes.html +0 -154
- data/docs/Mocha/ParameterMatchers/InstanceOf.html +0 -154
- data/docs/Mocha/ParameterMatchers/IsA.html +0 -153
- data/docs/Mocha/ParameterMatchers/KindOf.html +0 -154
- data/docs/Mocha/ParameterMatchers/Not.html +0 -154
- data/docs/Mocha/ParameterMatchers/Optionally.html +0 -153
- data/docs/Mocha/ParameterMatchers/RegexpMatches.html +0 -154
- data/docs/Mocha/ParameterMatchers/RespondsWith.html +0 -154
- data/docs/Mocha/ParameterMatchers/YamlEquivalent.html +0 -154
- data/docs/Mocha/ParameterMatchers.html +0 -3049
- data/docs/Mocha/Sequence.html +0 -149
- data/docs/Mocha/StateMachine/State.html +0 -141
- data/docs/Mocha/StateMachine/StatePredicate.html +0 -141
- data/docs/Mocha/StateMachine.html +0 -539
- data/docs/Mocha/StubbingError.html +0 -150
- data/docs/Mocha/UnexpectedInvocation.html +0 -140
- data/docs/Mocha.html +0 -127
- data/docs/_index.html +0 -537
- 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 -418
- data/docs/file.RELEASE.html +0 -875
- data/docs/file_list.html +0 -71
- data/docs/frames.html +0 -17
- data/docs/index.html +0 -418
- data/docs/js/app.js +0 -292
- data/docs/js/full_list.js +0 -216
- data/docs/js/jquery.js +0 -4
- data/docs/method_list.html +0 -571
- 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.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/class_method.rb +0 -113
- data/lib/mocha/mini_test.rb +0 -5
- data/lib/mocha/module_method.rb +0 -6
- data/lib/mocha/module_methods.rb +0 -10
- data/lib/mocha/multiple_yields.rb +0 -15
- data/lib/mocha/no_yields.rb +0 -5
- data/lib/mocha/parameter_matchers/object.rb +0 -15
- data/lib/mocha/pretty_parameters.rb +0 -24
- data/lib/mocha/single_yield.rb +0 -13
- data/lib/mocha/standalone.rb +0 -4
- data/lib/mocha/unexpected_invocation.rb +0 -24
- data/lib/mocha_standalone.rb +0 -4
- data/test/acceptance/acceptance_test_helper.rb +0 -35
- data/test/acceptance/bug_18914_test.rb +0 -38
- data/test/acceptance/bug_21465_test.rb +0 -32
- data/test/acceptance/bug_21563_test.rb +0 -23
- data/test/acceptance/exception_rescue_test.rb +0 -54
- data/test/acceptance/expectations_on_multiple_methods_test.rb +0 -56
- data/test/acceptance/expected_invocation_count_test.rb +0 -230
- data/test/acceptance/failure_messages_test.rb +0 -62
- data/test/acceptance/issue_272_test.rb +0 -51
- data/test/acceptance/issue_65_test.rb +0 -65
- data/test/acceptance/issue_70_test.rb +0 -54
- data/test/acceptance/mocha_example_test.rb +0 -97
- data/test/acceptance/mocha_test_result_test.rb +0 -84
- data/test/acceptance/mock_test.rb +0 -98
- data/test/acceptance/mock_with_initializer_block_test.rb +0 -56
- data/test/acceptance/mocked_methods_dispatch_test.rb +0 -76
- data/test/acceptance/multiple_expectations_failure_message_test.rb +0 -67
- data/test/acceptance/optional_parameters_test.rb +0 -68
- data/test/acceptance/parameter_matcher_test.rb +0 -300
- data/test/acceptance/partial_mocks_test.rb +0 -45
- data/test/acceptance/prepend_test.rb +0 -87
- data/test/acceptance/prevent_use_of_mocha_outside_test_test.rb +0 -77
- data/test/acceptance/raise_exception_test.rb +0 -37
- data/test/acceptance/return_value_test.rb +0 -50
- data/test/acceptance/sequence_test.rb +0 -190
- data/test/acceptance/states_test.rb +0 -72
- data/test/acceptance/stub_any_instance_method_defined_on_superclass_test.rb +0 -65
- data/test/acceptance/stub_any_instance_method_test.rb +0 -282
- data/test/acceptance/stub_class_method_defined_on_active_record_association_proxy_test.rb +0 -106
- data/test/acceptance/stub_class_method_defined_on_class_test.rb +0 -79
- data/test/acceptance/stub_class_method_defined_on_module_test.rb +0 -74
- data/test/acceptance/stub_class_method_defined_on_superclass_test.rb +0 -145
- data/test/acceptance/stub_everything_test.rb +0 -54
- data/test/acceptance/stub_instance_method_defined_on_active_record_association_proxy_test.rb +0 -92
- data/test/acceptance/stub_instance_method_defined_on_class_and_aliased_test.rb +0 -68
- data/test/acceptance/stub_instance_method_defined_on_class_test.rb +0 -68
- data/test/acceptance/stub_instance_method_defined_on_kernel_module_test.rb +0 -137
- data/test/acceptance/stub_instance_method_defined_on_module_test.rb +0 -77
- data/test/acceptance/stub_instance_method_defined_on_object_class_test.rb +0 -76
- data/test/acceptance/stub_instance_method_defined_on_singleton_class_test.rb +0 -68
- data/test/acceptance/stub_instance_method_defined_on_superclass_test.rb +0 -71
- data/test/acceptance/stub_method_defined_on_module_and_aliased_test.rb +0 -39
- data/test/acceptance/stub_module_method_test.rb +0 -201
- data/test/acceptance/stub_test.rb +0 -50
- data/test/acceptance/stubba_example_test.rb +0 -94
- data/test/acceptance/stubba_test_result_test.rb +0 -72
- data/test/acceptance/stubbing_error_backtrace_test.rb +0 -64
- data/test/acceptance/stubbing_frozen_object_test.rb +0 -89
- data/test/acceptance/stubbing_method_accepting_block_parameter_test.rb +0 -53
- 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 -141
- 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 -34
- data/test/acceptance/throw_test.rb +0 -43
- data/test/acceptance/unexpected_invocation_test.rb +0 -24
- data/test/acceptance/unstubbing_test.rb +0 -195
- 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 -176
- data/test/integration/test_unit_test.rb +0 -8
- data/test/method_definer.rb +0 -22
- 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 -56
- data/test/test_unit_result.rb +0 -22
- data/test/unit/any_instance_method_test.rb +0 -150
- 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 -54
- data/test/unit/central_test.rb +0 -99
- data/test/unit/change_state_side_effect_test.rb +0 -37
- data/test/unit/class_method_test.rb +0 -254
- 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 -40
- data/test/unit/expectation_list_test.rb +0 -80
- 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/method_matcher_test.rb +0 -26
- data/test/unit/mock_test.rb +0 -363
- data/test/unit/mockery_test.rb +0 -174
- data/test/unit/module_methods_test.rb +0 -17
- 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 -58
- data/test/unit/object_methods_test.rb +0 -62
- 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 -50
- 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 -61
- data/test/unit/sequence_test.rb +0 -100
- data/test/unit/single_return_value_test.rb +0 -12
- 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 -18
- data/test/unit/yield_parameters_test.rb +0 -91
data/docs/Mocha/Mock.html
DELETED
@@ -1,1197 +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.8.0
|
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>All methods return an <span class='object_link'><a href="Expectation.html" title="Mocha::Expectation (class)">Expectation</a></span> which can be further modified by
|
108
|
-
methods on <span class='object_link'><a href="Expectation.html" title="Mocha::Expectation (class)">Expectation</a></span>.</p>
|
109
|
-
|
110
|
-
<p>Stubs and expectations are basically the same thing. A stub is just an
|
111
|
-
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
|
112
|
-
sugar to make the intent of the test more explicit.</p>
|
113
|
-
|
114
|
-
<p>When a method is invoked on a mock object, the mock object searches through
|
115
|
-
its expectations from newest to oldest to find one that matches the
|
116
|
-
invocation. After the invocation, the matching expectation might stop
|
117
|
-
matching further invocations. For example, an <tt>expects(:foo).once</tt>
|
118
|
-
expectation only matches once and will be ignored on future invocations
|
119
|
-
while an <tt>expects(:foo).at_least_once</tt> expectation will always be matched
|
120
|
-
against invocations.</p>
|
121
|
-
|
122
|
-
<p>This scheme allows you to:</p>
|
123
|
-
<ul><li>
|
124
|
-
<p>Set up default stubs in your the <code>setup</code> method of your test
|
125
|
-
class and override some of those stubs in individual tests.</p>
|
126
|
-
</li><li>
|
127
|
-
<p>Set up different <code>once</code> expectations for the same method with
|
128
|
-
different action per invocation. However, it's better to use the
|
129
|
-
<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
|
130
|
-
described below.</p>
|
131
|
-
</li></ul>
|
132
|
-
|
133
|
-
<p>However, there are some possible “gotchas” caused by this scheme:</p>
|
134
|
-
<ul><li>
|
135
|
-
<p>if you create an expectation and then a stub for the same method, the stub
|
136
|
-
will always override the expectation and the expectation will never be met.</p>
|
137
|
-
</li><li>
|
138
|
-
<p>if you create a stub and then an expectation for the same method, the
|
139
|
-
expectation will match, and when it stops matching the stub will be used
|
140
|
-
instead, possibly masking test failures.</p>
|
141
|
-
</li><li>
|
142
|
-
<p>if you create different expectations for the same method, they will be
|
143
|
-
invoked in the opposite order than that in which they were specified,
|
144
|
-
rather than the same order.</p>
|
145
|
-
</li></ul>
|
146
|
-
|
147
|
-
<p>The best thing to do is not set up multiple expectations and stubs for the
|
148
|
-
same method with exactly the same matchers. Instead, use the
|
149
|
-
<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
|
150
|
-
actions for a method. You can also chain multiple calls to
|
151
|
-
<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
|
152
|
-
<span class='object_link'><a href="Expectation.html#then-instance_method" title="Mocha::Expectation#then (method)">Expectation#then</a></span> if desired).</p>
|
153
|
-
|
154
|
-
<p>If you want to specify more complex ordering or order invocations across
|
155
|
-
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
|
156
|
-
explicitly define a total or partial ordering of invocations.</p>
|
157
|
-
|
158
|
-
|
159
|
-
</div>
|
160
|
-
</div>
|
161
|
-
<div class="tags">
|
162
|
-
|
163
|
-
<div class="examples">
|
164
|
-
<p class="tag_title">Examples:</p>
|
165
|
-
|
166
|
-
|
167
|
-
<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>
|
168
|
-
<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>
|
169
|
-
<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
|
170
|
-
</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
|
171
|
-
</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>
|
172
|
-
|
173
|
-
</div>
|
174
|
-
|
175
|
-
|
176
|
-
</div>
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
<h2>
|
185
|
-
Instance Method Summary
|
186
|
-
<small><a href="#" class="summary_toggle">collapse</a></small>
|
187
|
-
</h2>
|
188
|
-
|
189
|
-
<ul class="summary">
|
190
|
-
|
191
|
-
<li class="public ">
|
192
|
-
<span class="summary_signature">
|
193
|
-
|
194
|
-
<a href="#expects-instance_method" title="#expects (instance method)">#<strong>expects</strong>(method_name_or_hash, backtrace = nil) ⇒ Expectation </a>
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
(also: #__expects__)
|
199
|
-
|
200
|
-
</span>
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
<span class="summary_desc"><div class='inline'>
|
211
|
-
<p>Adds an expectation that the specified method must be called exactly once
|
212
|
-
with any parameters.</p>
|
213
|
-
</div></span>
|
214
|
-
|
215
|
-
</li>
|
216
|
-
|
217
|
-
|
218
|
-
<li class="public ">
|
219
|
-
<span class="summary_signature">
|
220
|
-
|
221
|
-
<a href="#respond_to%3F-instance_method" title="#respond_to? (instance method)">#<strong>respond_to?</strong>(symbol, include_private = false) ⇒ Boolean </a>
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
</span>
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
<span class="summary_desc"><div class='inline'></div></span>
|
236
|
-
|
237
|
-
</li>
|
238
|
-
|
239
|
-
|
240
|
-
<li class="public ">
|
241
|
-
<span class="summary_signature">
|
242
|
-
|
243
|
-
<a href="#responds_like-instance_method" title="#responds_like (instance method)">#<strong>responds_like</strong>(responder) ⇒ Mock </a>
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
(also: #quacks_like)
|
248
|
-
|
249
|
-
</span>
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
<span class="summary_desc"><div class='inline'>
|
260
|
-
<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
|
261
|
-
to which <code>responder</code> responds.</p>
|
262
|
-
</div></span>
|
263
|
-
|
264
|
-
</li>
|
265
|
-
|
266
|
-
|
267
|
-
<li class="public ">
|
268
|
-
<span class="summary_signature">
|
269
|
-
|
270
|
-
<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>
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
(also: #quacks_like_instance_of)
|
275
|
-
|
276
|
-
</span>
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
<span class="summary_desc"><div class='inline'>
|
287
|
-
<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
|
288
|
-
to which an instance of the <code>responder_class</code> responds.</p>
|
289
|
-
</div></span>
|
290
|
-
|
291
|
-
</li>
|
292
|
-
|
293
|
-
|
294
|
-
<li class="public ">
|
295
|
-
<span class="summary_signature">
|
296
|
-
|
297
|
-
<a href="#stubs-instance_method" title="#stubs (instance method)">#<strong>stubs</strong>(method_name_or_hash, backtrace = nil) ⇒ Expectation </a>
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
(also: #__stubs__)
|
302
|
-
|
303
|
-
</span>
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
<span class="summary_desc"><div class='inline'>
|
314
|
-
<p>Adds an expectation that the specified method may be called any number of
|
315
|
-
times with any parameters.</p>
|
316
|
-
</div></span>
|
317
|
-
|
318
|
-
</li>
|
319
|
-
|
320
|
-
|
321
|
-
<li class="public ">
|
322
|
-
<span class="summary_signature">
|
323
|
-
|
324
|
-
<a href="#unstub-instance_method" title="#unstub (instance method)">#<strong>unstub</strong>(method_name) ⇒ Object </a>
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
</span>
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
<span class="summary_desc"><div class='inline'>
|
339
|
-
<p>Removes the specified stubbed method (added by calls to <span class='object_link'><a href="#expects-instance_method" title="Mocha::Mock#expects (method)">#expects</a></span> or
|
340
|
-
<span class='object_link'><a href="#stubs-instance_method" title="Mocha::Mock#stubs (method)">#stubs</a></span>) and all expectations associated with it.</p>
|
341
|
-
</div></span>
|
342
|
-
|
343
|
-
</li>
|
344
|
-
|
345
|
-
|
346
|
-
</ul>
|
347
|
-
|
348
|
-
|
349
|
-
<div id="method_missing_details" class="method_details_list">
|
350
|
-
<h2>Dynamic Method Handling</h2>
|
351
|
-
<p class="notice this">
|
352
|
-
This class handles dynamic methods through the <tt>method_missing</tt> method
|
353
|
-
|
354
|
-
</p>
|
355
|
-
|
356
|
-
<div class="method_details first">
|
357
|
-
<h3 class="signature first" id="method_missing-instance_method">
|
358
|
-
|
359
|
-
#<strong>method_missing</strong>(symbol, *arguments, &block) ⇒ <tt><span class='object_link'>Object</span></tt>
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
</h3><div class="docstring">
|
366
|
-
<div class="discussion">
|
367
|
-
|
368
|
-
<p>rubocop:disable Style/MethodMissingSuper</p>
|
369
|
-
|
370
|
-
|
371
|
-
</div>
|
372
|
-
</div>
|
373
|
-
<div class="tags">
|
374
|
-
|
375
|
-
|
376
|
-
</div><table class="source_code">
|
377
|
-
<tr>
|
378
|
-
<td>
|
379
|
-
<pre class="lines">
|
380
|
-
|
381
|
-
|
382
|
-
294
|
383
|
-
295
|
384
|
-
296
|
385
|
-
297
|
386
|
-
298
|
387
|
-
299
|
388
|
-
300
|
389
|
-
301
|
390
|
-
302
|
391
|
-
303
|
392
|
-
304
|
393
|
-
305
|
394
|
-
306
|
395
|
-
307
|
396
|
-
308
|
397
|
-
309
|
398
|
-
310
|
399
|
-
311</pre>
|
400
|
-
</td>
|
401
|
-
<td>
|
402
|
-
<pre class="code"><span class="info file"># File 'lib/mocha/mock.rb', line 294</span>
|
403
|
-
|
404
|
-
<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>
|
405
|
-
<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>
|
406
|
-
<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>
|
407
|
-
<span class='kw'>end</span>
|
408
|
-
<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_symbol'>symbol</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_arguments'>arguments</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
409
|
-
<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='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
410
|
-
<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_symbol'>symbol</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_arguments'>arguments</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>
|
411
|
-
<span class='kw'>if</span> <span class='ivar'>@unexpected_invocation</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
|
412
|
-
<span class='ivar'>@unexpected_invocation</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="UnexpectedInvocation.html" title="Mocha::UnexpectedInvocation (class)">UnexpectedInvocation</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_symbol'>symbol</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_arguments'>arguments</span><span class='rparen'>)</span>
|
413
|
-
<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='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_matching_expectation'>matching_expectation</span>
|
414
|
-
<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_full_description'>full_description</span>
|
415
|
-
<span class='id identifier rubyid_message'>message</span> <span class='op'><<</span> <span class='ivar'>@mockery</span><span class='period'>.</span><span class='id identifier rubyid_mocha_inspect'>mocha_inspect</span>
|
416
|
-
<span class='kw'>else</span>
|
417
|
-
<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_description'>short_description</span>
|
418
|
-
<span class='kw'>end</span>
|
419
|
-
<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='id identifier rubyid_message'>message</span><span class='comma'>,</span> <span class='id identifier rubyid_caller'>caller</span><span class='rparen'>)</span>
|
420
|
-
<span class='kw'>end</span>
|
421
|
-
<span class='kw'>end</span></pre>
|
422
|
-
</td>
|
423
|
-
</tr>
|
424
|
-
</table>
|
425
|
-
</div>
|
426
|
-
|
427
|
-
</div>
|
428
|
-
|
429
|
-
|
430
|
-
<div id="instance_method_details" class="method_details_list">
|
431
|
-
<h2>Instance Method Details</h2>
|
432
|
-
|
433
|
-
|
434
|
-
<div class="method_details first">
|
435
|
-
<h3 class="signature first" id="expects-instance_method">
|
436
|
-
|
437
|
-
|
438
|
-
<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>
|
439
|
-
|
440
|
-
<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>
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
<span class="aliases">Also known as:
|
446
|
-
<span class="names"><span id='__expects__-instance_method'>__expects__</span></span>
|
447
|
-
</span>
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
</h3><div class="docstring">
|
452
|
-
<div class="discussion">
|
453
|
-
|
454
|
-
<p>Adds an expectation that the specified method must be called exactly once
|
455
|
-
with any parameters.</p>
|
456
|
-
|
457
|
-
|
458
|
-
</div>
|
459
|
-
</div>
|
460
|
-
<div class="tags">
|
461
|
-
|
462
|
-
<div class="examples">
|
463
|
-
<p class="tag_title">Examples:</p>
|
464
|
-
|
465
|
-
|
466
|
-
<p class="example_title"><div class='inline'>
|
467
|
-
<p>Expected method invoked once so no error raised</p>
|
468
|
-
</div></p>
|
469
|
-
|
470
|
-
<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>
|
471
|
-
<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>
|
472
|
-
<span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span></code></pre>
|
473
|
-
|
474
|
-
|
475
|
-
<p class="example_title"><div class='inline'>
|
476
|
-
<p>Expected method not invoked so error raised</p>
|
477
|
-
</div></p>
|
478
|
-
|
479
|
-
<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>
|
480
|
-
<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>
|
481
|
-
<span class='comment'># error raised when test completes, because expected_method not called exactly once</span></code></pre>
|
482
|
-
|
483
|
-
|
484
|
-
<p class="example_title"><div class='inline'>
|
485
|
-
<p>Expected method invoked twice so error raised</p>
|
486
|
-
</div></p>
|
487
|
-
|
488
|
-
<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>
|
489
|
-
<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>
|
490
|
-
<span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_expected_method'>expected_method</span>
|
491
|
-
<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>
|
492
|
-
|
493
|
-
|
494
|
-
<p class="example_title"><div class='inline'>
|
495
|
-
<p>Setup multiple expectations using
|
496
|
-
<code>expected_methods_vs_return_values</code>.</p>
|
497
|
-
</div></p>
|
498
|
-
|
499
|
-
<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>
|
500
|
-
<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>
|
501
|
-
|
502
|
-
<span class='comment'># is exactly equivalent to
|
503
|
-
</span>
|
504
|
-
<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>
|
505
|
-
<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>
|
506
|
-
<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>
|
507
|
-
|
508
|
-
</div>
|
509
|
-
<p class="tag_title">Parameters:</p>
|
510
|
-
<ul class="param">
|
511
|
-
|
512
|
-
<li>
|
513
|
-
|
514
|
-
<span class='name'>method_name</span>
|
515
|
-
|
516
|
-
|
517
|
-
<span class='type'>(<tt>Symbol</tt>, <tt>String</tt>)</span>
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
—
|
522
|
-
<div class='inline'>
|
523
|
-
<p>name of expected method</p>
|
524
|
-
</div>
|
525
|
-
|
526
|
-
</li>
|
527
|
-
|
528
|
-
<li>
|
529
|
-
|
530
|
-
<span class='name'>expected_methods_vs_return_values</span>
|
531
|
-
|
532
|
-
|
533
|
-
<span class='type'>(<tt>Hash</tt>)</span>
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
—
|
538
|
-
<div class='inline'>
|
539
|
-
<p>expected method name symbols as keys and corresponding return values as
|
540
|
-
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
|
541
|
-
times.</p>
|
542
|
-
</div>
|
543
|
-
|
544
|
-
</li>
|
545
|
-
|
546
|
-
</ul>
|
547
|
-
|
548
|
-
<p class="tag_title">Returns:</p>
|
549
|
-
<ul class="return">
|
550
|
-
|
551
|
-
<li>
|
552
|
-
|
553
|
-
|
554
|
-
<span class='type'>(<tt><span class='object_link'><a href="Expectation.html" title="Mocha::Expectation (class)">Expectation</a></span></tt>)</span>
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
—
|
559
|
-
<div class='inline'>
|
560
|
-
<p>last-built expectation which can be further modified by methods on
|
561
|
-
<span class='object_link'><a href="Expectation.html" title="Mocha::Expectation (class)">Expectation</a></span>.</p>
|
562
|
-
</div>
|
563
|
-
|
564
|
-
</li>
|
565
|
-
|
566
|
-
</ul>
|
567
|
-
|
568
|
-
</div><table class="source_code">
|
569
|
-
<tr>
|
570
|
-
<td>
|
571
|
-
<pre class="lines">
|
572
|
-
|
573
|
-
|
574
|
-
105
|
575
|
-
106
|
576
|
-
107
|
577
|
-
108
|
578
|
-
109
|
579
|
-
110
|
580
|
-
111
|
581
|
-
112
|
582
|
-
113
|
583
|
-
114</pre>
|
584
|
-
</td>
|
585
|
-
<td>
|
586
|
-
<pre class="code"><span class="info file"># File 'lib/mocha/mock.rb', line 105</span>
|
587
|
-
|
588
|
-
<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>
|
589
|
-
<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>
|
590
|
-
<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>
|
591
|
-
<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>
|
592
|
-
<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>
|
593
|
-
<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>
|
594
|
-
<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>
|
595
|
-
<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>
|
596
|
-
<span class='kw'>end</span>
|
597
|
-
<span class='kw'>end</span></pre>
|
598
|
-
</td>
|
599
|
-
</tr>
|
600
|
-
</table>
|
601
|
-
</div>
|
602
|
-
|
603
|
-
<div class="method_details ">
|
604
|
-
<h3 class="signature " id="respond_to?-instance_method">
|
605
|
-
|
606
|
-
#<strong>respond_to?</strong>(symbol, include_private = false) ⇒ <tt>Boolean</tt>
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
</h3><div class="docstring">
|
613
|
-
<div class="discussion">
|
614
|
-
|
615
|
-
|
616
|
-
</div>
|
617
|
-
</div>
|
618
|
-
<div class="tags">
|
619
|
-
|
620
|
-
<p class="tag_title">Returns:</p>
|
621
|
-
<ul class="return">
|
622
|
-
|
623
|
-
<li>
|
624
|
-
|
625
|
-
|
626
|
-
<span class='type'>(<tt>Boolean</tt>)</span>
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
</li>
|
631
|
-
|
632
|
-
</ul>
|
633
|
-
|
634
|
-
</div><table class="source_code">
|
635
|
-
<tr>
|
636
|
-
<td>
|
637
|
-
<pre class="lines">
|
638
|
-
|
639
|
-
|
640
|
-
329
|
641
|
-
330
|
642
|
-
331</pre>
|
643
|
-
</td>
|
644
|
-
<td>
|
645
|
-
<pre class="code"><span class="info file"># File 'lib/mocha/mock.rb', line 329</span>
|
646
|
-
|
647
|
-
<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>
|
648
|
-
<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>
|
649
|
-
<span class='kw'>end</span></pre>
|
650
|
-
</td>
|
651
|
-
</tr>
|
652
|
-
</table>
|
653
|
-
</div>
|
654
|
-
|
655
|
-
<div class="method_details ">
|
656
|
-
<h3 class="signature " id="responds_like-instance_method">
|
657
|
-
|
658
|
-
#<strong>responds_like</strong>(responder) ⇒ <tt><span class='object_link'><a href="" title="Mocha::Mock (class)">Mock</a></span></tt>
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
<span class="aliases">Also known as:
|
663
|
-
<span class="names"><span id='quacks_like-instance_method'>quacks_like</span></span>
|
664
|
-
</span>
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
</h3><div class="docstring">
|
669
|
-
<div class="discussion">
|
670
|
-
|
671
|
-
<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
|
672
|
-
to which <code>responder</code> responds. The constraint is only applied at
|
673
|
-
method invocation time.</p>
|
674
|
-
|
675
|
-
<p>A <code>NoMethodError</code> will be raised if the <code>responder</code>
|
676
|
-
does not <code>#respond_to?</code> a method invocation (even if the method
|
677
|
-
has been expected or stubbed).</p>
|
678
|
-
|
679
|
-
<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
|
680
|
-
the <code>responder</code>.</p>
|
681
|
-
|
682
|
-
<p>Note that the methods on <code>responder</code> are never actually invoked.</p>
|
683
|
-
|
684
|
-
|
685
|
-
</div>
|
686
|
-
</div>
|
687
|
-
<div class="tags">
|
688
|
-
|
689
|
-
<div class="examples">
|
690
|
-
<p class="tag_title">Examples:</p>
|
691
|
-
|
692
|
-
|
693
|
-
<p class="example_title"><div class='inline'>
|
694
|
-
<p>Normal mocking</p>
|
695
|
-
</div></p>
|
696
|
-
|
697
|
-
<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>
|
698
|
-
<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>
|
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'>:foo</span><span class='rparen'>)</span>
|
700
|
-
<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
|
701
|
-
</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
|
702
|
-
</span><span class='id identifier rubyid_sheep'>sheep</span><span class='period'>.</span><span class='id identifier rubyid_chew'>chew</span>
|
703
|
-
<span class='id identifier rubyid_sheep'>sheep</span><span class='period'>.</span><span class='id identifier rubyid_foo'>foo</span>
|
704
|
-
<span class='comment'># no error raised</span></code></pre>
|
705
|
-
|
706
|
-
|
707
|
-
<p class="example_title"><div class='inline'>
|
708
|
-
<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>
|
709
|
-
</div></p>
|
710
|
-
|
711
|
-
<pre class="example code"><code><span class='kw'>class</span> <span class='const'>Sheep</span>
|
712
|
-
<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>
|
713
|
-
<span class='kw'>end</span>
|
714
|
-
|
715
|
-
<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>
|
716
|
-
<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>
|
717
|
-
<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>
|
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'>:foo</span><span class='rparen'>)</span>
|
719
|
-
<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
|
720
|
-
</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
|
721
|
-
</span><span class='id identifier rubyid_sheep'>sheep</span><span class='period'>.</span><span class='id identifier rubyid_chew'>chew</span>
|
722
|
-
<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>
|
723
|
-
|
724
|
-
|
725
|
-
<p class="example_title"><div class='inline'>
|
726
|
-
<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>
|
727
|
-
</div></p>
|
728
|
-
|
729
|
-
<pre class="example code"><code><span class='kw'>class</span> <span class='const'>Sheep</span>
|
730
|
-
<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>
|
731
|
-
<span class='kw'>end</span>
|
732
|
-
|
733
|
-
<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>
|
734
|
-
<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>
|
735
|
-
<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>
|
736
|
-
<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>
|
737
|
-
<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
|
738
|
-
</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
|
739
|
-
</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
|
740
|
-
</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>
|
741
|
-
|
742
|
-
</div>
|
743
|
-
<p class="tag_title">Parameters:</p>
|
744
|
-
<ul class="param">
|
745
|
-
|
746
|
-
<li>
|
747
|
-
|
748
|
-
<span class='name'>responder</span>
|
749
|
-
|
750
|
-
|
751
|
-
<span class='type'>(<tt><span class='object_link'>Object</span></tt>, <tt>#respond_to?</tt>)</span>
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
—
|
756
|
-
<div class='inline'>
|
757
|
-
<p>an object used to determine whether <span class='object_link'><a href="" title="Mocha::Mock (class)">Mocha::Mock</a></span> instance should
|
758
|
-
<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>
|
778
|
-
methods to be chained.</p>
|
779
|
-
</div>
|
780
|
-
|
781
|
-
</li>
|
782
|
-
|
783
|
-
</ul>
|
784
|
-
|
785
|
-
<p class="tag_title">See Also:</p>
|
786
|
-
<ul class="see">
|
787
|
-
|
788
|
-
<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>
|
789
|
-
|
790
|
-
</ul>
|
791
|
-
|
792
|
-
</div><table class="source_code">
|
793
|
-
<tr>
|
794
|
-
<td>
|
795
|
-
<pre class="lines">
|
796
|
-
|
797
|
-
|
798
|
-
216
|
799
|
-
217
|
800
|
-
218
|
801
|
-
219</pre>
|
802
|
-
</td>
|
803
|
-
<td>
|
804
|
-
<pre class="code"><span class="info file"># File 'lib/mocha/mock.rb', line 216</span>
|
805
|
-
|
806
|
-
<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>
|
807
|
-
<span class='ivar'>@responder</span> <span class='op'>=</span> <span class='id identifier rubyid_responder'>responder</span>
|
808
|
-
<span class='kw'>self</span>
|
809
|
-
<span class='kw'>end</span></pre>
|
810
|
-
</td>
|
811
|
-
</tr>
|
812
|
-
</table>
|
813
|
-
</div>
|
814
|
-
|
815
|
-
<div class="method_details ">
|
816
|
-
<h3 class="signature " id="responds_like_instance_of-instance_method">
|
817
|
-
|
818
|
-
#<strong>responds_like_instance_of</strong>(responder_class) ⇒ <tt><span class='object_link'><a href="" title="Mocha::Mock (class)">Mock</a></span></tt>
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
<span class="aliases">Also known as:
|
823
|
-
<span class="names"><span id='quacks_like_instance_of-instance_method'>quacks_like_instance_of</span></span>
|
824
|
-
</span>
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
</h3><div class="docstring">
|
829
|
-
<div class="discussion">
|
830
|
-
|
831
|
-
<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
|
832
|
-
to which an instance of the <code>responder_class</code> responds. The
|
833
|
-
constraint is only applied at method invocation time. Note that the
|
834
|
-
responder instance is instantiated using <tt>Class#allocate</tt>.</p>
|
835
|
-
|
836
|
-
<p>A <code>NoMethodError</code> will be raised if the responder instance does
|
837
|
-
not <code>#respond_to?</code> a method invocation (even if the method has
|
838
|
-
been expected or stubbed).</p>
|
839
|
-
|
840
|
-
<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
|
841
|
-
the responder instance.</p>
|
842
|
-
|
843
|
-
<p>Note that the methods on the responder instance are never actually invoked.</p>
|
844
|
-
|
845
|
-
|
846
|
-
</div>
|
847
|
-
</div>
|
848
|
-
<div class="tags">
|
849
|
-
|
850
|
-
<div class="examples">
|
851
|
-
<p class="tag_title">Examples:</p>
|
852
|
-
|
853
|
-
|
854
|
-
<p class="example_title"><div class='inline'>
|
855
|
-
<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>
|
856
|
-
</div></p>
|
857
|
-
|
858
|
-
<pre class="example code"><code><span class='kw'>class</span> <span class='const'>Sheep</span>
|
859
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span>
|
860
|
-
<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>
|
861
|
-
<span class='kw'>end</span>
|
862
|
-
<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>
|
863
|
-
<span class='kw'>end</span>
|
864
|
-
|
865
|
-
<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>
|
866
|
-
<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>
|
867
|
-
<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>
|
868
|
-
<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>
|
869
|
-
<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
|
870
|
-
</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
|
871
|
-
</span><span class='id identifier rubyid_sheep'>sheep</span><span class='period'>.</span><span class='id identifier rubyid_chew'>chew</span>
|
872
|
-
<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>
|
873
|
-
|
874
|
-
</div>
|
875
|
-
<p class="tag_title">Parameters:</p>
|
876
|
-
<ul class="param">
|
877
|
-
|
878
|
-
<li>
|
879
|
-
|
880
|
-
<span class='name'>responder_class</span>
|
881
|
-
|
882
|
-
|
883
|
-
<span class='type'>(<tt>Class</tt>)</span>
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
—
|
888
|
-
<div class='inline'>
|
889
|
-
<p>a class used to determine whether <span class='object_link'><a href="" title="Mocha::Mock (class)">Mocha::Mock</a></span> instance should
|
890
|
-
<code>#respond_to?</code> to an invocation.</p>
|
891
|
-
</div>
|
892
|
-
|
893
|
-
</li>
|
894
|
-
|
895
|
-
</ul>
|
896
|
-
|
897
|
-
<p class="tag_title">Returns:</p>
|
898
|
-
<ul class="return">
|
899
|
-
|
900
|
-
<li>
|
901
|
-
|
902
|
-
|
903
|
-
<span class='type'>(<tt><span class='object_link'><a href="" title="Mocha::Mock (class)">Mock</a></span></tt>)</span>
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
—
|
908
|
-
<div class='inline'>
|
909
|
-
<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>
|
910
|
-
methods to be chained.</p>
|
911
|
-
</div>
|
912
|
-
|
913
|
-
</li>
|
914
|
-
|
915
|
-
</ul>
|
916
|
-
|
917
|
-
<p class="tag_title">See Also:</p>
|
918
|
-
<ul class="see">
|
919
|
-
|
920
|
-
<li><span class='object_link'><a href="#responds_like-instance_method" title="Mocha::Mock#responds_like (method)">#responds_like</a></span></li>
|
921
|
-
|
922
|
-
</ul>
|
923
|
-
|
924
|
-
</div><table class="source_code">
|
925
|
-
<tr>
|
926
|
-
<td>
|
927
|
-
<pre class="lines">
|
928
|
-
|
929
|
-
|
930
|
-
249
|
931
|
-
250
|
932
|
-
251</pre>
|
933
|
-
</td>
|
934
|
-
<td>
|
935
|
-
<pre class="code"><span class="info file"># File 'lib/mocha/mock.rb', line 249</span>
|
936
|
-
|
937
|
-
<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>
|
938
|
-
<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>
|
939
|
-
<span class='kw'>end</span></pre>
|
940
|
-
</td>
|
941
|
-
</tr>
|
942
|
-
</table>
|
943
|
-
</div>
|
944
|
-
|
945
|
-
<div class="method_details ">
|
946
|
-
<h3 class="signature " id="stubs-instance_method">
|
947
|
-
|
948
|
-
|
949
|
-
<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>
|
950
|
-
|
951
|
-
<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>
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
<span class="aliases">Also known as:
|
957
|
-
<span class="names"><span id='__stubs__-instance_method'>__stubs__</span></span>
|
958
|
-
</span>
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
</h3><div class="docstring">
|
963
|
-
<div class="discussion">
|
964
|
-
|
965
|
-
<p>Adds an expectation that the specified method may be called any number of
|
966
|
-
times with any parameters.</p>
|
967
|
-
|
968
|
-
|
969
|
-
</div>
|
970
|
-
</div>
|
971
|
-
<div class="tags">
|
972
|
-
|
973
|
-
<div class="examples">
|
974
|
-
<p class="tag_title">Examples:</p>
|
975
|
-
|
976
|
-
|
977
|
-
<p class="example_title"><div class='inline'>
|
978
|
-
<p>No error raised however many times stubbed method is invoked</p>
|
979
|
-
</div></p>
|
980
|
-
|
981
|
-
<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>
|
982
|
-
<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>
|
983
|
-
<span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_stubbed_method'>stubbed_method</span>
|
984
|
-
<span class='id identifier rubyid_object'>object</span><span class='period'>.</span><span class='id identifier rubyid_stubbed_method'>stubbed_method</span>
|
985
|
-
<span class='comment'># no error raised</span></code></pre>
|
986
|
-
|
987
|
-
|
988
|
-
<p class="example_title"><div class='inline'>
|
989
|
-
<p>Setup multiple expectations using
|
990
|
-
<code>stubbed_methods_vs_return_values</code>.</p>
|
991
|
-
</div></p>
|
992
|
-
|
993
|
-
<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>
|
994
|
-
<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>
|
995
|
-
|
996
|
-
<span class='comment'># is exactly equivalent to
|
997
|
-
</span>
|
998
|
-
<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>
|
999
|
-
<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>
|
1000
|
-
<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>
|
1001
|
-
|
1002
|
-
</div>
|
1003
|
-
<p class="tag_title">Parameters:</p>
|
1004
|
-
<ul class="param">
|
1005
|
-
|
1006
|
-
<li>
|
1007
|
-
|
1008
|
-
<span class='name'>method_name</span>
|
1009
|
-
|
1010
|
-
|
1011
|
-
<span class='type'>(<tt>Symbol</tt>, <tt>String</tt>)</span>
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
—
|
1016
|
-
<div class='inline'>
|
1017
|
-
<p>name of stubbed method</p>
|
1018
|
-
</div>
|
1019
|
-
|
1020
|
-
</li>
|
1021
|
-
|
1022
|
-
<li>
|
1023
|
-
|
1024
|
-
<span class='name'>stubbed_methods_vs_return_values</span>
|
1025
|
-
|
1026
|
-
|
1027
|
-
<span class='type'>(<tt>Hash</tt>)</span>
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
—
|
1032
|
-
<div class='inline'>
|
1033
|
-
<p>stubbed method name symbols as keys and corresponding return values as
|
1034
|
-
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
|
1035
|
-
multiple times.</p>
|
1036
|
-
</div>
|
1037
|
-
|
1038
|
-
</li>
|
1039
|
-
|
1040
|
-
</ul>
|
1041
|
-
|
1042
|
-
<p class="tag_title">Returns:</p>
|
1043
|
-
<ul class="return">
|
1044
|
-
|
1045
|
-
<li>
|
1046
|
-
|
1047
|
-
|
1048
|
-
<span class='type'>(<tt><span class='object_link'><a href="Expectation.html" title="Mocha::Expectation (class)">Expectation</a></span></tt>)</span>
|
1049
|
-
|
1050
|
-
|
1051
|
-
|
1052
|
-
—
|
1053
|
-
<div class='inline'>
|
1054
|
-
<p>last-built expectation which can be further modified by methods on
|
1055
|
-
<span class='object_link'><a href="Expectation.html" title="Mocha::Expectation (class)">Expectation</a></span>.</p>
|
1056
|
-
</div>
|
1057
|
-
|
1058
|
-
</li>
|
1059
|
-
|
1060
|
-
</ul>
|
1061
|
-
|
1062
|
-
</div><table class="source_code">
|
1063
|
-
<tr>
|
1064
|
-
<td>
|
1065
|
-
<pre class="lines">
|
1066
|
-
|
1067
|
-
|
1068
|
-
141
|
1069
|
-
142
|
1070
|
-
143
|
1071
|
-
144
|
1072
|
-
145
|
1073
|
-
146
|
1074
|
-
147
|
1075
|
-
148
|
1076
|
-
149
|
1077
|
-
150
|
1078
|
-
151</pre>
|
1079
|
-
</td>
|
1080
|
-
<td>
|
1081
|
-
<pre class="code"><span class="info file"># File 'lib/mocha/mock.rb', line 141</span>
|
1082
|
-
|
1083
|
-
<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>
|
1084
|
-
<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>
|
1085
|
-
<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>
|
1086
|
-
<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>
|
1087
|
-
<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>
|
1088
|
-
<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>
|
1089
|
-
<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>
|
1090
|
-
<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>
|
1091
|
-
<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>
|
1092
|
-
<span class='kw'>end</span>
|
1093
|
-
<span class='kw'>end</span></pre>
|
1094
|
-
</td>
|
1095
|
-
</tr>
|
1096
|
-
</table>
|
1097
|
-
</div>
|
1098
|
-
|
1099
|
-
<div class="method_details ">
|
1100
|
-
<h3 class="signature " id="unstub-instance_method">
|
1101
|
-
|
1102
|
-
#<strong>unstub</strong>(method_name) ⇒ <tt><span class='object_link'>Object</span></tt>
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1107
|
-
|
1108
|
-
</h3><div class="docstring">
|
1109
|
-
<div class="discussion">
|
1110
|
-
|
1111
|
-
<p>Removes the specified stubbed method (added by calls to <span class='object_link'><a href="#expects-instance_method" title="Mocha::Mock#expects (method)">#expects</a></span> or
|
1112
|
-
<span class='object_link'><a href="#stubs-instance_method" title="Mocha::Mock#stubs (method)">#stubs</a></span>) and all expectations associated with it.</p>
|
1113
|
-
|
1114
|
-
|
1115
|
-
</div>
|
1116
|
-
</div>
|
1117
|
-
<div class="tags">
|
1118
|
-
|
1119
|
-
<div class="examples">
|
1120
|
-
<p class="tag_title">Examples:</p>
|
1121
|
-
|
1122
|
-
|
1123
|
-
<p class="example_title"><div class='inline'>
|
1124
|
-
<p>Invoking an unstubbed method causes error to be raised</p>
|
1125
|
-
</div></p>
|
1126
|
-
|
1127
|
-
<pre class="example code"><code>object = mock('mock') do
|
1128
|
-
object.stubs(:stubbed_method).returns(:result_one)
|
1129
|
-
object.stubbed_method # => :result_one
|
1130
|
-
object.unstub(:stubbed_method)
|
1131
|
-
object.stubbed_method # => unexpected invocation: #<Mock:mock>.stubbed_method()</code></pre>
|
1132
|
-
|
1133
|
-
</div>
|
1134
|
-
<p class="tag_title">Parameters:</p>
|
1135
|
-
<ul class="param">
|
1136
|
-
|
1137
|
-
<li>
|
1138
|
-
|
1139
|
-
<span class='name'>method_name</span>
|
1140
|
-
|
1141
|
-
|
1142
|
-
<span class='type'>(<tt>Symbol</tt>)</span>
|
1143
|
-
|
1144
|
-
|
1145
|
-
|
1146
|
-
—
|
1147
|
-
<div class='inline'>
|
1148
|
-
<p>name of method to unstub.</p>
|
1149
|
-
</div>
|
1150
|
-
|
1151
|
-
</li>
|
1152
|
-
|
1153
|
-
</ul>
|
1154
|
-
|
1155
|
-
|
1156
|
-
</div><table class="source_code">
|
1157
|
-
<tr>
|
1158
|
-
<td>
|
1159
|
-
<pre class="lines">
|
1160
|
-
|
1161
|
-
|
1162
|
-
163
|
1163
|
-
164
|
1164
|
-
165</pre>
|
1165
|
-
</td>
|
1166
|
-
<td>
|
1167
|
-
<pre class="code"><span class="info file"># File 'lib/mocha/mock.rb', line 163</span>
|
1168
|
-
|
1169
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_unstub'>unstub</span><span class='lparen'>(</span><span class='id identifier rubyid_method_name'>method_name</span><span class='rparen'>)</span>
|
1170
|
-
<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>
|
1171
|
-
<span class='kw'>end</span></pre>
|
1172
|
-
</td>
|
1173
|
-
</tr>
|
1174
|
-
</table>
|
1175
|
-
</div>
|
1176
|
-
|
1177
|
-
</div>
|
1178
|
-
|
1179
|
-
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-625523-7"></script>
|
1180
|
-
<script>
|
1181
|
-
window.dataLayer = window.dataLayer || [];
|
1182
|
-
function gtag(){dataLayer.push(arguments);}
|
1183
|
-
gtag('js', new Date());
|
1184
|
-
|
1185
|
-
gtag('config', 'UA-625523-7');
|
1186
|
-
</script>
|
1187
|
-
</div>
|
1188
|
-
|
1189
|
-
<div id="footer">
|
1190
|
-
Generated on Tue Jan 15 17:13:06 2019 by
|
1191
|
-
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
1192
|
-
0.9.16 (ruby-2.5.3).
|
1193
|
-
</div>
|
1194
|
-
|
1195
|
-
</div>
|
1196
|
-
</body>
|
1197
|
-
</html>
|