From f4b463ecb1203beaafbca11b9a760729b9a66223 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Thu, 9 Jan 2025 03:17:00 -0500 Subject: [PATCH] Use `response.parsed_body` for error view application controller spec (#33515) --- .../application_controller_spec.rb | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb index 4ee951628e..2e7a59db05 100644 --- a/spec/controllers/application_controller_spec.rb +++ b/spec/controllers/application_controller_spec.rb @@ -3,6 +3,8 @@ require 'rails_helper' RSpec.describe ApplicationController do + render_views + controller do def success head 200 @@ -23,9 +25,22 @@ RSpec.describe ApplicationController do shared_examples 'respond_with_error' do |code| it "returns http #{code} for http and renders template" do - expect(subject).to render_template("errors/#{code}", layout: 'error') + subject - expect(response).to have_http_status(code) + expect(response) + .to have_http_status(code) + expect(response.parsed_body) + .to have_css('body[class=error]') + expect(response.parsed_body.css('h1').to_s) + .to include(error_content(code)) + end + + def error_content(code) + if code == 422 + I18n.t('errors.422.content') + else + I18n.t("errors.#{code}") + end end end