Commit 2009279a authored by Balasankar "Balu" C's avatar Balasankar "Balu" C

Make specs DRY

Signed-off-by: default avatarBalasankar "Balu" C <balasankar@gitlab.com>
parent 399eb9f1
......@@ -3,5 +3,5 @@
require 'spec_helper'
describe MattermostService do
it_behaves_like "slack or mattermost notifications"
it_behaves_like "slack or mattermost notifications", "Mattermost"
end
......@@ -226,9 +226,10 @@ describe MicrosoftTeamsService do
)
end
shared_examples 'call Microsoft Teams API' do
shared_examples 'call Microsoft Teams API' do |branches_to_be_notified: nil|
before do
WebMock.stub_request(:post, webhook_url)
chat_service.branches_to_be_notified = branches_to_be_notified if branches_to_be_notified
end
it 'calls Microsoft Teams API for pipeline events' do
......@@ -245,6 +246,18 @@ describe MicrosoftTeamsService do
end
end
shared_examples 'does not call Microsoft Teams API' do |branches_to_be_notified: nil|
before do
chat_service.branches_to_be_notified = branches_to_be_notified if branches_to_be_notified
end
it 'does not call Microsoft Teams API for pipeline events' do
data = Gitlab::DataBuilder::Pipeline.build(pipeline)
result = chat_service.execute(data)
expect(result).to be_falsy
end
end
context 'with failed pipeline' do
let(:status) { 'failed' }
......@@ -278,40 +291,19 @@ describe MicrosoftTeamsService do
end
context 'only notify for the default branch' do
before do
chat_service.branches_to_be_notified = "default"
end
it_behaves_like 'call Microsoft Teams API'
it_behaves_like 'call Microsoft Teams API', branches_to_be_notified: "default"
end
context 'notify for only protected branches' do
before do
chat_service.branches_to_be_notified = "protected"
end
it 'does not call the Microsoft Teams API for pipeline events' do
data = Gitlab::DataBuilder::Pipeline.build(pipeline)
result = chat_service.execute(data)
expect(result).to be_falsy
end
it_behaves_like 'does not call Microsoft Teams API', branches_to_be_notified: "protected"
end
context 'notify for only default and protected branches' do
before do
chat_service.branches_to_be_notified = "default_and_protected"
end
it_behaves_like 'call Microsoft Teams API'
it_behaves_like 'call Microsoft Teams API', branches_to_be_notified: "default_and_protected"
end
context 'notify for all branches' do
before do
chat_service.branches_to_be_notified = "all"
end
it_behaves_like 'call Microsoft Teams API'
it_behaves_like 'call Microsoft Teams API', branches_to_be_notified: "all"
end
end
......@@ -325,40 +317,19 @@ describe MicrosoftTeamsService do
end
context 'only notify for the default branch' do
before do
chat_service.branches_to_be_notified = "default"
end
it 'does not call the Microsoft Teams API for pipeline events' do
data = Gitlab::DataBuilder::Pipeline.build(pipeline)
result = chat_service.execute(data)
expect(result).to be_falsy
end
it_behaves_like 'does not call Microsoft Teams API', branches_to_be_notified: "default"
end
context 'notify for only protected branches' do
before do
chat_service.branches_to_be_notified = "protected"
end
it_behaves_like 'call Microsoft Teams API'
it_behaves_like 'call Microsoft Teams API', branches_to_be_notified: "protected"
end
context 'notify for only default and protected branches' do
before do
chat_service.branches_to_be_notified = "default_and_protected"
end
it_behaves_like 'call Microsoft Teams API'
it_behaves_like 'call Microsoft Teams API', branches_to_be_notified: "default_and_protected"
end
context 'notify for all branches' do
before do
chat_service.branches_to_be_notified = "all"
end
it_behaves_like 'call Microsoft Teams API'
it_behaves_like 'call Microsoft Teams API', branches_to_be_notified: "all"
end
end
......@@ -368,50 +339,19 @@ describe MicrosoftTeamsService do
end
context 'only notify for the default branch' do
before do
chat_service.branches_to_be_notified = "default"
end
it 'does not call the Microsoft Teams API for pipeline events' do
data = Gitlab::DataBuilder::Pipeline.build(pipeline)
result = chat_service.execute(data)
expect(result).to be_falsy
end
it_behaves_like 'does not call Microsoft Teams API', branches_to_be_notified: "default"
end
context 'notify for only protected branches' do
before do
chat_service.branches_to_be_notified = "protected"
end
it 'does not call the Microsoft Teams API for pipeline events' do
data = Gitlab::DataBuilder::Pipeline.build(pipeline)
result = chat_service.execute(data)
expect(result).to be_falsy
end
it_behaves_like 'does not call Microsoft Teams API', branches_to_be_notified: "protected"
end
context 'notify for only default and protected branches' do
before do
chat_service.branches_to_be_notified = "default_and_protected"
end
it 'does not call the Microsoft Teams API for pipeline events' do
data = Gitlab::DataBuilder::Pipeline.build(pipeline)
result = chat_service.execute(data)
expect(result).to be_falsy
end
it_behaves_like 'does not call Microsoft Teams API', branches_to_be_notified: "default_and_protected"
end
context 'notify for all branches' do
before do
chat_service.branches_to_be_notified = "all"
end
it_behaves_like 'call Microsoft Teams API'
it_behaves_like 'call Microsoft Teams API', branches_to_be_notified: "all"
end
end
end
......
......@@ -53,9 +53,10 @@ describe PipelinesEmailService, :mailer do
end
end
shared_examples 'sending email' do
shared_examples 'sending email' do |branches_to_be_notified: nil|
before do
subject.recipients = recipients
subject.branches_to_be_notified = branches_to_be_notified if branches_to_be_notified
perform_enqueued_jobs do
run
......@@ -69,9 +70,10 @@ describe PipelinesEmailService, :mailer do
end
end
shared_examples 'not sending email' do
shared_examples 'not sending email' do |branches_to_be_notified: nil|
before do
subject.recipients = recipients
subject.branches_to_be_notified = branches_to_be_notified if branches_to_be_notified
perform_enqueued_jobs do
run
......@@ -109,35 +111,19 @@ describe PipelinesEmailService, :mailer do
end
context 'notifications are enabled only for default branch' do
before do
subject.branches_to_be_notified = "default"
end
it_behaves_like 'sending email'
it_behaves_like 'sending email', branches_to_be_notified: "default"
end
context 'notifications are enabled only for protected branch' do
before do
subject.branches_to_be_notified = "protected"
end
it_behaves_like 'sending email'
it_behaves_like 'sending email', branches_to_be_notified: "protected"
end
context 'notifications are enabled only for default and protected branches ' do
before do
subject.branches_to_be_notified = "default_and_protected"
end
it_behaves_like 'sending email'
it_behaves_like 'sending email', branches_to_be_notified: "default_and_protected"
end
context 'notifications are enabled only for all branches' do
before do
subject.branches_to_be_notified = "all"
end
it_behaves_like 'sending email'
it_behaves_like 'sending email', branches_to_be_notified: "all"
end
end
......@@ -149,35 +135,19 @@ describe PipelinesEmailService, :mailer do
end
context 'notifications are enabled only for default branch' do
before do
subject.branches_to_be_notified = "default"
end
it_behaves_like 'sending email'
it_behaves_like 'sending email', branches_to_be_notified: "default"
end
context 'notifications are enabled only for protected branch' do
before do
subject.branches_to_be_notified = "protected"
end
it_behaves_like 'sending email'
it_behaves_like 'sending email', branches_to_be_notified: "protected"
end
context 'notifications are enabled only for default and protected branches ' do
before do
subject.branches_to_be_notified = "default_and_protected"
end
it_behaves_like 'sending email'
it_behaves_like 'sending email', branches_to_be_notified: "default_and_protected"
end
context 'notifications are enabled only for all branches' do
before do
subject.branches_to_be_notified = "all"
end
it_behaves_like 'sending email'
it_behaves_like 'sending email', branches_to_be_notified: "all"
end
end
......@@ -188,35 +158,19 @@ describe PipelinesEmailService, :mailer do
end
context 'notifications are enabled only for default branch' do
before do
subject.branches_to_be_notified = "default"
end
it_behaves_like 'sending email'
it_behaves_like 'sending email', branches_to_be_notified: "default"
end
context 'notifications are enabled only for protected branch' do
before do
subject.branches_to_be_notified = "protected"
end
it_behaves_like 'sending email'
it_behaves_like 'sending email', branches_to_be_notified: "protected"
end
context 'notifications are enabled only for default and protected branches ' do
before do
subject.branches_to_be_notified = "default_and_protected"
end
it_behaves_like 'sending email'
it_behaves_like 'sending email', branches_to_be_notified: "default_and_protected"
end
context 'notifications are enabled only for all branches' do
before do
subject.branches_to_be_notified = "all"
end
it_behaves_like 'sending email'
it_behaves_like 'sending email', branches_to_be_notified: "all"
end
end
end
......@@ -265,42 +219,26 @@ describe PipelinesEmailService, :mailer do
end
context 'when the pipeline failed' do
context 'on a default branch' do
context 'on default branch' do
before do
data[:object_attributes][:ref] = project.default_branch
pipeline.update(ref: project.default_branch)
end
context 'notifications are enabled only for default branch' do
before do
subject.branches_to_be_notified = "default"
end
it_behaves_like 'sending email'
it_behaves_like 'sending email', branches_to_be_notified: "default"
end
context 'notifications are enabled only for protected branch' do
before do
subject.branches_to_be_notified = "protected"
end
it_behaves_like 'not sending email'
it_behaves_like 'not sending email', branches_to_be_notified: "protected"
end
context 'notifications are enabled only for default and protected branches ' do
before do
subject.branches_to_be_notified = "default_and_protected"
end
it_behaves_like 'sending email'
it_behaves_like 'sending email', branches_to_be_notified: "default_and_protected"
end
context 'notifications are enabled only for all branches' do
before do
subject.branches_to_be_notified = "all"
end
it_behaves_like 'sending email'
it_behaves_like 'sending email', branches_to_be_notified: "all"
end
end
......@@ -312,35 +250,19 @@ describe PipelinesEmailService, :mailer do
end
context 'notifications are enabled only for default branch' do
before do
subject.branches_to_be_notified = "default"
end
it_behaves_like 'not sending email'
it_behaves_like 'not sending email', branches_to_be_notified: "default"
end
context 'notifications are enabled only for protected branch' do
before do
subject.branches_to_be_notified = "protected"
end
it_behaves_like 'sending email'
it_behaves_like 'sending email', branches_to_be_notified: "protected"
end
context 'notifications are enabled only for default and protected branches ' do
before do
subject.branches_to_be_notified = "default_and_protected"
end
it_behaves_like 'sending email'
it_behaves_like 'sending email', branches_to_be_notified: "default_and_protected"
end
context 'notifications are enabled only for all branches' do
before do
subject.branches_to_be_notified = "all"
end
it_behaves_like 'sending email'
it_behaves_like 'sending email', branches_to_be_notified: "all"
end
end
......@@ -351,35 +273,19 @@ describe PipelinesEmailService, :mailer do
end
context 'notifications are enabled only for default branch' do
before do
subject.branches_to_be_notified = "default"
end
it_behaves_like 'not sending email'
it_behaves_like 'not sending email', branches_to_be_notified: "default"
end
context 'notifications are enabled only for protected branch' do
before do
subject.branches_to_be_notified = "protected"
end
it_behaves_like 'not sending email'
it_behaves_like 'not sending email', branches_to_be_notified: "protected"
end
context 'notifications are enabled only for default and protected branches ' do
before do
subject.branches_to_be_notified = "default_and_protected"
end
it_behaves_like 'not sending email'
it_behaves_like 'not sending email', branches_to_be_notified: "default_and_protected"
end
context 'notifications are enabled only for all branches' do
before do
subject.branches_to_be_notified = "all"
end
it_behaves_like 'sending email'
it_behaves_like 'sending email', branches_to_be_notified: "all"
end
end
end
......
......@@ -3,5 +3,5 @@
require 'spec_helper'
describe SlackService do
it_behaves_like "slack or mattermost notifications"
it_behaves_like "slack or mattermost notifications", "Slack"
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment