Skip to content

Commit 40e76ef

Browse files
authored
test: make mail checks in system specs less flakey (#765)
These specs currently fail semi-frequently since there is no actual guarantee that the emails will be in the same order every time, so I've rewritten the tests to select all emails with the expected `to` address
1 parent b0f1ed3 commit 40e76ef

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

spec/system/approved_user_application_spec.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,21 @@
2121
it "sends an email to the user after submitting" do
2222
subject.fill_in_mandatory_fields
2323
perform_enqueued_jobs { subject.submit }
24-
mail = ActionMailer::Base.deliveries[-2]
25-
expect(mail.to).to eq [user.email]
26-
expect(mail.subject).to eq I18n.t("approved_user_mailer.submitted.subject")
24+
25+
mails = ActionMailer::Base.deliveries.select { |mail| mail.to.include?(user.email) }
26+
27+
expect(mails.length).to be(1)
28+
expect(mails.first.subject).to eq I18n.t("approved_user_mailer.submitted.subject")
2729
end
2830

2931
it "sends an email to the admin after submitting" do
3032
subject.fill_in_mandatory_fields
3133
perform_enqueued_jobs { subject.submit }
32-
mail = ActionMailer::Base.deliveries[-1]
33-
expect(mail.to).to eq [admin.email]
34-
expect(mail.subject).to eq I18n.t("approved_user_mailer.admin_submitted.subject")
34+
35+
mails = ActionMailer::Base.deliveries.select { |mail| mail.to.include?(admin.email) }
36+
37+
expect(mails.length).to be(1)
38+
expect(mails.first.subject).to eq I18n.t("approved_user_mailer.admin_submitted.subject")
3539
end
3640

3741
it "leaves a required field blank" do

0 commit comments

Comments
 (0)