mocha 1.7.0 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +4 -9
  3. data/README.md +17 -16
  4. data/RELEASE.md +10 -0
  5. data/Rakefile +6 -13
  6. data/bin/build-matrix +16 -2
  7. data/docs/CNAME +1 -0
  8. data/docs/Mocha.html +127 -0
  9. data/docs/Mocha/API.html +1056 -0
  10. data/docs/Mocha/ClassMethods.html +267 -0
  11. data/docs/Mocha/Configuration.html +626 -0
  12. data/docs/Mocha/Expectation.html +2709 -0
  13. data/docs/Mocha/ExpectationError.html +157 -0
  14. data/docs/Mocha/ExpectationErrorFactory.html +269 -0
  15. data/docs/Mocha/Hooks.html +385 -0
  16. data/docs/Mocha/Integration.html +125 -0
  17. data/docs/Mocha/Integration/MiniTest.html +123 -0
  18. data/docs/Mocha/Integration/MiniTest/Adapter.html +165 -0
  19. data/docs/Mocha/Integration/TestUnit.html +123 -0
  20. data/docs/Mocha/Integration/TestUnit/Adapter.html +165 -0
  21. data/docs/Mocha/Mock.html +1197 -0
  22. data/docs/Mocha/ObjectMethods.html +712 -0
  23. data/docs/Mocha/ParameterMatchers.html +3049 -0
  24. data/docs/Mocha/ParameterMatchers/AllOf.html +154 -0
  25. data/docs/Mocha/ParameterMatchers/AnyOf.html +154 -0
  26. data/docs/Mocha/ParameterMatchers/AnyParameters.html +153 -0
  27. data/docs/Mocha/ParameterMatchers/Anything.html +153 -0
  28. data/docs/Mocha/ParameterMatchers/Base.html +448 -0
  29. data/docs/Mocha/ParameterMatchers/Equals.html +154 -0
  30. data/docs/Mocha/ParameterMatchers/EquivalentUri.html +153 -0
  31. data/docs/Mocha/ParameterMatchers/HasEntries.html +154 -0
  32. data/docs/Mocha/ParameterMatchers/HasEntry.html +154 -0
  33. data/docs/Mocha/ParameterMatchers/HasKey.html +154 -0
  34. data/docs/Mocha/ParameterMatchers/HasValue.html +154 -0
  35. data/docs/Mocha/ParameterMatchers/Includes.html +154 -0
  36. data/docs/Mocha/ParameterMatchers/InstanceOf.html +154 -0
  37. data/docs/Mocha/ParameterMatchers/IsA.html +153 -0
  38. data/docs/Mocha/ParameterMatchers/KindOf.html +154 -0
  39. data/docs/Mocha/ParameterMatchers/Not.html +154 -0
  40. data/docs/Mocha/ParameterMatchers/Optionally.html +153 -0
  41. data/docs/Mocha/ParameterMatchers/RegexpMatches.html +154 -0
  42. data/docs/Mocha/ParameterMatchers/RespondsWith.html +154 -0
  43. data/docs/Mocha/ParameterMatchers/YamlEquivalent.html +154 -0
  44. data/docs/Mocha/Sequence.html +149 -0
  45. data/docs/Mocha/StateMachine.html +539 -0
  46. data/docs/Mocha/StateMachine/State.html +141 -0
  47. data/docs/Mocha/StateMachine/StatePredicate.html +141 -0
  48. data/docs/Mocha/StubbingError.html +150 -0
  49. data/docs/Mocha/UnexpectedInvocation.html +140 -0
  50. data/docs/_index.html +537 -0
  51. data/docs/class_list.html +51 -0
  52. data/docs/css/common.css +1 -0
  53. data/docs/css/full_list.css +58 -0
  54. data/docs/css/style.css +496 -0
  55. data/docs/file.COPYING.html +81 -0
  56. data/docs/file.MIT-LICENSE.html +85 -0
  57. data/docs/file.README.html +418 -0
  58. data/docs/file.RELEASE.html +875 -0
  59. data/docs/file_list.html +71 -0
  60. data/docs/frames.html +17 -0
  61. data/docs/index.html +418 -0
  62. data/docs/js/app.js +292 -0
  63. data/docs/js/full_list.js +216 -0
  64. data/docs/js/jquery.js +4 -0
  65. data/docs/method_list.html +571 -0
  66. data/docs/top-level-namespace.html +118 -0
  67. data/lib/mocha/inspect.rb +1 -1
  68. data/lib/mocha/version.rb +1 -1
  69. data/mocha.gemspec +2 -3
  70. data/test/unit/object_inspect_test.rb +10 -0
  71. data/yard-templates/default/layout/html/google_analytics.erb +6 -9
  72. metadata +68 -36
@@ -0,0 +1,165 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>
7
+ Module: Mocha::Integration::TestUnit::Adapter
8
+
9
+ &mdash; 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::Integration::TestUnit::Adapter";
19
+ relpath = '../../../';
20
+ </script>
21
+
22
+
23
+ <script type="text/javascript" charset="utf-8" src="../../../js/jquery.js"></script>
24
+
25
+ <script type="text/javascript" charset="utf-8" src="../../../js/app.js"></script>
26
+
27
+
28
+ </head>
29
+ <body>
30
+ <div class="nav_wrap">
31
+ <iframe id="nav" src="../../../class_list.html?1"></iframe>
32
+ <div id="resizer"></div>
33
+ </div>
34
+
35
+ <div id="main" tabindex="-1">
36
+ <div id="header">
37
+ <div id="menu">
38
+
39
+ <a href="../../../_index.html">Index (A)</a> &raquo;
40
+ <span class='title'><span class='object_link'><a href="../../../Mocha.html" title="Mocha (module)">Mocha</a></span></span> &raquo; <span class='title'><span class='object_link'><a href="../../Integration.html" title="Mocha::Integration (module)">Integration</a></span></span> &raquo; <span class='title'><span class='object_link'><a href="../TestUnit.html" title="Mocha::Integration::TestUnit (module)">TestUnit</a></span></span>
41
+ &raquo;
42
+ <span class="title">Adapter</span>
43
+
44
+ </div>
45
+
46
+ <div id="search">
47
+
48
+ <a class="full_list_link" id="class_list_link"
49
+ href="../../../class_list.html">
50
+
51
+ <svg width="24" height="24">
52
+ <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
53
+ <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
54
+ <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
55
+ </svg>
56
+ </a>
57
+
58
+ </div>
59
+ <div class="clear"></div>
60
+ </div>
61
+
62
+ <div id="content"><h1>Module: Mocha::Integration::TestUnit::Adapter
63
+
64
+
65
+
66
+ </h1>
67
+ <div class="box_info">
68
+
69
+
70
+
71
+
72
+
73
+
74
+ <dl>
75
+ <dt>Includes:</dt>
76
+ <dd><span class='object_link'><a href="../../API.html" title="Mocha::API (module)">API</a></span></dd>
77
+ </dl>
78
+
79
+
80
+
81
+
82
+
83
+
84
+ <dl>
85
+ <dt>Defined in:</dt>
86
+ <dd>lib/mocha/integration/test_unit/adapter.rb</dd>
87
+ </dl>
88
+
89
+ </div>
90
+
91
+ <h2>Overview</h2><div class="docstring">
92
+ <div class="discussion">
93
+
94
+ <p>Integrates Mocha into recent versions of Test::Unit.</p>
95
+
96
+ <p>See the source code for an example of how to integrate Mocha into a test
97
+ library.</p>
98
+
99
+
100
+ </div>
101
+ </div>
102
+ <div class="tags">
103
+
104
+
105
+ </div>
106
+
107
+
108
+
109
+
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+
118
+
119
+ <h2>Method Summary</h2>
120
+
121
+ <h3 class="inherited">Methods included from <span class='object_link'><a href="../../API.html" title="Mocha::API (module)">API</a></span></h3>
122
+ <p class="inherited"><span class='object_link'><a href="../../API.html#mock-instance_method" title="Mocha::API#mock (method)">#mock</a></span>, <span class='object_link'><a href="../../API.html#sequence-instance_method" title="Mocha::API#sequence (method)">#sequence</a></span>, <span class='object_link'><a href="../../API.html#states-instance_method" title="Mocha::API#states (method)">#states</a></span>, <span class='object_link'><a href="../../API.html#stub-instance_method" title="Mocha::API#stub (method)">#stub</a></span>, <span class='object_link'><a href="../../API.html#stub_everything-instance_method" title="Mocha::API#stub_everything (method)">#stub_everything</a></span></p>
123
+
124
+
125
+
126
+
127
+
128
+
129
+
130
+
131
+
132
+ <h3 class="inherited">Methods included from <span class='object_link'><a href="../../Hooks.html" title="Mocha::Hooks (module)">Hooks</a></span></h3>
133
+ <p class="inherited"><span class='object_link'><a href="../../Hooks.html#mocha_setup-instance_method" title="Mocha::Hooks#mocha_setup (method)">#mocha_setup</a></span>, <span class='object_link'><a href="../../Hooks.html#mocha_teardown-instance_method" title="Mocha::Hooks#mocha_teardown (method)">#mocha_teardown</a></span>, <span class='object_link'><a href="../../Hooks.html#mocha_verify-instance_method" title="Mocha::Hooks#mocha_verify (method)">#mocha_verify</a></span></p>
134
+
135
+
136
+
137
+
138
+
139
+
140
+
141
+
142
+
143
+ <h3 class="inherited">Methods included from <span class='object_link'><a href="../../ParameterMatchers.html" title="Mocha::ParameterMatchers (module)">ParameterMatchers</a></span></h3>
144
+ <p class="inherited"><span class='object_link'><a href="../../ParameterMatchers.html#Not-instance_method" title="Mocha::ParameterMatchers#Not (method)">#Not</a></span>, <span class='object_link'><a href="../../ParameterMatchers.html#all_of-instance_method" title="Mocha::ParameterMatchers#all_of (method)">#all_of</a></span>, <span class='object_link'><a href="../../ParameterMatchers.html#any_of-instance_method" title="Mocha::ParameterMatchers#any_of (method)">#any_of</a></span>, <span class='object_link'><a href="../../ParameterMatchers.html#any_parameters-instance_method" title="Mocha::ParameterMatchers#any_parameters (method)">#any_parameters</a></span>, <span class='object_link'><a href="../../ParameterMatchers.html#anything-instance_method" title="Mocha::ParameterMatchers#anything (method)">#anything</a></span>, <span class='object_link'><a href="../../ParameterMatchers.html#equals-instance_method" title="Mocha::ParameterMatchers#equals (method)">#equals</a></span>, <span class='object_link'><a href="../../ParameterMatchers.html#equivalent_uri-instance_method" title="Mocha::ParameterMatchers#equivalent_uri (method)">#equivalent_uri</a></span>, <span class='object_link'><a href="../../ParameterMatchers.html#has_entries-instance_method" title="Mocha::ParameterMatchers#has_entries (method)">#has_entries</a></span>, <span class='object_link'><a href="../../ParameterMatchers.html#has_entry-instance_method" title="Mocha::ParameterMatchers#has_entry (method)">#has_entry</a></span>, <span class='object_link'><a href="../../ParameterMatchers.html#has_equivalent_query_string-instance_method" title="Mocha::ParameterMatchers#has_equivalent_query_string (method)">#has_equivalent_query_string</a></span>, <span class='object_link'><a href="../../ParameterMatchers.html#has_key-instance_method" title="Mocha::ParameterMatchers#has_key (method)">#has_key</a></span>, <span class='object_link'><a href="../../ParameterMatchers.html#has_value-instance_method" title="Mocha::ParameterMatchers#has_value (method)">#has_value</a></span>, <span class='object_link'><a href="../../ParameterMatchers.html#includes-instance_method" title="Mocha::ParameterMatchers#includes (method)">#includes</a></span>, <span class='object_link'><a href="../../ParameterMatchers.html#instance_of-instance_method" title="Mocha::ParameterMatchers#instance_of (method)">#instance_of</a></span>, <span class='object_link'><a href="../../ParameterMatchers.html#is_a-instance_method" title="Mocha::ParameterMatchers#is_a (method)">#is_a</a></span>, <span class='object_link'><a href="../../ParameterMatchers.html#kind_of-instance_method" title="Mocha::ParameterMatchers#kind_of (method)">#kind_of</a></span>, <span class='object_link'><a href="../../ParameterMatchers.html#optionally-instance_method" title="Mocha::ParameterMatchers#optionally (method)">#optionally</a></span>, <span class='object_link'><a href="../../ParameterMatchers.html#regexp_matches-instance_method" title="Mocha::ParameterMatchers#regexp_matches (method)">#regexp_matches</a></span>, <span class='object_link'><a href="../../ParameterMatchers.html#responds_with-instance_method" title="Mocha::ParameterMatchers#responds_with (method)">#responds_with</a></span>, <span class='object_link'><a href="../../ParameterMatchers.html#yaml_equivalent-instance_method" title="Mocha::ParameterMatchers#yaml_equivalent (method)">#yaml_equivalent</a></span></p>
145
+
146
+
147
+ <script async src="https://www.googletagmanager.com/gtag/js?id=UA-625523-7"></script>
148
+ <script>
149
+ window.dataLayer = window.dataLayer || [];
150
+ function gtag(){dataLayer.push(arguments);}
151
+ gtag('js', new Date());
152
+
153
+ gtag('config', 'UA-625523-7');
154
+ </script>
155
+ </div>
156
+
157
+ <div id="footer">
158
+ Generated on Tue Jan 15 17:13:06 2019 by
159
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
160
+ 0.9.16 (ruby-2.5.3).
161
+ </div>
162
+
163
+ </div>
164
+ </body>
165
+ </html>
@@ -0,0 +1,1197 @@
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
+ &mdash; 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> &raquo;
40
+ <span class='title'><span class='object_link'><a href="../Mocha.html" title="Mocha (module)">Mocha</a></span></span>
41
+ &raquo;
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&#39;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'># =&gt; 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'># =&gt; 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'># =&gt; 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) &#x21d2; 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) &#x21d2; 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) &#x21d2; 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) &#x21d2; 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) &#x21d2; 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) &#x21d2; 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, &amp;block) &#x21d2; <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'>&amp;</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'>&amp;&amp;</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'>&quot;</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'>&#39; 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'>&quot;</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'>&amp;</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'>&amp;&amp;</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'>&amp;</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'>&lt;&lt;</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) &#x21d2; <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) &#x21d2; <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'># =&gt; 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'>=&gt;</span> <span class='symbol'>:result_one</span><span class='comma'>,</span> <span class='symbol'>:expected_method_two</span> <span class='op'>=&gt;</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
+ &mdash;
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
+ &mdash;
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
+ &mdash;
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) &#x21d2; <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) &#x21d2; <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'>&#39;</span><span class='tstring_content'>sheep</span><span class='tstring_end'>&#39;</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'># =&gt; 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'># =&gt; 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'>&#39;</span><span class='tstring_content'>sheep</span><span class='tstring_end'>&#39;</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'># =&gt; 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'># =&gt; 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'># =&gt; 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'>&#39;</span><span class='tstring_content'>sheep_class</span><span class='tstring_end'>&#39;</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'># =&gt; 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'># =&gt; 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'># =&gt; 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'># =&gt; 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
+ &mdash;
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
+ &mdash;
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) &#x21d2; <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'>&quot;</span><span class='tstring_content'>some awkward code we don&#39;t want to call</span><span class='tstring_end'>&quot;</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'>&#39;</span><span class='tstring_content'>sheep</span><span class='tstring_end'>&#39;</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'># =&gt; 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'># =&gt; 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'># =&gt; 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
+ &mdash;
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
+ &mdash;
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) &#x21d2; <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) &#x21d2; <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'>=&gt;</span> <span class='symbol'>:result_one</span><span class='comma'>,</span> <span class='symbol'>:stubbed_method_two</span> <span class='op'>=&gt;</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
+ &mdash;
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
+ &mdash;
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
+ &mdash;
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) &#x21d2; <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(&#39;mock&#39;) do
1128
+ object.stubs(:stubbed_method).returns(:result_one)
1129
+ object.stubbed_method # =&gt; :result_one
1130
+ object.unstub(:stubbed_method)
1131
+ object.stubbed_method # =&gt; unexpected invocation: #&lt;Mock:mock&gt;.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
+ &mdash;
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>