diff options
author | Alex Kalderimis <alex.kalderimis@gmail.com> | 2019-08-20 01:09:37 +0100 |
---|---|---|
committer | Alex Kalderimis <alex.kalderimis@gmail.com> | 2019-08-20 01:09:37 +0100 |
commit | 7dbfdba8cdfac0a54c9cf0d4e52efe94a0ac7726 (patch) | |
tree | 0e3fa4ffcfa34f8eb2a0726782d63a0cf26d356e | |
parent | d4a5e3fd8746a3af2d57060d304b760e7539d752 (diff) | |
download | gitlab-ce-better-email-matchers.tar.gz |
Start project of removing dependency on email_specbetter-email-matchers
-rw-r--r-- | spec/mailers/notify_spec.rb | 7 | ||||
-rw-r--r-- | spec/support/matchers/deliver_mail_to.rb | 12 | ||||
-rw-r--r-- | spec/support/matchers/have_mail_body.rb | 9 | ||||
-rw-r--r-- | spec/support/matchers/have_mail_subject.rb | 7 |
4 files changed, 31 insertions, 4 deletions
diff --git a/spec/mailers/notify_spec.rb b/spec/mailers/notify_spec.rb index dcc4b70a382..44ae59aaa3d 100644 --- a/spec/mailers/notify_spec.rb +++ b/spec/mailers/notify_spec.rb @@ -3,7 +3,6 @@ require 'email_spec' describe Notify do include EmailSpec::Helpers - include EmailSpec::Matchers include EmailHelpers include RepoHelpers @@ -55,7 +54,7 @@ describe Notify do aggregate_failures do expect(sender.display_name).to eq(current_user.name) expect(sender.address).to eq(gitlab_sender) - expect(subject).to deliver_to(recipient.notification_email) + expect(subject).to deliver_mail_to(recipient.notification_email) end end end @@ -76,12 +75,12 @@ describe Notify do it 'has the correct subject and body' do aggregate_failures do is_expected.to have_referable_subject(issue) - is_expected.to have_body_text(project_issue_path(project, issue)) + is_expected.to have_mail_body(project_issue_path(project, issue)) end end it 'contains the description' do - is_expected.to have_body_text issue.description + is_expected.to have_mail_body(issue.description) end it 'does not add a reason header' do diff --git a/spec/support/matchers/deliver_mail_to.rb b/spec/support/matchers/deliver_mail_to.rb new file mode 100644 index 00000000000..8c171ee3c36 --- /dev/null +++ b/spec/support/matchers/deliver_mail_to.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +RSpec::Matchers.define :deliver_mail_to do |*targets| + match do |email| + expected_recipients = targets.map {|t| t.try(:email) || t } + header = email.header[:to] || email.header[:bcc] + recipients = header.try(:addrs).try(:map, &:to_s) + + expect(email.perform_deliveries).to be_truthy + expect(recipients).to include(*expected_recipients) + end +end diff --git a/spec/support/matchers/have_mail_body.rb b/spec/support/matchers/have_mail_body.rb new file mode 100644 index 00000000000..b1b0059aa9d --- /dev/null +++ b/spec/support/matchers/have_mail_body.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +RSpec::Matchers.define :have_mail_body do |target| + match do |email| + matcher = target.is_a?(String) ? include(target) : match(target) + + expect(email.default_part_body.to_s.gsub(/\s+/, ' ')).to matcher + end +end diff --git a/spec/support/matchers/have_mail_subject.rb b/spec/support/matchers/have_mail_subject.rb new file mode 100644 index 00000000000..46bcd5fa1b5 --- /dev/null +++ b/spec/support/matchers/have_mail_subject.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +RSpec::Matchers.define :have_mail_subject do |target| + match do |email| + expect(email).to have_attributes(subject: target) + end +end |