diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb
index 03dd8867b1873e8140941e6be725ef994097a3a5..050ab50f84fbca058b9f886c35e8b108b45d0c0e 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 0bfc4685532f576c184eb0393b26ee94a41b494e..dfb252544e7965a3bb0a786f93e5563401e67ebf 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