From 4a5a915e86a7eb3ccef4206ce69a8b89d9672c2b Mon Sep 17 00:00:00 2001 From: Nicholas La Roux Date: Mon, 8 Jun 2026 18:01:20 +0200 Subject: [PATCH] Migrate a few tests to use `NotificationAssertions` (#38098) --- spec/lib/request_pool_spec.rb | 10 ++++++++-- spec/models/setting_spec.rb | 15 ++++++--------- spec/rails_helper.rb | 1 + 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/spec/lib/request_pool_spec.rb b/spec/lib/request_pool_spec.rb index 2e8c785de8..8df7339156 100644 --- a/spec/lib/request_pool_spec.rb +++ b/spec/lib/request_pool_spec.rb @@ -52,11 +52,17 @@ RSpec.describe RequestPool do end it 'closes the connections' do - subject.with('http://example.com') do |http_client| - http_client.get('/').flush + notifications = capture_notifications('with.request_pool') do + subject.with('http://example.com') do |http_client| + http_client.get('/').flush + end end expect { reaper_observes_idle_timeout }.to change(subject, :size).from(1).to(0) + + expect(notifications.size).to eq(1) + expect(notifications.first.payload[:host]).to eq('http://example.com') + expect(notifications.first.payload[:miss]).to be(true) end def reaper_observes_idle_timeout diff --git a/spec/models/setting_spec.rb b/spec/models/setting_spec.rb index a1e24e8350..d4b0661217 100644 --- a/spec/models/setting_spec.rb +++ b/spec/models/setting_spec.rb @@ -36,14 +36,12 @@ RSpec.describe Setting do context 'when the setting has been saved to database' do it 'returns the value from database' do - callback = double - allow(callback).to receive(:call) - - ActiveSupport::Notifications.subscribed callback, 'sql.active_record' do + notifications = capture_notifications('sql.active_record') do expect(described_class[key]).to eq 42 end - expect(callback).to have_received(:call) + expect(notifications.size).to eq(1) + expect(notifications.first.payload[:name]).to eq('Setting Load') end end @@ -62,12 +60,11 @@ RSpec.describe Setting do end it 'does not query the database' do - callback = double - allow(callback).to receive(:call) - ActiveSupport::Notifications.subscribed callback, 'sql.active_record' do + notifications = capture_notifications('sql.active_record') do described_class[key] end - expect(callback).to_not have_received(:call) + + expect(notifications).to be_empty end it 'returns the cached value' do diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 02bd2ef25e..55ad344b80 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -82,6 +82,7 @@ RSpec.configure do |config| config.include Devise::Test::IntegrationHelpers, type: :request config.include ActionMailer::TestHelper config.include Paperclip::Shoulda::Matchers + config.include ActiveSupport::Testing::NotificationAssertions config.include ActiveSupport::Testing::TimeHelpers config.include Chewy::Rspec::Helpers config.include Redisable