Skip to content

Commit 71517a1

Browse files
authored
Merge pull request rails#54465 from D-Forz/rendered-docs
Fix RDoc for ActionView::TestCase::Behavior#rendered [ci skip]
2 parents 4c6cdf1 + 951eec7 commit 71517a1

File tree

1 file changed

+50
-52
lines changed

1 file changed

+50
-52
lines changed

actionview/lib/action_view/test_case.rb

Lines changed: 50 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,56 @@ module Behavior
6060
include ActiveSupport::Testing::ConstantLookup
6161

6262
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
64113

65114
module ClassMethods
66115
def inherited(descendant) # :nodoc:
@@ -243,57 +292,6 @@ def rendered_views
243292
@_rendered_views ||= RenderedViewsCollection.new
244293
end
245294

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-
297295
def _routes
298296
@controller._routes if @controller.respond_to?(:_routes)
299297
end

0 commit comments

Comments
 (0)