From d42182d9a28268114d91fa840dafca9e48260bec Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 25 Mar 2026 05:58:04 -0400 Subject: [PATCH] Use more granular content check via `parsed_body` (#38378) --- .../admin/accounts_controller_spec.rb | 9 +++++---- .../admin/disputes/appeals_controller_spec.rb | 8 +++++--- .../admin/instances_controller_spec.rb | 10 +++++----- .../auth/sessions_controller_spec.rb | 20 +++++++++---------- .../account_controller_concern_spec.rb | 4 ++-- .../settings/imports_controller_spec.rb | 4 ++-- .../confirmations_controller_spec.rb | 10 ++++++---- 7 files changed, 35 insertions(+), 30 deletions(-) diff --git a/spec/controllers/admin/accounts_controller_spec.rb b/spec/controllers/admin/accounts_controller_spec.rb index f8e78759cc..10b8d774cf 100644 --- a/spec/controllers/admin/accounts_controller_spec.rb +++ b/spec/controllers/admin/accounts_controller_spec.rb @@ -63,11 +63,12 @@ RSpec.describe Admin::AccountsController do note2 = Fabricate(:account_moderation_note, target_account: account, content: 'Note 2 remarks') get :show, params: { id: account.id } - expect(response).to have_http_status(200) - expect(response.body) - .to include(note1.content) - .and include(note2.content) + expect(response) + .to have_http_status(200) + expect(response.parsed_body) + .to have_css("#account_moderation_note_#{note1.id}", text: note1.content) + .and have_css("#account_moderation_note_#{note2.id}", text: note2.content) end end diff --git a/spec/controllers/admin/disputes/appeals_controller_spec.rb b/spec/controllers/admin/disputes/appeals_controller_spec.rb index b67ee30f74..6b955dd803 100644 --- a/spec/controllers/admin/disputes/appeals_controller_spec.rb +++ b/spec/controllers/admin/disputes/appeals_controller_spec.rb @@ -23,9 +23,11 @@ RSpec.describe Admin::Disputes::AppealsController do it 'returns a page that lists details of appeals' do get :index - expect(response).to have_http_status(:success) - expect(response.body).to include("#{strike.account.username}") - expect(response.body).to include("#{appeal.account.username}") + expect(response) + .to have_http_status(:success) + expect(response.parsed_body) + .to have_css('span.username', text: strike.account.username) + .and have_css('span.target', text: appeal.account.username) end end diff --git a/spec/controllers/admin/instances_controller_spec.rb b/spec/controllers/admin/instances_controller_spec.rb index b6508eb38b..3027c92fcf 100644 --- a/spec/controllers/admin/instances_controller_spec.rb +++ b/spec/controllers/admin/instances_controller_spec.rb @@ -47,11 +47,11 @@ RSpec.describe Admin::InstancesController do it 'shows an instance page' do get :show, params: { id: account_popular_main.domain } - expect(response).to have_http_status(200) - - expect(response.body) - .to include(I18n.t('admin.instances.totals_time_period_hint_html')) - .and include(I18n.t('accounts.nothing_here')) + expect(response) + .to have_http_status(200) + expect(response.parsed_body) + .to have_css('p', text: I18n.t('admin.instances.totals_time_period_hint_html')) + .and have_css('p', text: I18n.t('accounts.nothing_here')) expect(Admin::ActionLogFilter).to have_received(:new).with(target_domain: account_popular_main.domain) end diff --git a/spec/controllers/auth/sessions_controller_spec.rb b/spec/controllers/auth/sessions_controller_spec.rb index 924122d161..d8d640a058 100644 --- a/spec/controllers/auth/sessions_controller_spec.rb +++ b/spec/controllers/auth/sessions_controller_spec.rb @@ -226,8 +226,8 @@ RSpec.describe Auth::SessionsController do end it 'renders two factor authentication page' do - expect(response.body) - .to include(I18n.t('simple_form.hints.sessions.otp')) + expect(response.parsed_body) + .to have_css('p.hint.authentication-hint', text: I18n.t('simple_form.hints.sessions.otp')) end end @@ -242,8 +242,8 @@ RSpec.describe Auth::SessionsController do end it 'renders two factor authentication page' do - expect(response.body) - .to include(I18n.t('simple_form.hints.sessions.otp')) + expect(response.parsed_body) + .to have_css('p.hint.authentication-hint', text: I18n.t('simple_form.hints.sessions.otp')) end end @@ -253,8 +253,8 @@ RSpec.describe Auth::SessionsController do end it 'renders two factor authentication page' do - expect(response.body) - .to include(I18n.t('simple_form.hints.sessions.otp')) + expect(response.parsed_body) + .to have_css('p.hint.authentication-hint', text: I18n.t('simple_form.hints.sessions.otp')) end end @@ -387,8 +387,8 @@ RSpec.describe Auth::SessionsController do end it 'renders webauthn authentication page' do - expect(response.body) - .to include(I18n.t('simple_form.title.sessions.webauthn')) + expect(response.parsed_body) + .to have_css('h3.title', text: I18n.t('simple_form.title.sessions.webauthn')) end end @@ -398,8 +398,8 @@ RSpec.describe Auth::SessionsController do end it 'renders webauthn authentication page' do - expect(response.body) - .to include(I18n.t('simple_form.title.sessions.webauthn')) + expect(response.parsed_body) + .to have_css('h3.title', text: I18n.t('simple_form.title.sessions.webauthn')) end end diff --git a/spec/controllers/concerns/account_controller_concern_spec.rb b/spec/controllers/concerns/account_controller_concern_spec.rb index b5c8c16643..2f7e230d48 100644 --- a/spec/controllers/concerns/account_controller_concern_spec.rb +++ b/spec/controllers/concerns/account_controller_concern_spec.rb @@ -59,8 +59,8 @@ RSpec.describe AccountControllerConcern do .to have_http_status(200) .and have_http_link_header(webfinger_url(resource: account.to_webfinger_s)).for(rel: 'lrdd', type: 'application/jrd+json') .and have_http_link_header(ActivityPub::TagManager.instance.uri_for(account)).for(rel: 'alternate', type: 'application/activity+json') - expect(response.body) - .to include(account.username) + expect(response.parsed_body) + .to eq(account.username) end end end diff --git a/spec/controllers/settings/imports_controller_spec.rb b/spec/controllers/settings/imports_controller_spec.rb index c2c6c353f3..0b399fcc40 100644 --- a/spec/controllers/settings/imports_controller_spec.rb +++ b/spec/controllers/settings/imports_controller_spec.rb @@ -22,8 +22,8 @@ RSpec.describe Settings::ImportsController do it 'assigns the expected imports', :aggregate_failures do expect(response).to have_http_status(200) expect(response.headers['Cache-Control']).to include('private, no-store') - expect(response.body) - .to include("bulk_import_#{import.id}") + expect(response.parsed_body) + .to have_css("#bulk_import_#{import.id}") .and not_include("bulk_import_#{other_import.id}") end end diff --git a/spec/controllers/settings/two_factor_authentication/confirmations_controller_spec.rb b/spec/controllers/settings/two_factor_authentication/confirmations_controller_spec.rb index db4fb19411..a87c55364e 100644 --- a/spec/controllers/settings/two_factor_authentication/confirmations_controller_spec.rb +++ b/spec/controllers/settings/two_factor_authentication/confirmations_controller_spec.rb @@ -12,7 +12,8 @@ RSpec.describe Settings::TwoFactorAuthentication::ConfirmationsController do expect(response).to have_http_status(200) expect(response.body) .to include(qr_code_markup) - .and include(I18n.t('settings.two_factor_authentication')) + expect(response.parsed_body) + .to have_title(I18n.t('settings.two_factor_authentication')) end def qr_code_markup @@ -80,7 +81,8 @@ RSpec.describe Settings::TwoFactorAuthentication::ConfirmationsController do .to have_http_status(200) expect(response.body) .to include(*otp_backup_codes) - .and include(I18n.t('settings.two_factor_authentication')) + expect(response.parsed_body) + .to have_title(I18n.t('settings.two_factor_authentication')) end end @@ -98,8 +100,8 @@ RSpec.describe Settings::TwoFactorAuthentication::ConfirmationsController do it 'renders page with error message' do subject - expect(response.body) - .to include(I18n.t('otp_authentication.wrong_code')) + expect(response.parsed_body) + .to have_css('.flash-message', text: I18n.t('otp_authentication.wrong_code')) end it_behaves_like 'renders expected page'