forked from rspec/rspec.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBasicObject.html
373 lines (373 loc) · 16.9 KB
/
BasicObject.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
Class: BasicObject
— Documentation by YARD 0.8.7.6
</title>
<link rel="stylesheet" href="/stylesheets/docs/style.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="/stylesheets/docs/common.css" type="text/css" charset="utf-8" />
<script type="text/javascript" charset="utf-8">
hasFrames = window.top.frames.main ? true : false;
relpath = '';
framesUrl = "frames.html#!BasicObject.html";
</script>
<script type="text/javascript" charset="utf-8" src="/javascripts/docs/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="/javascripts/docs/app.js"></script>
</head>
<body>
<div id="header">
<div id="menu">
<a href="_index.html">Index (B)</a> »
<span class="title">BasicObject</span>
<div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
</div>
<div id="search">
<a class="full_list_link" id="class_list_link"
href="class_list.html">
Class List
</a>
<a class="full_list_link" id="method_list_link"
href="method_list.html">
Method List
</a>
<a class="full_list_link" id="file_list_link"
href="file_list.html">
File List
</a>
</div>
<div class="clear"></div>
</div>
<iframe id="search_frame"></iframe>
<div id="content"><h1>Class: BasicObject
</h1>
<dl class="box">
<dt class="r1 last">Defined in:</dt>
<dd class="r1 last">lib/rspec/mocks/syntax.rb</dd>
</dl>
<div class="clear"></div>
<h2>Overview</h2><div class="docstring">
<div class="discussion">
<p>The legacy <code>:should</code> syntax adds the following methods directly to
<code>BasicObject</code> so that they are available off of any object. Note, however,
that this syntax does not always play nice with delegate/proxy objects.
We recommend you use the non-monkeypatching <code>:expect</code> syntax instead.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">See Also:</p>
<ul class="see">
<li><span class='object_link'><a href="Class.html" title="Class (class)">Class</a></span></li>
</ul>
</div>
<h2>
Instance Method Summary
<small>(<a href="#" class="summary_toggle">collapse</a>)</small>
</h2>
<ul class="summary">
<li class="public ">
<span class="summary_signature">
<a href="#as_null_object-instance_method" title="#as_null_object (instance method)">- (Object) <strong>as_null_object</strong> </a>
</span>
<span class="summary_desc"><div class='inline'><p>Tells the object to respond to all messages.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#null_object%3F-instance_method" title="#null_object? (instance method)">- (Object) <strong>null_object?</strong> </a>
</span>
<span class="summary_desc"><div class='inline'><p>Returns true if this object has received <code>as_null_object</code>.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#should_not_receive-instance_method" title="#should_not_receive (instance method)">- (Object) <strong>should_not_receive</strong> </a>
</span>
<span class="summary_desc"><div class='inline'><p>Sets and expectation that this object should <em>not</em> receive a message during this example.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#should_receive-instance_method" title="#should_receive (instance method)">- (Object) <strong>should_receive</strong> </a>
</span>
<span class="summary_desc"><div class='inline'><p>Sets an expectation that this object should receive a message before the end of the example.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#stub-instance_method" title="#stub (instance method)">- (Object) <strong>stub</strong> </a>
</span>
<span class="summary_desc"><div class='inline'><p>Tells the object to respond to the message with the specified value.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#stub_chain-instance_method" title="#stub_chain (instance method)">- (Object) <strong>stub_chain</strong> </a>
</span>
<span class="summary_desc"><div class='inline'><p>Stubs a chain of methods.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#unstub-instance_method" title="#unstub (instance method)">- (Object) <strong>unstub</strong> </a>
</span>
<span class="summary_desc"><div class='inline'><p>Removes a stub.</p>
</div></span>
</li>
</ul>
<div id="instance_method_details" class="method_details_list">
<h2>Instance Method Details</h2>
<div class="method_details first">
<h3 class="signature first" id="as_null_object-instance_method">
- (<tt>Object</tt>) <strong>as_null_object</strong>
</h3><div class="docstring">
<div class="discussion">
<div class="note notetag">
<strong>Note:</strong>
<div class='inline'><p>This is only available when you have enabled the <code>should</code> syntax.</p>
</div>
</div>
<p>Tells the object to respond to all messages. If specific stub values
are declared, they'll work as expected. If not, the receiver is
returned.</p>
</div>
</div>
<div class="tags">
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/rspec/mocks/syntax.rb', line 283</span>
</pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="null_object?-instance_method">
- (<tt>Object</tt>) <strong>null_object?</strong>
</h3><div class="docstring">
<div class="discussion">
<div class="note notetag">
<strong>Note:</strong>
<div class='inline'><p>This is only available when you have enabled the <code>should</code> syntax.</p>
</div>
</div>
<p>Returns true if this object has received <code>as_null_object</code></p>
</div>
</div>
<div class="tags">
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/rspec/mocks/syntax.rb', line 294</span>
</pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="should_not_receive-instance_method">
- (<tt>Object</tt>) <strong>should_not_receive</strong>
</h3><div class="docstring">
<div class="discussion">
<p>Sets and expectation that this object should <em>not</em> receive a message
during this example.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">See Also:</p>
<ul class="see">
<li><span class='object_link'><a href="RSpec/Mocks/ExampleMethods.html#expect-instance_method" title="RSpec::Mocks::ExampleMethods#expect (method)">RSpec::Mocks::ExampleMethods#expect</a></span></li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/rspec/mocks/syntax.rb', line 225</span>
</pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="should_receive-instance_method">
- (<tt>Object</tt>) <strong>should_receive</strong>
</h3><div class="docstring">
<div class="discussion">
<div class="note notetag">
<strong>Note:</strong>
<div class='inline'><p>This is only available when you have enabled the <code>should</code> syntax.</p>
</div>
</div>
<p>Sets an expectation that this object should receive a message before
the end of the example.</p>
</div>
</div>
<div class="tags">
<div class="examples">
<p class="tag_title">Examples:</p>
<pre class="example code"><code><span class='id identifier rubyid_logger'>logger</span> <span class='op'>=</span> <span class='id identifier rubyid_double'>double</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>logger</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
<span class='id identifier rubyid_thing_that_logs'>thing_that_logs</span> <span class='op'>=</span> <span class='const'>ThingThatLogs</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_logger'>logger</span><span class='rparen'>)</span>
<span class='id identifier rubyid_logger'>logger</span><span class='period'>.</span><span class='id identifier rubyid_should_receive'>should_receive</span><span class='lparen'>(</span><span class='symbol'>:log</span><span class='rparen'>)</span>
<span class='id identifier rubyid_thing_that_logs'>thing_that_logs</span><span class='period'>.</span><span class='id identifier rubyid_do_something_that_logs_a_message'>do_something_that_logs_a_message</span></code></pre>
</div>
<p class="tag_title">See Also:</p>
<ul class="see">
<li><span class='object_link'><a href="RSpec/Mocks/ExampleMethods.html#expect-instance_method" title="RSpec::Mocks::ExampleMethods#expect (method)">RSpec::Mocks::ExampleMethods#expect</a></span></li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/rspec/mocks/syntax.rb', line 212</span>
</pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="stub-instance_method">
- (<tt>Object</tt>) <strong>stub</strong>
</h3><div class="docstring">
<div class="discussion">
<div class="note notetag">
<strong>Note:</strong>
<div class='inline'><p>This is only available when you have enabled the <code>should</code> syntax.</p>
</div>
</div>
<p>Tells the object to respond to the message with the specified value.</p>
</div>
</div>
<div class="tags">
<div class="examples">
<p class="tag_title">Examples:</p>
<pre class="example code"><code><span class='id identifier rubyid_counter'>counter</span><span class='period'>.</span><span class='id identifier rubyid_stub'>stub</span><span class='lparen'>(</span><span class='symbol'>:count</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_and_return'>and_return</span><span class='lparen'>(</span><span class='int'>37</span><span class='rparen'>)</span>
<span class='id identifier rubyid_counter'>counter</span><span class='period'>.</span><span class='id identifier rubyid_stub'>stub</span><span class='lparen'>(</span><span class='symbol'>:count</span> <span class='op'>=></span> <span class='int'>37</span><span class='rparen'>)</span>
<span class='id identifier rubyid_counter'>counter</span><span class='period'>.</span><span class='id identifier rubyid_stub'>stub</span><span class='lparen'>(</span><span class='symbol'>:count</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='int'>37</span> <span class='rbrace'>}</span></code></pre>
</div>
<p class="tag_title">See Also:</p>
<ul class="see">
<li><span class='object_link'><a href="RSpec/Mocks/ExampleMethods.html#allow-instance_method" title="RSpec::Mocks::ExampleMethods#allow (method)">RSpec::Mocks::ExampleMethods#allow</a></span></li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/rspec/mocks/syntax.rb', line 230</span>
</pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="stub_chain-instance_method">
<span class="overload">- (<tt>Object</tt>) <strong>stub_chain</strong>(method1, method2) </span>
<span class="overload">- (<tt>Object</tt>) <strong>stub_chain</strong>("method1.method2") </span>
<span class="overload">- (<tt>Object</tt>) <strong>stub_chain</strong>(method1, method_to_value_hash) </span>
</h3><div class="docstring">
<div class="discussion">
<div class="note notetag">
<strong>Note:</strong>
<div class='inline'><p>This is only available when you have enabled the <code>should</code> syntax.</p>
</div>
</div>
<p>Stubs a chain of methods.</p>
<h2>Warning:</h2>
<p>Chains can be arbitrarily long, which makes it quite painless to
violate the Law of Demeter in violent ways, so you should consider any
use of <code>stub_chain</code> a code smell. Even though not all code smells
indicate real problems (think fluent interfaces), <code>stub_chain</code> still
results in brittle examples. For example, if you write
<code>foo.stub_chain(:bar, :baz => 37)</code> in a spec and then the
implementation calls <code>foo.baz.bar</code>, the stub will not work.</p>
</div>
</div>
<div class="tags">
<div class="examples">
<p class="tag_title">Examples:</p>
<pre class="example code"><code><span class='id identifier rubyid_double'>double</span><span class='period'>.</span><span class='id identifier rubyid_stub_chain'>stub_chain</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>foo.bar</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='symbol'>:baz</span> <span class='rbrace'>}</span>
<span class='id identifier rubyid_double'>double</span><span class='period'>.</span><span class='id identifier rubyid_stub_chain'>stub_chain</span><span class='lparen'>(</span><span class='symbol'>:foo</span><span class='comma'>,</span> <span class='symbol'>:bar</span> <span class='op'>=></span> <span class='symbol'>:baz</span><span class='rparen'>)</span>
<span class='id identifier rubyid_double'>double</span><span class='period'>.</span><span class='id identifier rubyid_stub_chain'>stub_chain</span><span class='lparen'>(</span><span class='symbol'>:foo</span><span class='comma'>,</span> <span class='symbol'>:bar</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='symbol'>:baz</span> <span class='rbrace'>}</span>
<span class='comment'># Given any of ^^ these three forms ^^:
</span> <span class='id identifier rubyid_double'>double</span><span class='period'>.</span><span class='id identifier rubyid_foo'>foo</span><span class='period'>.</span><span class='id identifier rubyid_bar'>bar</span> <span class='comment'># => :baz
</span>
<span class='comment'># Common use in Rails/ActiveRecord:
</span> <span class='const'>Article</span><span class='period'>.</span><span class='id identifier rubyid_stub_chain'>stub_chain</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>recent.published</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='lbracket'>[</span><span class='const'>Article</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='rbracket'>]</span> <span class='rbrace'>}</span></code></pre>
</div>
<p class="tag_title">See Also:</p>
<ul class="see">
<li><span class='object_link'><a href="RSpec/Mocks/ExampleMethods.html#receive_message_chain-instance_method" title="RSpec::Mocks::ExampleMethods#receive_message_chain (method)">RSpec::Mocks::ExampleMethods#receive_message_chain</a></span></li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/rspec/mocks/syntax.rb', line 252</span>
</pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="unstub-instance_method">
- (<tt>Object</tt>) <strong>unstub</strong>
</h3><div class="docstring">
<div class="discussion">
<div class="note notetag">
<strong>Note:</strong>
<div class='inline'><p>This is only available when you have enabled the <code>should</code> syntax.</p>
</div>
</div>
<p>Removes a stub. On a double, the object will no longer respond to
<code>message</code>. On a real object, the original method (if it exists) is
restored.</p>
<p>This is rarely used, but can be useful when a stub is set up during a
shared <code>before</code> hook for the common case, but you want to replace it
for a special case.</p>
</div>
</div>
<div class="tags">
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/rspec/mocks/syntax.rb', line 241</span>
</pre>
</td>
</tr>
</table>
</div>
</div>
</div>
<div id="footer">
Generated on Fri Jun 12 08:15:01 2015 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.8.7.6 (ruby-2.1.5).
</div>
</body>
</html>