rails/rails-controller-testing

assert_template raising errors when response object is nil

danascheider opened this issue · 3 comments

Hi there! I'm using rails-controller-testing with Rails 5.2.0 and rspec-rails 3.7.2. An error is being raised because for some reason, the response object is nil. I have the following controller code:

class HomeController < ApplicationController
  def index
  end
end

And the request spec looks like this:

require "rails_helper"

RSpec.describe "Root path", type: :request do
  it "loads the main page" do
    get root_path
    expect(response).to render_template(:index)
  end
end

I traced the error to this line of code:

I don't suppose there's a way to check if the template is being streamed and run this code conditionally if so?

Hey Dana. After the get method is called the response should never be nil.

https://github.com/rails/rails/blob/6c05728a507fe828647c2a0f62cf8ede1534a642/actionpack/lib/action_controller/test_case.rb#L473.

It being a while since I don't use RSpec, but do you know if the type: :request defines a ActionController::TestCase or a ActionDispatch::IntegrationTest? If it is the later render_template should not work because it is made for controller tests, not for integrations tests.

If it is the former maybe RSpec or something else is overriding the response method or process method what could be causing the response to be nil.

Thanks for the response @rafaelfranca ! I'll look into it a little more a let you know what I find out. Could be useful information.

This issue has been automatically closed because there has been no follow-up response from the original author. We currently don't have enough information in order to take action. Please reach out if you have any additional information that will help us move this issue forward.