mocha 0.10.5 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING.rdoc +1 -1
- data/README.rdoc +6 -4
- data/RELEASE.rdoc +12 -0
- data/Rakefile +29 -60
- data/doc/Mocha.html +112 -0
- data/doc/Mocha/API.html +898 -0
- data/doc/Mocha/ClassMethods.html +246 -0
- data/doc/Mocha/Configuration.html +471 -0
- data/doc/Mocha/Expectation.html +2570 -0
- data/doc/Mocha/Mock.html +830 -0
- data/doc/Mocha/ObjectMethods.html +668 -0
- data/doc/Mocha/ParameterMatchers.html +2715 -0
- data/doc/Mocha/ParameterMatchers/AllOf.html +137 -0
- data/doc/Mocha/ParameterMatchers/AnyOf.html +137 -0
- data/doc/Mocha/ParameterMatchers/AnyParameters.html +136 -0
- data/doc/Mocha/ParameterMatchers/Anything.html +136 -0
- data/doc/Mocha/ParameterMatchers/Base.html +419 -0
- data/doc/Mocha/ParameterMatchers/Equals.html +137 -0
- data/doc/Mocha/ParameterMatchers/HasEntries.html +137 -0
- data/doc/Mocha/ParameterMatchers/HasEntry.html +137 -0
- data/doc/Mocha/ParameterMatchers/HasKey.html +137 -0
- data/doc/Mocha/ParameterMatchers/HasValue.html +137 -0
- data/doc/Mocha/ParameterMatchers/Includes.html +137 -0
- data/doc/Mocha/ParameterMatchers/InstanceOf.html +137 -0
- data/doc/Mocha/ParameterMatchers/IsA.html +136 -0
- data/doc/Mocha/ParameterMatchers/KindOf.html +137 -0
- data/doc/Mocha/ParameterMatchers/Not.html +137 -0
- data/doc/Mocha/ParameterMatchers/Optionally.html +136 -0
- data/doc/Mocha/ParameterMatchers/QueryStringMatches.html +136 -0
- data/doc/Mocha/ParameterMatchers/RegexpMatches.html +137 -0
- data/doc/Mocha/ParameterMatchers/RespondsWith.html +137 -0
- data/doc/Mocha/ParameterMatchers/YamlEquivalent.html +137 -0
- data/doc/Mocha/Sequence.html +133 -0
- data/doc/Mocha/StateMachine.html +510 -0
- data/doc/Mocha/StateMachine/State.html +125 -0
- data/doc/Mocha/StateMachine/StatePredicate.html +125 -0
- data/doc/Mocha/StubbingError.html +134 -0
- data/doc/Mocha/UnexpectedInvocation.html +124 -0
- data/doc/_index.html +481 -0
- data/doc/class_list.html +47 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +55 -0
- data/doc/css/style.css +322 -0
- data/doc/file.COPYING.html +72 -0
- data/doc/file.MIT-LICENSE.html +86 -0
- data/doc/file.README.html +153 -0
- data/doc/file.RELEASE.html +933 -0
- data/doc/file.misc.html +108 -0
- data/doc/file.mocha.html +90 -0
- data/doc/file.stubba.html +129 -0
- data/doc/file_list.html +67 -0
- data/doc/frames.html +13 -0
- data/doc/index.html +153 -0
- data/doc/js/app.js +205 -0
- data/doc/js/full_list.js +173 -0
- data/doc/js/jquery.js +16 -0
- data/doc/method_list.html +510 -0
- data/doc/top-level-namespace.html +105 -0
- data/lib/mocha/any_instance_method.rb +16 -11
- data/lib/mocha/api.rb +120 -106
- data/lib/mocha/argument_iterator.rb +6 -6
- data/lib/mocha/backtrace_filter.rb +1 -1
- data/lib/mocha/cardinality.rb +21 -21
- data/lib/mocha/central.rb +8 -8
- data/lib/mocha/change_state_side_effect.rb +5 -5
- data/lib/mocha/class_method.rb +14 -19
- data/lib/mocha/configuration.rb +47 -37
- data/lib/mocha/deprecation.rb +8 -8
- data/lib/mocha/exception_raiser.rb +7 -7
- data/lib/mocha/expectation.rb +173 -77
- data/lib/mocha/expectation_error.rb +2 -2
- data/lib/mocha/expectation_list.rb +11 -11
- data/lib/mocha/in_state_ordering_constraint.rb +5 -5
- data/lib/mocha/inspect.rb +8 -8
- data/lib/mocha/instance_method.rb +1 -17
- data/lib/mocha/integration.rb +9 -9
- data/lib/mocha/integration/mini_test/assertion_counter.rb +9 -9
- data/lib/mocha/integration/mini_test/exception_translation.rb +6 -6
- data/lib/mocha/integration/mini_test/version_13.rb +6 -6
- data/lib/mocha/integration/mini_test/version_140.rb +6 -6
- data/lib/mocha/integration/mini_test/version_141.rb +6 -6
- data/lib/mocha/integration/mini_test/version_142_to_172.rb +7 -7
- data/lib/mocha/integration/mini_test/version_200.rb +7 -7
- data/lib/mocha/integration/test_unit/assertion_counter.rb +10 -10
- data/lib/mocha/integration/test_unit/gem_version_200.rb +6 -6
- data/lib/mocha/integration/test_unit/gem_version_201_to_202.rb +6 -6
- data/lib/mocha/integration/test_unit/ruby_version_185_and_below.rb +6 -6
- data/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb +6 -6
- data/lib/mocha/is_a.rb +1 -1
- data/lib/mocha/logger.rb +6 -6
- data/lib/mocha/method_matcher.rb +7 -7
- data/lib/mocha/mock.rb +85 -48
- data/lib/mocha/mockery.rb +47 -33
- data/lib/mocha/module_method.rb +2 -2
- data/lib/mocha/multiple_yields.rb +9 -9
- data/lib/mocha/names.rb +18 -18
- data/lib/mocha/no_yields.rb +7 -7
- data/lib/mocha/object.rb +104 -75
- data/lib/mocha/parameter_matchers.rb +3 -3
- data/lib/mocha/parameter_matchers/all_of.rb +22 -12
- data/lib/mocha/parameter_matchers/any_of.rb +23 -12
- data/lib/mocha/parameter_matchers/any_parameters.rb +15 -8
- data/lib/mocha/parameter_matchers/anything.rb +20 -11
- data/lib/mocha/parameter_matchers/base.rb +35 -27
- data/lib/mocha/parameter_matchers/equals.rb +23 -12
- data/lib/mocha/parameter_matchers/has_entries.rb +22 -12
- data/lib/mocha/parameter_matchers/has_entry.rb +31 -13
- data/lib/mocha/parameter_matchers/has_key.rb +21 -11
- data/lib/mocha/parameter_matchers/has_value.rb +21 -11
- data/lib/mocha/parameter_matchers/includes.rb +15 -5
- data/lib/mocha/parameter_matchers/instance_of.rb +23 -12
- data/lib/mocha/parameter_matchers/is_a.rb +23 -12
- data/lib/mocha/parameter_matchers/kind_of.rb +23 -12
- data/lib/mocha/parameter_matchers/not.rb +22 -12
- data/lib/mocha/parameter_matchers/object.rb +5 -3
- data/lib/mocha/parameter_matchers/optionally.rb +24 -12
- data/lib/mocha/parameter_matchers/query_string.rb +14 -3
- data/lib/mocha/parameter_matchers/regexp_matches.rb +21 -11
- data/lib/mocha/parameter_matchers/responds_with.rb +17 -6
- data/lib/mocha/parameter_matchers/yaml_equivalent.rb +16 -6
- data/lib/mocha/parameters_matcher.rb +8 -8
- data/lib/mocha/pretty_parameters.rb +7 -7
- data/lib/mocha/return_values.rb +11 -11
- data/lib/mocha/sequence.rb +23 -14
- data/lib/mocha/single_return_value.rb +7 -7
- data/lib/mocha/single_yield.rb +9 -9
- data/lib/mocha/standalone.rb +1 -1
- data/lib/mocha/state_machine.rb +61 -46
- data/lib/mocha/stubbing_error.rb +8 -5
- data/lib/mocha/thrower.rb +2 -2
- data/lib/mocha/unexpected_invocation.rb +9 -6
- data/lib/mocha/version.rb +1 -1
- data/lib/mocha/yield_parameters.rb +10 -10
- data/lib/mocha_standalone.rb +1 -1
- data/mocha.gemspec +4 -7
- data/test/acceptance/acceptance_test_helper.rb +10 -10
- data/test/acceptance/api_test.rb +20 -20
- data/test/acceptance/bug_18914_test.rb +12 -12
- data/test/acceptance/bug_21465_test.rb +6 -6
- data/test/acceptance/bug_21563_test.rb +5 -5
- data/test/acceptance/exception_rescue_test.rb +1 -1
- data/test/acceptance/expected_invocation_count_test.rb +17 -17
- data/test/acceptance/failure_messages_test.rb +13 -13
- data/test/acceptance/minitest_test.rb +39 -39
- data/test/acceptance/mocha_example_test.rb +26 -26
- data/test/acceptance/mocha_test_result_test.rb +13 -13
- data/test/acceptance/mock_test.rb +5 -5
- data/test/acceptance/mock_with_initializer_block_test.rb +5 -5
- data/test/acceptance/mocked_methods_dispatch_test.rb +4 -4
- data/test/acceptance/multiple_expectations_failure_message_test.rb +2 -2
- data/test/acceptance/optional_parameters_test.rb +5 -5
- data/test/acceptance/parameter_matcher_test.rb +18 -18
- data/test/acceptance/partial_mocks_test.rb +9 -9
- data/test/acceptance/raise_exception_test.rb +1 -1
- data/test/acceptance/return_value_test.rb +5 -5
- data/test/acceptance/sequence_test.rb +29 -29
- data/test/acceptance/states_test.rb +17 -17
- data/test/acceptance/stub_any_instance_method_test.rb +13 -13
- data/test/acceptance/stub_class_method_defined_on_active_record_association_proxy_test.rb +7 -7
- data/test/acceptance/stub_everything_test.rb +5 -5
- data/test/acceptance/stub_instance_method_defined_on_singleton_class_test.rb +1 -1
- data/test/acceptance/stub_module_method_test.rb +17 -17
- data/test/acceptance/stub_test.rb +5 -5
- data/test/acceptance/stubba_example_test.rb +24 -24
- data/test/acceptance/stubba_test_result_test.rb +11 -11
- data/test/acceptance/stubbing_error_backtrace_test.rb +6 -6
- data/test/acceptance/stubbing_frozen_object_test.rb +88 -0
- data/test/acceptance/stubbing_method_unnecessarily_test.rb +9 -9
- data/test/acceptance/stubbing_nil_test.rb +59 -0
- data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +13 -13
- data/test/acceptance/stubbing_non_existent_class_method_test.rb +15 -15
- data/test/acceptance/stubbing_non_existent_instance_method_test.rb +14 -14
- data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +13 -13
- data/test/acceptance/stubbing_non_public_class_method_test.rb +12 -12
- data/test/acceptance/stubbing_non_public_instance_method_test.rb +12 -12
- data/test/acceptance/stubbing_on_non_mock_object_test.rb +9 -9
- data/test/acceptance/stubbing_same_class_method_on_parent_and_child_classes_test.rb +35 -0
- data/test/acceptance/throw_test.rb +1 -1
- data/test/deprecation_disabler.rb +1 -1
- data/test/execution_point.rb +7 -7
- data/test/method_definer.rb +1 -1
- data/test/mini_test_result.rb +21 -21
- data/test/simple_counter.rb +5 -5
- data/test/test_helper.rb +1 -1
- data/test/test_runner.rb +22 -24
- data/test/test_unit_result.rb +20 -0
- data/test/unit/any_instance_method_test.rb +28 -32
- data/test/unit/array_inspect_test.rb +3 -3
- data/test/unit/backtrace_filter_test.rb +3 -3
- data/test/unit/cardinality_test.rb +12 -12
- data/test/unit/central_test.rb +18 -18
- data/test/unit/change_state_side_effect_test.rb +12 -12
- data/test/unit/class_method_test.rb +33 -91
- data/test/unit/date_time_inspect_test.rb +4 -4
- data/test/unit/exception_raiser_test.rb +5 -5
- data/test/unit/expectation_list_test.rb +7 -7
- data/test/unit/expectation_test.rb +66 -66
- data/test/unit/hash_inspect_test.rb +4 -4
- data/test/unit/in_state_ordering_constraint_test.rb +13 -13
- data/test/unit/method_matcher_test.rb +3 -3
- data/test/unit/mock_test.rb +40 -40
- data/test/unit/mockery_test.rb +25 -25
- data/test/unit/multiple_yields_test.rb +2 -2
- data/test/unit/no_yields_test.rb +2 -2
- data/test/unit/object_inspect_test.rb +4 -4
- data/test/unit/object_test.rb +15 -15
- data/test/unit/parameter_matchers/all_of_test.rb +6 -6
- data/test/unit/parameter_matchers/any_of_test.rb +6 -6
- data/test/unit/parameter_matchers/anything_test.rb +5 -5
- data/test/unit/parameter_matchers/has_entries_test.rb +10 -10
- data/test/unit/parameter_matchers/has_entry_test.rb +13 -13
- data/test/unit/parameter_matchers/has_key_test.rb +11 -11
- data/test/unit/parameter_matchers/has_value_test.rb +12 -12
- data/test/unit/parameter_matchers/includes_test.rb +4 -4
- data/test/unit/parameter_matchers/not_test.rb +6 -6
- data/test/unit/parameter_matchers/regexp_matches_test.rb +9 -9
- data/test/unit/parameter_matchers/responds_with_test.rb +6 -6
- data/test/unit/parameter_matchers/stub_matcher.rb +4 -4
- data/test/unit/parameter_matchers/yaml_equivalent_test.rb +6 -6
- data/test/unit/parameters_matcher_test.rb +16 -16
- data/test/unit/return_values_test.rb +5 -5
- data/test/unit/sequence_test.rb +10 -10
- data/test/unit/single_return_value_test.rb +3 -3
- data/test/unit/single_yield_test.rb +2 -2
- data/test/unit/state_machine_test.rb +19 -19
- data/test/unit/string_inspect_test.rb +2 -2
- data/test/unit/thrower_test.rb +1 -1
- data/test/unit/yield_parameters_test.rb +11 -11
- metadata +113 -101
@@ -0,0 +1,668 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
6
|
+
<title>
|
7
|
+
Module: Mocha::ObjectMethods
|
8
|
+
|
9
|
+
— Mocha 0.11.0
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="../css/style.css" type="text/css" media="screen" charset="utf-8" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="../css/common.css" type="text/css" media="screen" charset="utf-8" />
|
16
|
+
|
17
|
+
<script type="text/javascript" charset="utf-8">
|
18
|
+
relpath = '..';
|
19
|
+
if (relpath != '') relpath += '/';
|
20
|
+
</script>
|
21
|
+
|
22
|
+
<script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
|
23
|
+
|
24
|
+
<script type="text/javascript" charset="utf-8" src="../js/app.js"></script>
|
25
|
+
|
26
|
+
|
27
|
+
</head>
|
28
|
+
<body>
|
29
|
+
<script type="text/javascript" charset="utf-8">
|
30
|
+
if (window.top.frames.main) document.body.className = 'frames';
|
31
|
+
</script>
|
32
|
+
|
33
|
+
<div id="header">
|
34
|
+
<div id="menu">
|
35
|
+
|
36
|
+
<a href="../_index.html">Index (O)</a> »
|
37
|
+
<span class='title'><span class='object_link'><a href="../Mocha.html" title="Mocha (module)">Mocha</a></span></span>
|
38
|
+
»
|
39
|
+
<span class="title">ObjectMethods</span>
|
40
|
+
|
41
|
+
|
42
|
+
<div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
|
43
|
+
</div>
|
44
|
+
|
45
|
+
<div id="search">
|
46
|
+
|
47
|
+
<a id="class_list_link" href="#">Class List</a>
|
48
|
+
|
49
|
+
<a id="method_list_link" href="#">Method List</a>
|
50
|
+
|
51
|
+
<a id="file_list_link" href="#">File List</a>
|
52
|
+
|
53
|
+
</div>
|
54
|
+
<div class="clear"></div>
|
55
|
+
</div>
|
56
|
+
|
57
|
+
<iframe id="search_frame"></iframe>
|
58
|
+
|
59
|
+
<div id="content"><h1>Module: Mocha::ObjectMethods
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
</h1>
|
64
|
+
|
65
|
+
<dl class="box">
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
<dt class="r1 last">Defined in:</dt>
|
75
|
+
<dd class="r1 last">lib/mocha/object.rb<span class="defines">,<br />
|
76
|
+
lib/mocha/parameter_matchers/object.rb</span>
|
77
|
+
</dd>
|
78
|
+
|
79
|
+
</dl>
|
80
|
+
<div class="clear"></div>
|
81
|
+
|
82
|
+
<h2>Overview</h2><div class="docstring">
|
83
|
+
<div class="discussion">
|
84
|
+
|
85
|
+
<p>Methods added to all objects to allow mocking and stubbing on real (i.e.
|
86
|
+
non-mock) objects.</p>
|
87
|
+
|
88
|
+
<p>Both <span class='object_link'><a href="#expects-instance_method" title="Mocha::ObjectMethods#expects (method)">#expects</a></span> and <span class='object_link'><a href="#stubs-instance_method" title="Mocha::ObjectMethods#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
|
89
|
+
modified by methods on <span class='object_link'><a href="Expectation.html" title="Mocha::Expectation (class)">Expectation</a></span>.</p>
|
90
|
+
|
91
|
+
|
92
|
+
</div>
|
93
|
+
</div>
|
94
|
+
<div class="tags">
|
95
|
+
|
96
|
+
|
97
|
+
</div>
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
<h2>
|
106
|
+
Instance Method Summary
|
107
|
+
<small>(<a href="#" class="summary_toggle">collapse</a>)</small>
|
108
|
+
</h2>
|
109
|
+
|
110
|
+
<ul class="summary">
|
111
|
+
|
112
|
+
<li class="public ">
|
113
|
+
<span class="summary_signature">
|
114
|
+
|
115
|
+
<a href="#expects-instance_method" title="#expects (instance method)">- (Expectation) <strong>expects</strong>(expected_methods_vs_return_values) </a>
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
</span>
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
<span class="summary_desc"><div class='inline'>
|
129
|
+
<p>Adds an expectation that the specified method must be called exactly once
|
130
|
+
with any parameters.</p>
|
131
|
+
</div></span>
|
132
|
+
|
133
|
+
</li>
|
134
|
+
|
135
|
+
|
136
|
+
<li class="public ">
|
137
|
+
<span class="summary_signature">
|
138
|
+
|
139
|
+
<a href="#stubs-instance_method" title="#stubs (instance method)">- (Expectation) <strong>stubs</strong>(stubbed_methods_vs_return_values) </a>
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
</span>
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
|
152
|
+
<span class="summary_desc"><div class='inline'>
|
153
|
+
<p>Adds an expectation that the specified method may be called any number of
|
154
|
+
times with any parameters.</p>
|
155
|
+
</div></span>
|
156
|
+
|
157
|
+
</li>
|
158
|
+
|
159
|
+
|
160
|
+
<li class="public ">
|
161
|
+
<span class="summary_signature">
|
162
|
+
|
163
|
+
<a href="#unstub-instance_method" title="#unstub (instance method)">- (Object) <strong>unstub</strong>(*method_names) </a>
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
</span>
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
|
176
|
+
<span class="summary_desc"><div class='inline'>
|
177
|
+
<p>Removes the specified stubbed methods (added by calls to <span class='object_link'><a href="#expects-instance_method" title="Mocha::ObjectMethods#expects (method)">#expects</a></span> or
|
178
|
+
<span class='object_link'><a href="#stubs-instance_method" title="Mocha::ObjectMethods#stubs (method)">#stubs</a></span>) and all expectations associated with them.</p>
|
179
|
+
</div></span>
|
180
|
+
|
181
|
+
</li>
|
182
|
+
|
183
|
+
|
184
|
+
</ul>
|
185
|
+
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
<div id="instance_method_details" class="method_details_list">
|
190
|
+
<h2>Instance Method Details</h2>
|
191
|
+
|
192
|
+
|
193
|
+
<div class="method_details first">
|
194
|
+
<p class="signature first" id="expects-instance_method">
|
195
|
+
|
196
|
+
|
197
|
+
<span class="overload">- (<tt><span class='object_link'><a href="Expectation.html" title="Mocha::Expectation (class)">Expectation</a></span></tt>) <strong>expects</strong>(method_name) </span>
|
198
|
+
|
199
|
+
<span class="overload">- (<tt><span class='object_link'><a href="Expectation.html" title="Mocha::Expectation (class)">Expectation</a></span></tt>) <strong>expects</strong>(expected_methods_vs_return_values) </span>
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
|
204
|
+
</p><div class="docstring">
|
205
|
+
<div class="discussion">
|
206
|
+
|
207
|
+
<p>Adds an expectation that the specified method must be called exactly once
|
208
|
+
with any parameters.</p>
|
209
|
+
|
210
|
+
<p>The original implementation of the method is replaced during the test and
|
211
|
+
then restored at the end of the test.</p>
|
212
|
+
|
213
|
+
|
214
|
+
</div>
|
215
|
+
</div>
|
216
|
+
<div class="tags">
|
217
|
+
|
218
|
+
<div class="examples">
|
219
|
+
<h3>Examples:</h3>
|
220
|
+
|
221
|
+
<h4><div class='inline'>
|
222
|
+
<p>Setting up an expectation on a non-mock object.</p>
|
223
|
+
</div></h4>
|
224
|
+
<pre class="example code"><span class='id identifier rubyid_product'>product</span> <span class='op'>=</span> <span class='const'>Product</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
|
225
|
+
<span class='id identifier rubyid_product'>product</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:save</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_returns'>returns</span><span class='lparen'>(</span><span class='kw'>true</span><span class='rparen'>)</span>
|
226
|
+
<span class='id identifier rubyid_assert_equal'>assert_equal</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='id identifier rubyid_product'>product</span><span class='period'>.</span><span class='id identifier rubyid_save'>save</span></pre>
|
227
|
+
|
228
|
+
<h4><div class='inline'>
|
229
|
+
<p>Setting up multiple expectations on a non-mock object.</p>
|
230
|
+
</div></h4>
|
231
|
+
<pre class="example code"><span class='id identifier rubyid_product'>product</span> <span class='op'>=</span> <span class='const'>Product</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
|
232
|
+
<span class='id identifier rubyid_product'>product</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:valid?</span> <span class='op'>=></span> <span class='kw'>true</span><span class='comma'>,</span> <span class='symbol'>:save</span> <span class='op'>=></span> <span class='kw'>true</span><span class='rparen'>)</span>
|
233
|
+
|
234
|
+
<span class='comment'># exactly equivalent to
|
235
|
+
</span>
|
236
|
+
<span class='id identifier rubyid_product'>product</span> <span class='op'>=</span> <span class='const'>Product</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
|
237
|
+
<span class='id identifier rubyid_product'>product</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:valid?</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_returns'>returns</span><span class='lparen'>(</span><span class='kw'>true</span><span class='rparen'>)</span>
|
238
|
+
<span class='id identifier rubyid_product'>product</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:save</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_returns'>returns</span><span class='lparen'>(</span><span class='kw'>true</span><span class='rparen'>)</span></pre>
|
239
|
+
|
240
|
+
</div>
|
241
|
+
<h3>Parameters:</h3>
|
242
|
+
<ul class="param">
|
243
|
+
|
244
|
+
<li>
|
245
|
+
|
246
|
+
<span class='name'>method_name</span>
|
247
|
+
|
248
|
+
|
249
|
+
<span class='type'>(<tt>Symbol</tt>, <tt>String</tt>)</span>
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
—
|
254
|
+
<div class='inline'>
|
255
|
+
<p>name of expected method</p>
|
256
|
+
</div>
|
257
|
+
|
258
|
+
</li>
|
259
|
+
|
260
|
+
<li>
|
261
|
+
|
262
|
+
<span class='name'>expected_methods_vs_return_values</span>
|
263
|
+
|
264
|
+
|
265
|
+
<span class='type'>(<tt>Hash</tt>)</span>
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
—
|
270
|
+
<div class='inline'>
|
271
|
+
<p>expected method name symbols as keys and corresponding return values as
|
272
|
+
values - these expectations are setup as if <span class='object_link'><a href="#expects-instance_method" title="Mocha::ObjectMethods#expects (method)">#expects</a></span> were called multiple
|
273
|
+
times.</p>
|
274
|
+
</div>
|
275
|
+
|
276
|
+
</li>
|
277
|
+
|
278
|
+
</ul>
|
279
|
+
|
280
|
+
<h3>Returns:</h3>
|
281
|
+
<ul class="return">
|
282
|
+
|
283
|
+
<li>
|
284
|
+
|
285
|
+
|
286
|
+
<span class='type'>(<tt><span class='object_link'><a href="Expectation.html" title="Mocha::Expectation (class)">Expectation</a></span></tt>)</span>
|
287
|
+
|
288
|
+
|
289
|
+
|
290
|
+
—
|
291
|
+
<div class='inline'>
|
292
|
+
<p>last-built expectation which can be further modified by methods on
|
293
|
+
<span class='object_link'><a href="Expectation.html" title="Mocha::Expectation (class)">Expectation</a></span>.</p>
|
294
|
+
</div>
|
295
|
+
|
296
|
+
</li>
|
297
|
+
|
298
|
+
</ul>
|
299
|
+
<h3>Raises:</h3>
|
300
|
+
<ul class="raise">
|
301
|
+
|
302
|
+
<li>
|
303
|
+
|
304
|
+
|
305
|
+
<span class='type'>(<tt><span class='object_link'><a href="StubbingError.html" title="Mocha::StubbingError (class)">StubbingError</a></span></tt>)</span>
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
—
|
310
|
+
<div class='inline'>
|
311
|
+
<p>if attempting to stub method which is not allowed.</p>
|
312
|
+
</div>
|
313
|
+
|
314
|
+
</li>
|
315
|
+
|
316
|
+
</ul>
|
317
|
+
|
318
|
+
<h3>See Also:</h3>
|
319
|
+
<ul class="see">
|
320
|
+
|
321
|
+
<li><span class='object_link'><a href="Mock.html#expects-instance_method" title="Mocha::Mock#expects (method)">Mock#expects</a></span></li>
|
322
|
+
|
323
|
+
</ul>
|
324
|
+
|
325
|
+
</div><table class="source_code">
|
326
|
+
<tr>
|
327
|
+
<td>
|
328
|
+
<pre class="lines">
|
329
|
+
|
330
|
+
|
331
|
+
63
|
332
|
+
64
|
333
|
+
65
|
334
|
+
66
|
335
|
+
67
|
336
|
+
68
|
337
|
+
69
|
338
|
+
70
|
339
|
+
71
|
340
|
+
72
|
341
|
+
73
|
342
|
+
74
|
343
|
+
75
|
344
|
+
76
|
345
|
+
77
|
346
|
+
78
|
347
|
+
79
|
348
|
+
80
|
349
|
+
81
|
350
|
+
82</pre>
|
351
|
+
</td>
|
352
|
+
<td>
|
353
|
+
<pre class="code"><span class="info file"># File 'lib/mocha/object.rb', line 63</span>
|
354
|
+
|
355
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='id identifier rubyid_expected_methods_vs_return_values'>expected_methods_vs_return_values</span><span class='rparen'>)</span>
|
356
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_expected_methods_vs_return_values'>expected_methods_vs_return_values</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='op'>=~</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>the[^a-z]*spanish[^a-z]*inquisition</span><span class='regexp_end'>/i</span></span>
|
357
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>Mocha</span><span class='op'>::</span><span class='const'>ExpectationError</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>NOBODY EXPECTS THE SPANISH INQUISITION!</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
358
|
+
<span class='kw'>end</span>
|
359
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_frozen?'>frozen?</span>
|
360
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>StubbingError</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>can't stub method on frozen object: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_mocha_inspect'>mocha_inspect</span><span class='rbrace'>}</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='id identifier rubyid_caller'>caller</span><span class='rparen'>)</span>
|
361
|
+
<span class='kw'>end</span>
|
362
|
+
<span class='id identifier rubyid_expectation'>expectation</span> <span class='op'>=</span> <span class='kw'>nil</span>
|
363
|
+
<span class='id identifier rubyid_mockery'>mockery</span> <span class='op'>=</span> <span class='const'>Mocha</span><span class='op'>::</span><span class='const'>Mockery</span><span class='period'>.</span><span class='id identifier rubyid_instance'>instance</span>
|
364
|
+
<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_expected_methods_vs_return_values'>expected_methods_vs_return_values</span><span class='rparen'>)</span>
|
365
|
+
<span class='id identifier rubyid_iterator'>iterator</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='op'>|</span>
|
366
|
+
<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>
|
367
|
+
<span class='id identifier rubyid_mockery'>mockery</span><span class='period'>.</span><span class='id identifier rubyid_on_stubbing'>on_stubbing</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='rparen'>)</span>
|
368
|
+
<span class='id identifier rubyid_method'>method</span> <span class='op'>=</span> <span class='id identifier rubyid_stubba_method'>stubba_method</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_stubba_object'>stubba_object</span><span class='comma'>,</span> <span class='id identifier rubyid_method_name'>method_name</span><span class='rparen'>)</span>
|
369
|
+
<span class='id identifier rubyid_mockery'>mockery</span><span class='period'>.</span><span class='id identifier rubyid_stubba'>stubba</span><span class='period'>.</span><span class='id identifier rubyid_stub'>stub</span><span class='lparen'>(</span><span class='id identifier rubyid_method'>method</span><span class='rparen'>)</span>
|
370
|
+
<span class='id identifier rubyid_expectation'>expectation</span> <span class='op'>=</span> <span class='id identifier rubyid_mocha'>mocha</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='id identifier rubyid_method_name'>method_name</span><span class='comma'>,</span> <span class='id identifier rubyid_caller'>caller</span><span class='rparen'>)</span>
|
371
|
+
<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'>if</span> <span class='id identifier rubyid_args'>args</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span> <span class='op'>></span> <span class='int'>0</span>
|
372
|
+
<span class='rbrace'>}</span>
|
373
|
+
<span class='id identifier rubyid_expectation'>expectation</span>
|
374
|
+
<span class='kw'>end</span></pre>
|
375
|
+
</td>
|
376
|
+
</tr>
|
377
|
+
</table>
|
378
|
+
</div>
|
379
|
+
|
380
|
+
<div class="method_details ">
|
381
|
+
<p class="signature " id="stubs-instance_method">
|
382
|
+
|
383
|
+
|
384
|
+
<span class="overload">- (<tt><span class='object_link'><a href="Expectation.html" title="Mocha::Expectation (class)">Expectation</a></span></tt>) <strong>stubs</strong>(method_name) </span>
|
385
|
+
|
386
|
+
<span class="overload">- (<tt><span class='object_link'><a href="Expectation.html" title="Mocha::Expectation (class)">Expectation</a></span></tt>) <strong>stubs</strong>(stubbed_methods_vs_return_values) </span>
|
387
|
+
|
388
|
+
|
389
|
+
|
390
|
+
|
391
|
+
</p><div class="docstring">
|
392
|
+
<div class="discussion">
|
393
|
+
|
394
|
+
<p>Adds an expectation that the specified method may be called any number of
|
395
|
+
times with any parameters.</p>
|
396
|
+
|
397
|
+
|
398
|
+
</div>
|
399
|
+
</div>
|
400
|
+
<div class="tags">
|
401
|
+
|
402
|
+
<div class="examples">
|
403
|
+
<h3>Examples:</h3>
|
404
|
+
|
405
|
+
<h4><div class='inline'>
|
406
|
+
<p>Setting up a stubbed methods on a non-mock object.</p>
|
407
|
+
</div></h4>
|
408
|
+
<pre class="example code"><span class='id identifier rubyid_product'>product</span> <span class='op'>=</span> <span class='const'>Product</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
|
409
|
+
<span class='id identifier rubyid_product'>product</span><span class='period'>.</span><span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='symbol'>:save</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_returns'>returns</span><span class='lparen'>(</span><span class='kw'>true</span><span class='rparen'>)</span>
|
410
|
+
<span class='id identifier rubyid_assert_equal'>assert_equal</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='id identifier rubyid_product'>product</span><span class='period'>.</span><span class='id identifier rubyid_save'>save</span></pre>
|
411
|
+
|
412
|
+
<h4><div class='inline'>
|
413
|
+
<p>Setting up multiple stubbed methods on a non-mock object.</p>
|
414
|
+
</div></h4>
|
415
|
+
<pre class="example code"><span class='id identifier rubyid_product'>product</span> <span class='op'>=</span> <span class='const'>Product</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
|
416
|
+
<span class='id identifier rubyid_product'>product</span><span class='period'>.</span><span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='symbol'>:valid?</span> <span class='op'>=></span> <span class='kw'>true</span><span class='comma'>,</span> <span class='symbol'>:save</span> <span class='op'>=></span> <span class='kw'>true</span><span class='rparen'>)</span>
|
417
|
+
|
418
|
+
<span class='comment'># exactly equivalent to
|
419
|
+
</span>
|
420
|
+
<span class='id identifier rubyid_product'>product</span> <span class='op'>=</span> <span class='const'>Product</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
|
421
|
+
<span class='id identifier rubyid_product'>product</span><span class='period'>.</span><span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='symbol'>:valid?</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_returns'>returns</span><span class='lparen'>(</span><span class='kw'>true</span><span class='rparen'>)</span>
|
422
|
+
<span class='id identifier rubyid_product'>product</span><span class='period'>.</span><span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='symbol'>:save</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_returns'>returns</span><span class='lparen'>(</span><span class='kw'>true</span><span class='rparen'>)</span></pre>
|
423
|
+
|
424
|
+
</div>
|
425
|
+
<h3>Parameters:</h3>
|
426
|
+
<ul class="param">
|
427
|
+
|
428
|
+
<li>
|
429
|
+
|
430
|
+
<span class='name'>method_name</span>
|
431
|
+
|
432
|
+
|
433
|
+
<span class='type'>(<tt>Symbol</tt>, <tt>String</tt>)</span>
|
434
|
+
|
435
|
+
|
436
|
+
|
437
|
+
—
|
438
|
+
<div class='inline'>
|
439
|
+
<p>name of stubbed method</p>
|
440
|
+
</div>
|
441
|
+
|
442
|
+
</li>
|
443
|
+
|
444
|
+
<li>
|
445
|
+
|
446
|
+
<span class='name'>stubbed_methods_vs_return_values</span>
|
447
|
+
|
448
|
+
|
449
|
+
<span class='type'>(<tt>Hash</tt>)</span>
|
450
|
+
|
451
|
+
|
452
|
+
|
453
|
+
—
|
454
|
+
<div class='inline'>
|
455
|
+
<p>stubbed method name symbols as keys and corresponding return values as
|
456
|
+
values - these stubbed methods are setup as if <span class='object_link'><a href="#stubs-instance_method" title="Mocha::ObjectMethods#stubs (method)">#stubs</a></span> were called
|
457
|
+
multiple times.</p>
|
458
|
+
</div>
|
459
|
+
|
460
|
+
</li>
|
461
|
+
|
462
|
+
</ul>
|
463
|
+
|
464
|
+
<h3>Returns:</h3>
|
465
|
+
<ul class="return">
|
466
|
+
|
467
|
+
<li>
|
468
|
+
|
469
|
+
|
470
|
+
<span class='type'>(<tt><span class='object_link'><a href="Expectation.html" title="Mocha::Expectation (class)">Expectation</a></span></tt>)</span>
|
471
|
+
|
472
|
+
|
473
|
+
|
474
|
+
—
|
475
|
+
<div class='inline'>
|
476
|
+
<p>last-built expectation which can be further modified by methods on
|
477
|
+
<span class='object_link'><a href="Expectation.html" title="Mocha::Expectation (class)">Expectation</a></span>.</p>
|
478
|
+
</div>
|
479
|
+
|
480
|
+
</li>
|
481
|
+
|
482
|
+
</ul>
|
483
|
+
<h3>Raises:</h3>
|
484
|
+
<ul class="raise">
|
485
|
+
|
486
|
+
<li>
|
487
|
+
|
488
|
+
|
489
|
+
<span class='type'>(<tt><span class='object_link'><a href="StubbingError.html" title="Mocha::StubbingError (class)">StubbingError</a></span></tt>)</span>
|
490
|
+
|
491
|
+
|
492
|
+
|
493
|
+
—
|
494
|
+
<div class='inline'>
|
495
|
+
<p>if attempting to stub method which is not allowed.</p>
|
496
|
+
</div>
|
497
|
+
|
498
|
+
</li>
|
499
|
+
|
500
|
+
</ul>
|
501
|
+
|
502
|
+
<h3>See Also:</h3>
|
503
|
+
<ul class="see">
|
504
|
+
|
505
|
+
<li><span class='object_link'><a href="Mock.html#stubs-instance_method" title="Mocha::Mock#stubs (method)">Mock#stubs</a></span></li>
|
506
|
+
|
507
|
+
</ul>
|
508
|
+
|
509
|
+
</div><table class="source_code">
|
510
|
+
<tr>
|
511
|
+
<td>
|
512
|
+
<pre class="lines">
|
513
|
+
|
514
|
+
|
515
|
+
110
|
516
|
+
111
|
517
|
+
112
|
518
|
+
113
|
519
|
+
114
|
520
|
+
115
|
521
|
+
116
|
522
|
+
117
|
523
|
+
118
|
524
|
+
119
|
525
|
+
120
|
526
|
+
121
|
527
|
+
122
|
528
|
+
123
|
529
|
+
124
|
530
|
+
125
|
531
|
+
126</pre>
|
532
|
+
</td>
|
533
|
+
<td>
|
534
|
+
<pre class="code"><span class="info file"># File 'lib/mocha/object.rb', line 110</span>
|
535
|
+
|
536
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='id identifier rubyid_stubbed_methods_vs_return_values'>stubbed_methods_vs_return_values</span><span class='rparen'>)</span>
|
537
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_frozen?'>frozen?</span>
|
538
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>StubbingError</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>can't stub method on frozen object: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_mocha_inspect'>mocha_inspect</span><span class='rbrace'>}</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='id identifier rubyid_caller'>caller</span><span class='rparen'>)</span>
|
539
|
+
<span class='kw'>end</span>
|
540
|
+
<span class='id identifier rubyid_expectation'>expectation</span> <span class='op'>=</span> <span class='kw'>nil</span>
|
541
|
+
<span class='id identifier rubyid_mockery'>mockery</span> <span class='op'>=</span> <span class='const'>Mocha</span><span class='op'>::</span><span class='const'>Mockery</span><span class='period'>.</span><span class='id identifier rubyid_instance'>instance</span>
|
542
|
+
<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_stubbed_methods_vs_return_values'>stubbed_methods_vs_return_values</span><span class='rparen'>)</span>
|
543
|
+
<span class='id identifier rubyid_iterator'>iterator</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='op'>|</span>
|
544
|
+
<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>
|
545
|
+
<span class='id identifier rubyid_mockery'>mockery</span><span class='period'>.</span><span class='id identifier rubyid_on_stubbing'>on_stubbing</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='rparen'>)</span>
|
546
|
+
<span class='id identifier rubyid_method'>method</span> <span class='op'>=</span> <span class='id identifier rubyid_stubba_method'>stubba_method</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_stubba_object'>stubba_object</span><span class='comma'>,</span> <span class='id identifier rubyid_method_name'>method_name</span><span class='rparen'>)</span>
|
547
|
+
<span class='id identifier rubyid_mockery'>mockery</span><span class='period'>.</span><span class='id identifier rubyid_stubba'>stubba</span><span class='period'>.</span><span class='id identifier rubyid_stub'>stub</span><span class='lparen'>(</span><span class='id identifier rubyid_method'>method</span><span class='rparen'>)</span>
|
548
|
+
<span class='id identifier rubyid_expectation'>expectation</span> <span class='op'>=</span> <span class='id identifier rubyid_mocha'>mocha</span><span class='period'>.</span><span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='id identifier rubyid_method_name'>method_name</span><span class='comma'>,</span> <span class='id identifier rubyid_caller'>caller</span><span class='rparen'>)</span>
|
549
|
+
<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'>if</span> <span class='id identifier rubyid_args'>args</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span> <span class='op'>></span> <span class='int'>0</span>
|
550
|
+
<span class='rbrace'>}</span>
|
551
|
+
<span class='id identifier rubyid_expectation'>expectation</span>
|
552
|
+
<span class='kw'>end</span></pre>
|
553
|
+
</td>
|
554
|
+
</tr>
|
555
|
+
</table>
|
556
|
+
</div>
|
557
|
+
|
558
|
+
<div class="method_details ">
|
559
|
+
<p class="signature " id="unstub-instance_method">
|
560
|
+
|
561
|
+
- (<tt><span class='object_link'><a href="../Object.html" title="Object (class)">Object</a></span></tt>) <strong>unstub</strong>(*method_names)
|
562
|
+
|
563
|
+
|
564
|
+
|
565
|
+
</p><div class="docstring">
|
566
|
+
<div class="discussion">
|
567
|
+
|
568
|
+
<p>Removes the specified stubbed methods (added by calls to <span class='object_link'><a href="#expects-instance_method" title="Mocha::ObjectMethods#expects (method)">#expects</a></span> or
|
569
|
+
<span class='object_link'><a href="#stubs-instance_method" title="Mocha::ObjectMethods#stubs (method)">#stubs</a></span>) and all expectations associated with them.</p>
|
570
|
+
|
571
|
+
<p>Restores the original behaviour of the methods before they were stubbed.</p>
|
572
|
+
|
573
|
+
<p>WARNING: If you <span class='object_link'><a href="#unstub-instance_method" title="Mocha::ObjectMethods#unstub (method)">#unstub</a></span> a method which still has unsatisfied
|
574
|
+
expectations, you may be removing the only way those expectations can be
|
575
|
+
satisfied. Use <span class='object_link'><a href="#unstub-instance_method" title="Mocha::ObjectMethods#unstub (method)">#unstub</a></span> with care.</p>
|
576
|
+
|
577
|
+
|
578
|
+
</div>
|
579
|
+
</div>
|
580
|
+
<div class="tags">
|
581
|
+
|
582
|
+
<div class="examples">
|
583
|
+
<h3>Examples:</h3>
|
584
|
+
|
585
|
+
<h4><div class='inline'>
|
586
|
+
<p>Stubbing and unstubbing a method on a real (non-mock) object.</p>
|
587
|
+
</div></h4>
|
588
|
+
<pre class="example code"><span class='id identifier rubyid_multiplier'>multiplier</span> <span class='op'>=</span> <span class='const'>Multiplier</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
|
589
|
+
<span class='id identifier rubyid_multiplier'>multiplier</span><span class='period'>.</span><span class='id identifier rubyid_double'>double</span><span class='lparen'>(</span><span class='int'>2</span><span class='rparen'>)</span> <span class='comment'># => 4
|
590
|
+
</span><span class='id identifier rubyid_multiplier'>multiplier</span><span class='period'>.</span><span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='symbol'>:double</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_raises'>raises</span> <span class='comment'># new behaviour defined
|
591
|
+
</span><span class='id identifier rubyid_multiplier'>multiplier</span><span class='period'>.</span><span class='id identifier rubyid_double'>double</span><span class='lparen'>(</span><span class='int'>2</span><span class='rparen'>)</span> <span class='comment'># => raises exception
|
592
|
+
</span><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> <span class='comment'># original behaviour restored
|
593
|
+
</span><span class='id identifier rubyid_multiplier'>multiplier</span><span class='period'>.</span><span class='id identifier rubyid_double'>double</span><span class='lparen'>(</span><span class='int'>2</span><span class='rparen'>)</span> <span class='comment'># => 4</span></pre>
|
594
|
+
|
595
|
+
<h4><div class='inline'>
|
596
|
+
<p>Unstubbing multiple methods on a real (non-mock) object.</p>
|
597
|
+
</div></h4>
|
598
|
+
<pre class="example 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>
|
599
|
+
|
600
|
+
<span class='comment'># exactly equivalent to
|
601
|
+
</span>
|
602
|
+
<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>
|
603
|
+
<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></pre>
|
604
|
+
|
605
|
+
</div>
|
606
|
+
<h3>Parameters:</h3>
|
607
|
+
<ul class="param">
|
608
|
+
|
609
|
+
<li>
|
610
|
+
|
611
|
+
<span class='name'>method_names</span>
|
612
|
+
|
613
|
+
|
614
|
+
<span class='type'>(<tt>Array<Symbol></tt>)</span>
|
615
|
+
|
616
|
+
|
617
|
+
|
618
|
+
—
|
619
|
+
<div class='inline'>
|
620
|
+
<p>names of methods to unstub.</p>
|
621
|
+
</div>
|
622
|
+
|
623
|
+
</li>
|
624
|
+
|
625
|
+
</ul>
|
626
|
+
|
627
|
+
|
628
|
+
</div><table class="source_code">
|
629
|
+
<tr>
|
630
|
+
<td>
|
631
|
+
<pre class="lines">
|
632
|
+
|
633
|
+
|
634
|
+
151
|
635
|
+
152
|
636
|
+
153
|
637
|
+
154
|
638
|
+
155
|
639
|
+
156
|
640
|
+
157</pre>
|
641
|
+
</td>
|
642
|
+
<td>
|
643
|
+
<pre class="code"><span class="info file"># File 'lib/mocha/object.rb', line 151</span>
|
644
|
+
|
645
|
+
<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>
|
646
|
+
<span class='id identifier rubyid_mockery'>mockery</span> <span class='op'>=</span> <span class='const'>Mocha</span><span class='op'>::</span><span class='const'>Mockery</span><span class='period'>.</span><span class='id identifier rubyid_instance'>instance</span>
|
647
|
+
<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>
|
648
|
+
<span class='id identifier rubyid_method'>method</span> <span class='op'>=</span> <span class='id identifier rubyid_stubba_method'>stubba_method</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_stubba_object'>stubba_object</span><span class='comma'>,</span> <span class='id identifier rubyid_method_name'>method_name</span><span class='rparen'>)</span>
|
649
|
+
<span class='id identifier rubyid_mockery'>mockery</span><span class='period'>.</span><span class='id identifier rubyid_stubba'>stubba</span><span class='period'>.</span><span class='id identifier rubyid_unstub'>unstub</span><span class='lparen'>(</span><span class='id identifier rubyid_method'>method</span><span class='rparen'>)</span>
|
650
|
+
<span class='kw'>end</span>
|
651
|
+
<span class='kw'>end</span></pre>
|
652
|
+
</td>
|
653
|
+
</tr>
|
654
|
+
</table>
|
655
|
+
</div>
|
656
|
+
|
657
|
+
</div>
|
658
|
+
|
659
|
+
</div>
|
660
|
+
|
661
|
+
<div id="footer">
|
662
|
+
Generated on Thu Apr 19 10:54:34 2012 by
|
663
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
664
|
+
0.7.5 (ruby-1.9.3).
|
665
|
+
</div>
|
666
|
+
|
667
|
+
</body>
|
668
|
+
</html>
|