Commit 76295946 authored by blackst0ne's avatar blackst0ne

DRY specs, fix typos in docs

parent a7439b4a
...@@ -16,7 +16,7 @@ class DiscordService < ChatNotificationService ...@@ -16,7 +16,7 @@ class DiscordService < ChatNotificationService
end end
def help def help
"This service sends notifications about projects events to Discord channels.<br /> "This service sends notifications about project events to Discord channels.<br />
To set up this service: To set up this service:
<ol> <ol>
<li><a href='https://support.discordapp.com/hc/en-us/articles/228383668-Intro-to-Webhooks'>Setup a custom Incoming Webhook</a>.</li> <li><a href='https://support.discordapp.com/hc/en-us/articles/228383668-Intro-to-Webhooks'>Setup a custom Incoming Webhook</a>.</li>
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
The Discord Notifications service sends event notifications from GitLab to the channel for which the webhook was created. The Discord Notifications service sends event notifications from GitLab to the channel for which the webhook was created.
To send GitLab event notifications to a Discord channel, create a webhook in Discourse and configure it in GitLab. To send GitLab event notifications to a Discord channel, create a webhook in Discord and configure it in GitLab.
## Create webhook ## Create webhook
......
...@@ -43,20 +43,12 @@ describe DiscordService do ...@@ -43,20 +43,12 @@ describe DiscordService do
WebMock.stub_request(:post, webhook_url) WebMock.stub_request(:post, webhook_url)
end end
shared_examples "Discord service" do
it "calls Discord Webhooks API" do
subject.execute(sample_data)
expect(WebMock).to have_requested(:post, webhook_url).with { |req| req.body =~ /\A{"content":.+}\Z/ }.once
end
end
context "with push events" do context "with push events" do
let(:sample_data) do let(:sample_data) do
Gitlab::DataBuilder::Push.build_sample(project, user) Gitlab::DataBuilder::Push.build_sample(project, user)
end end
it_behaves_like "Discord service" it_behaves_like "Interacts with external service", "Discord", content_key: :content
it "specifies the webhook when it is configured" do it "specifies the webhook when it is configured" do
expect(Discordrb::Webhooks::Client).to receive(:new).with(url: webhook_url).and_return(double(:discord_service).as_null_object) expect(Discordrb::Webhooks::Client).to receive(:new).with(url: webhook_url).and_return(double(:discord_service).as_null_object)
...@@ -86,7 +78,7 @@ describe DiscordService do ...@@ -86,7 +78,7 @@ describe DiscordService do
subject.notify_only_default_branch = false subject.notify_only_default_branch = false
end end
it_behaves_like "Discord service" it_behaves_like "Interacts with external service", "Discord", content_key: :content
end end
end end
end end
...@@ -99,7 +91,7 @@ describe DiscordService do ...@@ -99,7 +91,7 @@ describe DiscordService do
service.hook_data(issue, "open") service.hook_data(issue, "open")
end end
it_behaves_like "Discord service" it_behaves_like "Interacts with external service", "Discord", content_key: :content
end end
context "with merge events" do context "with merge events" do
...@@ -122,7 +114,7 @@ describe DiscordService do ...@@ -122,7 +114,7 @@ describe DiscordService do
project.add_developer(user) project.add_developer(user)
end end
it_behaves_like "Discord service" it_behaves_like "Interacts with external service", "Discord", content_key: :content
end end
context "with wiki page events" do context "with wiki page events" do
...@@ -137,7 +129,7 @@ describe DiscordService do ...@@ -137,7 +129,7 @@ describe DiscordService do
let(:wiki_page) { create(:wiki_page, wiki: project.wiki, attrs: opts) } let(:wiki_page) { create(:wiki_page, wiki: project.wiki, attrs: opts) }
let(:sample_data) { Gitlab::DataBuilder::WikiPage.build(wiki_page, user, "create") } let(:sample_data) { Gitlab::DataBuilder::WikiPage.build(wiki_page, user, "create") }
it_behaves_like "Discord service" it_behaves_like "Interacts with external service", "Discord", content_key: :content
end end
context "with note events" do context "with note events" do
...@@ -152,7 +144,7 @@ describe DiscordService do ...@@ -152,7 +144,7 @@ describe DiscordService do
note: "a comment on a commit") note: "a comment on a commit")
end end
it_behaves_like "Discord service" it_behaves_like "Interacts with external service", "Discord", content_key: :content
end end
context "with merge request comment" do context "with merge request comment" do
...@@ -160,7 +152,7 @@ describe DiscordService do ...@@ -160,7 +152,7 @@ describe DiscordService do
create(:note_on_merge_request, project: project, note: "merge request note") create(:note_on_merge_request, project: project, note: "merge request note")
end end
it_behaves_like "Discord service" it_behaves_like "Interacts with external service", "Discord", content_key: :content
end end
context "with issue comment" do context "with issue comment" do
...@@ -168,7 +160,7 @@ describe DiscordService do ...@@ -168,7 +160,7 @@ describe DiscordService do
create(:note_on_issue, project: project, note: "issue note") create(:note_on_issue, project: project, note: "issue note")
end end
it_behaves_like "Discord service" it_behaves_like "Interacts with external service", "Discord", content_key: :content
end end
context "with snippet comment" do context "with snippet comment" do
...@@ -176,7 +168,7 @@ describe DiscordService do ...@@ -176,7 +168,7 @@ describe DiscordService do
create(:note_on_project_snippet, project: project, note: "snippet note") create(:note_on_project_snippet, project: project, note: "snippet note")
end end
it_behaves_like "Discord service" it_behaves_like "Interacts with external service", "Discord", content_key: :content
end end
end end
...@@ -191,7 +183,7 @@ describe DiscordService do ...@@ -191,7 +183,7 @@ describe DiscordService do
context "with failed pipeline" do context "with failed pipeline" do
let(:status) { "failed" } let(:status) { "failed" }
it_behaves_like "Discord service" it_behaves_like "Interacts with external service", "Discord", content_key: :content
end end
context "with succeeded pipeline" do context "with succeeded pipeline" do
...@@ -210,7 +202,7 @@ describe DiscordService do ...@@ -210,7 +202,7 @@ describe DiscordService do
subject.notify_only_broken_pipelines = false subject.notify_only_broken_pipelines = false
end end
it_behaves_like "Discord service" it_behaves_like "Interacts with external service", "Discord", content_key: :content
end end
end end
...@@ -236,7 +228,7 @@ describe DiscordService do ...@@ -236,7 +228,7 @@ describe DiscordService do
subject.notify_only_default_branch = false subject.notify_only_default_branch = false
end end
it_behaves_like "Discord service" it_behaves_like "Interacts with external service", "Discord", content_key: :content
end end
end end
end end
......
...@@ -41,23 +41,12 @@ describe HangoutsChatService do ...@@ -41,23 +41,12 @@ describe HangoutsChatService do
WebMock.stub_request(:post, webhook_url) WebMock.stub_request(:post, webhook_url)
end end
shared_examples 'Hangouts Chat service' do
it 'calls Hangouts Chat API' do
subject.execute(sample_data)
expect(WebMock)
.to have_requested(:post, webhook_url)
.with { |req| req.body =~ /\A{"text":.+}\Z/ }
.once
end
end
context 'with push events' do context 'with push events' do
let(:sample_data) do let(:sample_data) do
Gitlab::DataBuilder::Push.build_sample(project, user) Gitlab::DataBuilder::Push.build_sample(project, user)
end end
it_behaves_like 'Hangouts Chat service' it_behaves_like "Interacts with external service", "Hangouts Chat", content_key: :text
it 'specifies the webhook when it is configured' do it 'specifies the webhook when it is configured' do
expect(HangoutsChat::Sender).to receive(:new).with(webhook_url).and_return(double(:hangouts_chat_service).as_null_object) expect(HangoutsChat::Sender).to receive(:new).with(webhook_url).and_return(double(:hangouts_chat_service).as_null_object)
...@@ -87,7 +76,7 @@ describe HangoutsChatService do ...@@ -87,7 +76,7 @@ describe HangoutsChatService do
subject.notify_only_default_branch = false subject.notify_only_default_branch = false
end end
it_behaves_like 'Hangouts Chat service' it_behaves_like "Interacts with external service", "Hangouts Chat", content_key: :text
end end
end end
end end
...@@ -100,7 +89,7 @@ describe HangoutsChatService do ...@@ -100,7 +89,7 @@ describe HangoutsChatService do
service.hook_data(issue, 'open') service.hook_data(issue, 'open')
end end
it_behaves_like 'Hangouts Chat service' it_behaves_like "Interacts with external service", "Hangouts Chat", content_key: :text
end end
context 'with merge events' do context 'with merge events' do
...@@ -123,7 +112,7 @@ describe HangoutsChatService do ...@@ -123,7 +112,7 @@ describe HangoutsChatService do
project.add_developer(user) project.add_developer(user)
end end
it_behaves_like 'Hangouts Chat service' it_behaves_like "Interacts with external service", "Hangouts Chat", content_key: :text
end end
context 'with wiki page events' do context 'with wiki page events' do
...@@ -138,7 +127,7 @@ describe HangoutsChatService do ...@@ -138,7 +127,7 @@ describe HangoutsChatService do
let(:wiki_page) { create(:wiki_page, wiki: project.wiki, attrs: opts) } let(:wiki_page) { create(:wiki_page, wiki: project.wiki, attrs: opts) }
let(:sample_data) { Gitlab::DataBuilder::WikiPage.build(wiki_page, user, 'create') } let(:sample_data) { Gitlab::DataBuilder::WikiPage.build(wiki_page, user, 'create') }
it_behaves_like 'Hangouts Chat service' it_behaves_like "Interacts with external service", "Hangouts Chat", content_key: :text
end end
context 'with note events' do context 'with note events' do
...@@ -152,7 +141,7 @@ describe HangoutsChatService do ...@@ -152,7 +141,7 @@ describe HangoutsChatService do
note: 'a comment on a commit') note: 'a comment on a commit')
end end
it_behaves_like 'Hangouts Chat service' it_behaves_like "Interacts with external service", "Hangouts Chat", content_key: :text
end end
context 'with merge request comment' do context 'with merge request comment' do
...@@ -161,7 +150,7 @@ describe HangoutsChatService do ...@@ -161,7 +150,7 @@ describe HangoutsChatService do
note: 'merge request note') note: 'merge request note')
end end
it_behaves_like 'Hangouts Chat service' it_behaves_like "Interacts with external service", "Hangouts Chat", content_key: :text
end end
context 'with issue comment' do context 'with issue comment' do
...@@ -169,7 +158,7 @@ describe HangoutsChatService do ...@@ -169,7 +158,7 @@ describe HangoutsChatService do
create(:note_on_issue, project: project, note: 'issue note') create(:note_on_issue, project: project, note: 'issue note')
end end
it_behaves_like 'Hangouts Chat service' it_behaves_like "Interacts with external service", "Hangouts Chat", content_key: :text
end end
context 'with snippet comment' do context 'with snippet comment' do
...@@ -178,7 +167,7 @@ describe HangoutsChatService do ...@@ -178,7 +167,7 @@ describe HangoutsChatService do
note: 'snippet note') note: 'snippet note')
end end
it_behaves_like 'Hangouts Chat service' it_behaves_like "Interacts with external service", "Hangouts Chat", content_key: :text
end end
end end
...@@ -193,7 +182,7 @@ describe HangoutsChatService do ...@@ -193,7 +182,7 @@ describe HangoutsChatService do
context 'with failed pipeline' do context 'with failed pipeline' do
let(:status) { 'failed' } let(:status) { 'failed' }
it_behaves_like 'Hangouts Chat service' it_behaves_like "Interacts with external service", "Hangouts Chat", content_key: :text
end end
context 'with succeeded pipeline' do context 'with succeeded pipeline' do
...@@ -212,7 +201,7 @@ describe HangoutsChatService do ...@@ -212,7 +201,7 @@ describe HangoutsChatService do
subject.notify_only_broken_pipelines = false subject.notify_only_broken_pipelines = false
end end
it_behaves_like 'Hangouts Chat service' it_behaves_like "Interacts with external service", "Hangouts Chat", content_key: :text
end end
end end
...@@ -238,7 +227,7 @@ describe HangoutsChatService do ...@@ -238,7 +227,7 @@ describe HangoutsChatService do
subject.notify_only_default_branch = false subject.notify_only_default_branch = false
end end
it_behaves_like 'Hangouts Chat service' it_behaves_like "Interacts with external service", "Hangouts Chat", content_key: :text
end end
end end
end end
......
require "spec_helper"
shared_examples_for "Interacts with external service" do |service_name, content_key:|
it "calls #{service_name} Webhooks API" do
subject.execute(sample_data)
expect(WebMock).to have_requested(:post, webhook_url).with { |req| req.body =~ /\A{"#{content_key}":.+}\Z/ }.once
end
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