Migrate a few tests to use NotificationAssertions (#38098)

This commit is contained in:
Nicholas La Roux 2026-06-08 18:01:20 +02:00 committed by GitHub
parent fc64804b4d
commit 4a5a915e86
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 11 deletions

View File

@ -52,11 +52,17 @@ RSpec.describe RequestPool do
end end
it 'closes the connections' do it 'closes the connections' do
subject.with('http://example.com') do |http_client| notifications = capture_notifications('with.request_pool') do
http_client.get('/').flush subject.with('http://example.com') do |http_client|
http_client.get('/').flush
end
end end
expect { reaper_observes_idle_timeout }.to change(subject, :size).from(1).to(0) 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 end
def reaper_observes_idle_timeout def reaper_observes_idle_timeout

View File

@ -36,14 +36,12 @@ RSpec.describe Setting do
context 'when the setting has been saved to database' do context 'when the setting has been saved to database' do
it 'returns the value from database' do it 'returns the value from database' do
callback = double notifications = capture_notifications('sql.active_record') do
allow(callback).to receive(:call)
ActiveSupport::Notifications.subscribed callback, 'sql.active_record' do
expect(described_class[key]).to eq 42 expect(described_class[key]).to eq 42
end end
expect(callback).to have_received(:call) expect(notifications.size).to eq(1)
expect(notifications.first.payload[:name]).to eq('Setting Load')
end end
end end
@ -62,12 +60,11 @@ RSpec.describe Setting do
end end
it 'does not query the database' do it 'does not query the database' do
callback = double notifications = capture_notifications('sql.active_record') do
allow(callback).to receive(:call)
ActiveSupport::Notifications.subscribed callback, 'sql.active_record' do
described_class[key] described_class[key]
end end
expect(callback).to_not have_received(:call)
expect(notifications).to be_empty
end end
it 'returns the cached value' do it 'returns the cached value' do

View File

@ -82,6 +82,7 @@ RSpec.configure do |config|
config.include Devise::Test::IntegrationHelpers, type: :request config.include Devise::Test::IntegrationHelpers, type: :request
config.include ActionMailer::TestHelper config.include ActionMailer::TestHelper
config.include Paperclip::Shoulda::Matchers config.include Paperclip::Shoulda::Matchers
config.include ActiveSupport::Testing::NotificationAssertions
config.include ActiveSupport::Testing::TimeHelpers config.include ActiveSupport::Testing::TimeHelpers
config.include Chewy::Rspec::Helpers config.include Chewy::Rspec::Helpers
config.include Redisable config.include Redisable