@@ -60,7 +60,56 @@ module Behavior
60
60
include ActiveSupport ::Testing ::ConstantLookup
61
61
62
62
delegate :lookup_context , to : :controller
63
- attr_accessor :controller , :request , :output_buffer , :rendered
63
+ attr_accessor :controller , :request , :output_buffer
64
+
65
+ # Returns the content rendered by the last +render+ call.
66
+ #
67
+ # The returned object behaves like a string but also exposes a number of methods
68
+ # that allows you to parse the content string in formats registered using
69
+ # <tt>.register_parser</tt>.
70
+ #
71
+ # By default includes the following parsers:
72
+ #
73
+ # +.html+
74
+ #
75
+ # Parse the <tt>rendered</tt> content String into HTML. By default, this means
76
+ # a <tt>Nokogiri::XML::Node</tt>.
77
+ #
78
+ # test "renders HTML" do
79
+ # article = Article.create!(title: "Hello, world")
80
+ #
81
+ # render partial: "articles/article", locals: { article: article }
82
+ #
83
+ # assert_pattern { rendered.html.at("main h1") => { content: "Hello, world" } }
84
+ # end
85
+ #
86
+ # To parse the rendered content into a <tt>Capybara::Simple::Node</tt>,
87
+ # re-register an <tt>:html</tt> parser with a call to
88
+ # <tt>Capybara.string</tt>:
89
+ #
90
+ # register_parser :html, -> rendered { Capybara.string(rendered) }
91
+ #
92
+ # test "renders HTML" do
93
+ # article = Article.create!(title: "Hello, world")
94
+ #
95
+ # render partial: article
96
+ #
97
+ # rendered.html.assert_css "h1", text: "Hello, world"
98
+ # end
99
+ #
100
+ # +.json+
101
+ #
102
+ # Parse the <tt>rendered</tt> content String into JSON. By default, this means
103
+ # a <tt>ActiveSupport::HashWithIndifferentAccess</tt>.
104
+ #
105
+ # test "renders JSON" do
106
+ # article = Article.create!(title: "Hello, world")
107
+ #
108
+ # render formats: :json, partial: "articles/article", locals: { article: article }
109
+ #
110
+ # assert_pattern { rendered.json => { title: "Hello, world" } }
111
+ # end
112
+ attr_accessor :rendered
64
113
65
114
module ClassMethods
66
115
def inherited ( descendant ) # :nodoc:
@@ -243,57 +292,6 @@ def rendered_views
243
292
@_rendered_views ||= RenderedViewsCollection . new
244
293
end
245
294
246
- ##
247
- # :method: rendered
248
- #
249
- # Returns the content rendered by the last +render+ call.
250
- #
251
- # The returned object behaves like a string but also exposes a number of methods
252
- # that allows you to parse the content string in formats registered using
253
- # <tt>.register_parser</tt>.
254
- #
255
- # By default includes the following parsers:
256
- #
257
- # +.html+
258
- #
259
- # Parse the <tt>rendered</tt> content String into HTML. By default, this means
260
- # a <tt>Nokogiri::XML::Node</tt>.
261
- #
262
- # test "renders HTML" do
263
- # article = Article.create!(title: "Hello, world")
264
- #
265
- # render partial: "articles/article", locals: { article: article }
266
- #
267
- # assert_pattern { rendered.html.at("main h1") => { content: "Hello, world" } }
268
- # end
269
- #
270
- # To parse the rendered content into a <tt>Capybara::Simple::Node</tt>,
271
- # re-register an <tt>:html</tt> parser with a call to
272
- # <tt>Capybara.string</tt>:
273
- #
274
- # register_parser :html, -> rendered { Capybara.string(rendered) }
275
- #
276
- # test "renders HTML" do
277
- # article = Article.create!(title: "Hello, world")
278
- #
279
- # render partial: article
280
- #
281
- # rendered.html.assert_css "h1", text: "Hello, world"
282
- # end
283
- #
284
- # +.json+
285
- #
286
- # Parse the <tt>rendered</tt> content String into JSON. By default, this means
287
- # a <tt>ActiveSupport::HashWithIndifferentAccess</tt>.
288
- #
289
- # test "renders JSON" do
290
- # article = Article.create!(title: "Hello, world")
291
- #
292
- # render formats: :json, partial: "articles/article", locals: { article: article }
293
- #
294
- # assert_pattern { rendered.json => { title: "Hello, world" } }
295
- # end
296
-
297
295
def _routes
298
296
@controller . _routes if @controller . respond_to? ( :_routes )
299
297
end
0 commit comments