Search code examples
rspec-railsruby-on-rails-7

Undefined Method "To" for ActionDispatch::TestResponse using rspec-rails 6 in request spec


I have a Request spec that looks like this in Rails 7, Rspec-rails 6 :

require 'rails_helper'

RSpec.describe 'GuestTokens', type: :request do
  describe 'GET /guest_tokens/:id' do
    context 'with a JSON format' do
      let(:guest_token) { FactoryBot.create(:guest_token) }

      it 'should return a JSON object of the guest token' do
        get "/guest_tokens/#{guest_token.id}.json"

        expect response.to render_template :show
      end
    end
  end
end

calling response.to

gives me undefined method 'to' for #<ActionDispatch::TestResponse

I'm not sure where I am straying away from the example in the docs: https://relishapp.com/rspec/rspec-rails/docs/request-specs/request-spec

Perhaps this is a configuration issue?


Solution

  • You need to call the expect function on the response like this

    expect(response).to render_template :show