method

rendered

Importance_2
Ruby on Rails latest stable (v7.1.3.2) - 0 notes - Class: ActionView::TestCase::Behavior
  • 1.0.0
  • 1.1.6
  • 1.2.6
  • 2.0.3
  • 2.1.0
  • 2.2.1
  • 2.3.8
  • 3.0.0
  • 3.0.9
  • 3.1.0
  • 3.2.1
  • 3.2.8
  • 3.2.13
  • 4.0.2
  • 4.1.8
  • 4.2.1
  • 4.2.7
  • 4.2.9
  • 5.0.0.1
  • 5.1.7
  • 5.2.3
  • 6.0.0
  • 6.1.3.1
  • 6.1.7.7
  • 7.0.0
  • 7.1.3.2 (0)
  • 7.1.3.4 (0)
  • What's this?
rendered() public

Returns the content rendered by the last render call.

The returned object behaves like a string but also exposes a number of methods that allows you to parse the content string in formats registered using .register_parser.

By default includes the following parsers:

.html

Parse the rendered content String into HTML. By default, this means a Nokogiri::XML::Node.

test "renders HTML" do
  article = Article.create!(title: "Hello, world")

  render partial: "articles/article", locals: { article: article }

  assert_pattern { rendered.html.at("main h1") => { content: "Hello, world" } }
end

To parse the rendered content into a Capybara::Simple::Node, re-register an :html parser with a call to Capybara.string:

register_parser :html, -> rendered { Capybara.string(rendered) }

test "renders HTML" do
  article = Article.create!(title: "Hello, world")

  render partial: article

  rendered.html.assert_css "h1", text: "Hello, world"
end

.json

Parse the rendered content String into JSON. By default, this means a ActiveSupport::HashWithIndifferentAccess.

test "renders JSON" do
  article = Article.create!(title: "Hello, world")

  render formats: :json, partial: "articles/article", locals: { article: article }

  assert_pattern { rendered.json => { title: "Hello, world" } }
end
Show source
Register or log in to add new notes.