From 572585665f838584b9547831528f26fb60df8d0f Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin <godfat@godfat.org> Date: Mon, 19 Sep 2016 13:54:16 +0800 Subject: [PATCH] Use EmailHelpers where possible, feedback: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/6342#note_15434860 --- spec/models/ci/pipeline_spec.rb | 5 ++--- spec/support/email_helpers.rb | 6 +++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index 03dd8867b18..050ab50f84f 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -535,14 +535,13 @@ describe Ci::Pipeline, models: true do shared_examples 'sending a notification' do it 'sends an email' do - sent_to = ActionMailer::Base.deliveries.flat_map(&:to) - expect(sent_to).to contain_exactly(pipeline.user.email) + should_only_email(pipeline.user) end end shared_examples 'not sending any notification' do it 'does not send any email' do - expect(ActionMailer::Base.deliveries).to be_empty + should_email_no_one end end diff --git a/spec/support/email_helpers.rb b/spec/support/email_helpers.rb index 0bfc4685532..dfb252544e7 100644 --- a/spec/support/email_helpers.rb +++ b/spec/support/email_helpers.rb @@ -1,6 +1,6 @@ module EmailHelpers def sent_to_user?(user) - ActionMailer::Base.deliveries.map(&:to).flatten.count(user.email) == 1 + ActionMailer::Base.deliveries.flat_map(&:to).count(user.email) == 1 end def reset_delivered_emails! @@ -20,4 +20,8 @@ module EmailHelpers def should_not_email(user) expect(sent_to_user?(user)).to be_falsey end + + def should_email_no_one + expect(ActionMailer::Base.deliveries).to be_empty + end end -- GitLab