Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support/helpers/email_helpers.rb')
-rw-r--r--spec/support/helpers/email_helpers.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/spec/support/helpers/email_helpers.rb b/spec/support/helpers/email_helpers.rb
index 57386233775..2a7d15f03c6 100644
--- a/spec/support/helpers/email_helpers.rb
+++ b/spec/support/helpers/email_helpers.rb
@@ -14,6 +14,18 @@ module EmailHelpers
ActiveJob::Base.queue_adapter.enqueued_jobs.clear
end
+ def expect_only_one_email_to_be_sent(subject:, to:)
+ count_of_sent_emails = ActionMailer::Base.deliveries.count
+ expect(count_of_sent_emails).to eq(1), "Expected only one email to be sent, but #{count_of_sent_emails} emails were sent instead"
+
+ return unless count_of_sent_emails == 1
+
+ message = ActionMailer::Base.deliveries.first
+
+ expect(message.subject).to eq(subject), "Expected '#{subject}' email to be sent, but '#{message.subject}' email was sent instead"
+ expect(message.to).to match_array(to), "Expected the email to be sent to #{to}, but it was sent to #{message.to} instead"
+ end
+
def should_only_email(*users, kind: :to)
recipients = email_recipients(kind: kind)