> For the complete documentation index, see [llms.txt](https://ploegert.gitbook.io/til/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ploegert.gitbook.io/til/programmy/rails/render-the-response-body-in-controller-specs.md).

# Render The Response Body In Controller Specs

Controller specs skip the rendering of views by default. If you want to inspect some aspect of what is rendered in the HTML body of a response (`response.body`), you can include the `render_views` directive in that spec.

```ruby
require 'rails_helper'

RSpec.describe DashboardController do
  describe '#index' do
    render_views

    context 'when there is a signed in user' do
      it 'includes their email' do
        user = User.create(email: 'user@example.com')

        sign_in(user)

        get :index

        expect(response.body).to include('user@example.com')
      end
    end
  end
end
```

The `render_views` directive call can go at the top of a spec, and all views for all tests will be rendered. Or you can place it in the nested contexts only where it is needed.

View rendering is skipped by default in an effort to keep tests speedy. To not unnecessarily slow down your test suite, make sure to use it sparingly and only in tests where you are actually inspecting `response.body`.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ploegert.gitbook.io/til/programmy/rails/render-the-response-body-in-controller-specs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
