forked from rspec/rspec.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExampleMethods.html
338 lines (338 loc) · 17.1 KB
/
ExampleMethods.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
Module: RSpec::Rails::ViewExampleGroup::ExampleMethods
— Documentation by YARD 0.9.24
</title>
<link rel="stylesheet" href="/documentation/4.0/rspec-rails/css/style.css" type="text/css" />
<link rel="stylesheet" href="/documentation/4.0/rspec-rails/css/common.css" type="text/css" />
<link rel="stylesheet" href="/documentation/4.0/rspec-rails/css/rspec.css" type="text/css" />
<script type="text/javascript">
pathId = "RSpec::Rails::ViewExampleGroup::ExampleMethods";
relpath = '../../../';
</script>
<script type="text/javascript" charset="utf-8" src="/documentation/4.0/rspec-rails/js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="/documentation/4.0/rspec-rails/js/app.js"></script>
</head>
<body>
<div class="nav_wrap">
<iframe id="nav" src="../../../class_list.html?1"></iframe>
<div id="resizer"></div>
</div>
<div id="main" tabindex="-1">
<div id="header">
<div id="menu">
<a href="../../../_index.html">Index (E)</a> »
<span class='title'><span class='object_link'><a href="../../../RSpec.html" title="RSpec (module)">RSpec</a></span></span> » <span class='title'><span class='object_link'><a href="../../Rails.html" title="RSpec::Rails (module)">Rails</a></span></span> » <span class='title'><span class='object_link'><a href="../ViewExampleGroup.html" title="RSpec::Rails::ViewExampleGroup (module)">ViewExampleGroup</a></span></span>
»
<span class="title">ExampleMethods</span>
</div>
<div id="search">
<a class="full_list_link" id="class_list_link"
href="../../../class_list.html">
<svg width="24" height="24">
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
</svg>
</a>
</div>
<div class="clear"></div>
</div>
<div id="content"><h1>Module: RSpec::Rails::ViewExampleGroup::ExampleMethods
</h1>
<div class="box_info">
<dl>
<dt>Extended by:</dt>
<dd>ActiveSupport::Concern</dd>
</dl>
<dl>
<dt>Defined in:</dt>
<dd>lib/rspec/rails/example/view_example_group.rb</dd>
</dl>
</div>
<h2>Overview</h2><div class="docstring">
<div class="discussion">
<p>DSL exposed to view specs.</p>
</div>
</div>
<div class="tags">
</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="#params-instance_method" title="#params (instance method)">#<strong>params</strong> ⇒ Object </a>
</span>
<span class="summary_desc"><div class='inline'><p>Provides access to the params hash that will be available within the view.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#render-instance_method" title="#render (instance method)">#<strong>render</strong>(options = {}, local_assigns = {}, &block) ⇒ Object </a>
</span>
<span class="summary_desc"><div class='inline'><p>Delegates to ActionView::Base#render, so see documentation on that for more info.</p>
</div></span>
</li>
<li class="public deprecated">
<span class="summary_signature">
<a href="#response-instance_method" title="#response (instance method)">#<strong>response</strong> ⇒ Object </a>
</span>
<span class="deprecated note title">deprecated</span>
<span class="summary_desc"><strong>Deprecated.</strong> <div class='inline'><p>Use <code>rendered</code> instead.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#stub_template-instance_method" title="#stub_template (instance method)">#<strong>stub_template</strong>(hash) ⇒ Object </a>
</span>
<span class="summary_desc"><div class='inline'><p>Simulates the presence of a template on the file system by adding a Rails' FixtureResolver to the front of the view_paths list.</p>
</div></span>
</li>
<li class="public deprecated">
<span class="summary_signature">
<a href="#template-instance_method" title="#template (instance method)">#<strong>template</strong> ⇒ Object </a>
</span>
<span class="deprecated note title">deprecated</span>
<span class="summary_desc"><strong>Deprecated.</strong> <div class='inline'><p>Use <code>view</code> instead.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#view-instance_method" title="#view (instance method)">#<strong>view</strong> ⇒ Object </a>
</span>
<span class="summary_desc"><div class='inline'><p>The instance of <code>ActionView::Base</code> that is used to render the template.</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="params-instance_method">
#<strong>params</strong> ⇒ <tt>Object</tt>
</h3><div class="docstring">
<div class="discussion">
<p>Provides access to the params hash that will be available within the
view.</p>
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='symbol'>:foo</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>bar</span><span class='tstring_end'>'</span></span>
</code></pre>
</div>
</div>
<div class="tags">
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
99
100
101</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/rspec/rails/example/view_example_group.rb', line 99</span>
<span class='kw'>def</span> <span class='id identifier rubyid_params'>params</span>
<span class='id identifier rubyid_controller'>controller</span><span class='period'>.</span><span class='id identifier rubyid_params'>params</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="render-instance_method">
<span class="overload">#<strong>render</strong> ⇒ <tt>Object</tt> </span>
<span class="overload">#<strong>render</strong>({partial: path_to_file}) ⇒ <tt>Object</tt> </span>
<span class="overload">#<strong>render</strong>({partial: path_to_file}, {... locals ...}) ⇒ <tt>Object</tt> </span>
<span class="overload">#<strong>render</strong>({partial: path_to_file}, {... locals ...}) ⇒ <tt>Object</tt> </span>
</h3><div class="docstring">
<div class="discussion">
<p>Delegates to ActionView::Base#render, so see documentation on that
for more info.</p>
<p>The only addition is that you can call render with no arguments, and
RSpec will pass the top level description to render:</p>
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_describe'>describe</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>widgets/new.html.erb</span><span class='tstring_end'>"</span></span> <span class='kw'>do</span>
<span class='id identifier rubyid_it'>it</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>shows all the widgets</span><span class='tstring_end'>"</span></span> <span class='kw'>do</span>
<span class='id identifier rubyid_render'>render</span> <span class='comment'># => view.render(file: "widgets/new.html.erb")
</span> <span class='comment'># ...
</span> <span class='kw'>end</span>
<span class='kw'>end</span>
</code></pre>
</div>
</div>
<div class="tags">
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
66
67
68
69</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/rspec/rails/example/view_example_group.rb', line 66</span>
<span class='kw'>def</span> <span class='id identifier rubyid_render'>render</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='id identifier rubyid_local_assigns'>local_assigns</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
<span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='id identifier rubyid__default_render_options'>_default_render_options</span> <span class='kw'>if</span> <span class='const'>Hash</span> <span class='op'>===</span> <span class='id identifier rubyid_options'>options</span> <span class='op'>&&</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_empty?'>empty?</span>
<span class='kw'>super</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='id identifier rubyid_local_assigns'>local_assigns</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="response-instance_method">
#<strong>response</strong> ⇒ <tt>Object</tt>
</h3><div class="docstring">
<div class="discussion">
<div class="note deprecated"><strong>Deprecated.</strong> <div class='inline'><p>Use <code>rendered</code> instead.</p>
</div></div>
</div>
</div>
<div class="tags">
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
110
111
112
113
114
115
116
117
118
119
120
121
122
123</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/rspec/rails/example/view_example_group.rb', line 110</span>
<span class='kw'>def</span> <span class='id identifier rubyid_response'>response</span>
<span class='comment'># `assert_template` expects `response` to implement a #body method
</span> <span class='comment'># like an `ActionDispatch::Response` does to force the view to
</span> <span class='comment'># render. For backwards compatibility, we use #response as an alias
</span> <span class='comment'># for #rendered, but it needs to implement #body to avoid
</span> <span class='comment'># `assert_template` raising a `NoMethodError`.
</span> <span class='kw'>unless</span> <span class='id identifier rubyid_rendered'>rendered</span><span class='period'>.</span><span class='id identifier rubyid_respond_to?'>respond_to?</span><span class='lparen'>(</span><span class='symbol'>:body</span><span class='rparen'>)</span>
<span class='kw'>def</span> <span class='id identifier rubyid_rendered'>rendered</span><span class='period'>.</span><span class='id identifier rubyid_body'>body</span>
<span class='kw'>self</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_rendered'>rendered</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="stub_template-instance_method">
#<strong>stub_template</strong>(hash) ⇒ <tt>Object</tt>
</h3><div class="docstring">
<div class="discussion">
<p>Simulates the presence of a template on the file system by adding a
Rails' FixtureResolver to the front of the view_paths list. Designed to
help isolate view examples from partials rendered by the view template
that is the subject of the example.</p>
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_stub_template'>stub_template</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>widgets/_widget.html.erb</span><span class='tstring_end'>"</span></span> <span class='op'>=></span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>This content.</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
</code></pre>
</div>
</div>
<div class="tags">
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
91
92
93</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/rspec/rails/example/view_example_group.rb', line 91</span>
<span class='kw'>def</span> <span class='id identifier rubyid_stub_template'>stub_template</span><span class='lparen'>(</span><span class='id identifier rubyid_hash'>hash</span><span class='rparen'>)</span>
<span class='id identifier rubyid_view'>view</span><span class='period'>.</span><span class='id identifier rubyid_view_paths'>view_paths</span><span class='period'>.</span><span class='id identifier rubyid_unshift'>unshift</span><span class='lparen'>(</span><span class='const'>StubResolverCache</span><span class='period'>.</span><span class='id identifier rubyid_resolver_for'>resolver_for</span><span class='lparen'>(</span><span class='id identifier rubyid_hash'>hash</span><span class='rparen'>)</span><span class='rparen'>)</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="template-instance_method">
#<strong>template</strong> ⇒ <tt>Object</tt>
</h3><div class="docstring">
<div class="discussion">
<div class="note deprecated"><strong>Deprecated.</strong> <div class='inline'><p>Use <code>view</code> instead.</p>
</div></div>
</div>
</div>
<div class="tags">
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
104
105
106
107</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/rspec/rails/example/view_example_group.rb', line 104</span>
<span class='kw'>def</span> <span class='id identifier rubyid_template'>template</span>
<span class='const'><span class='object_link'><a href="../../../RSpec.html" title="RSpec (module)">RSpec</a></span></span><span class='period'>.</span><span class='id identifier rubyid_deprecate'>deprecate</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>template</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>replacement:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>view</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
<span class='id identifier rubyid_view'>view</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="view-instance_method">
#<strong>view</strong> ⇒ <tt>Object</tt>
</h3><div class="docstring">
<div class="discussion">
<p>The instance of <code>ActionView::Base</code> that is used to render the template.
Use this to stub methods <em>before</em> calling <code>render</code>.</p>
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_describe'>describe</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>widgets/new.html.erb</span><span class='tstring_end'>"</span></span> <span class='kw'>do</span>
<span class='id identifier rubyid_it'>it</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>shows all the widgets</span><span class='tstring_end'>"</span></span> <span class='kw'>do</span>
<span class='id identifier rubyid_view'>view</span><span class='period'>.</span><span class='id identifier rubyid_stub'>stub</span><span class='lparen'>(</span><span class='symbol'>:foo</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>foo</span><span class='tstring_end'>"</span></span> <span class='rbrace'>}</span>
<span class='id identifier rubyid_render'>render</span>
<span class='comment'># ...
</span> <span class='kw'>end</span>
<span class='kw'>end</span>
</code></pre>
</div>
</div>
<div class="tags">
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
81
82
83</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/rspec/rails/example/view_example_group.rb', line 81</span>
<span class='kw'>def</span> <span class='id identifier rubyid_view'>view</span>
<span class='id identifier rubyid__view'>_view</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
</div>
</div>
<div id="footer">
Generated on Wed Apr 8 23:32:18 2020 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.24 (ruby-2.6.3).
</div>
</div>
</body>
</html>