0
0
Fork 0

Use capture_emails helper to improve email assertions in specs (#29245)

This commit is contained in:
Matt Jankowski 2024-02-19 10:57:47 -05:00 committed by GitHub
parent 86627ea2e4
commit 64f9939e39
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 97 additions and 47 deletions

View file

@ -157,8 +157,6 @@ RSpec.describe NotifyService, type: :service do
describe 'email' do
before do
ActionMailer::Base.deliveries.clear
user.settings.update('notification_emails.follow': enabled)
user.save
end
@ -167,7 +165,15 @@ RSpec.describe NotifyService, type: :service do
let(:enabled) { true }
it 'sends email', :sidekiq_inline do
expect { subject }.to change(ActionMailer::Base.deliveries, :count).by(1)
emails = capture_emails { subject }
expect(emails.size)
.to eq(1)
expect(emails.first)
.to have_attributes(
to: contain_exactly(user.email),
subject: eq(I18n.t('notification_mailer.follow.subject', name: sender.acct))
)
end
end
@ -175,7 +181,9 @@ RSpec.describe NotifyService, type: :service do
let(:enabled) { false }
it "doesn't send email" do
expect { subject }.to_not change(ActionMailer::Base.deliveries, :count).from(0)
emails = capture_emails { subject }
expect(emails).to be_empty
end
end
end