diff options
author | Timothy Andrew <mail@timothyandrew.net> | 2016-09-20 14:48:13 +0530 |
---|---|---|
committer | Timothy Andrew <mail@timothyandrew.net> | 2016-09-20 14:48:13 +0530 |
commit | fa890604aaf15b9e4f0199e6a4cff24c29955a37 (patch) | |
tree | 1606c5585a93d3c0449effbe7b5cc901900833dd /spec/models/project_services/slack_service/pipeline_message_spec.rb | |
parent | 0b97b42d60a662c0d138c44f6dbd05a3048ac349 (diff) | |
parent | 95b9421ad3b2678da6e0af0131eafd52cdd0b2a5 (diff) | |
download | gitlab-ce-fa890604aaf15b9e4f0199e6a4cff24c29955a37.tar.gz |
Merge remote-tracking branch 'origin/master' into 21170-cycle-analytics
Diffstat (limited to 'spec/models/project_services/slack_service/pipeline_message_spec.rb')
-rw-r--r-- | spec/models/project_services/slack_service/pipeline_message_spec.rb | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/spec/models/project_services/slack_service/pipeline_message_spec.rb b/spec/models/project_services/slack_service/pipeline_message_spec.rb new file mode 100644 index 00000000000..babb3909f56 --- /dev/null +++ b/spec/models/project_services/slack_service/pipeline_message_spec.rb @@ -0,0 +1,55 @@ +require 'spec_helper' + +describe SlackService::PipelineMessage do + subject { SlackService::PipelineMessage.new(args) } + + let(:args) do + { + object_attributes: { + id: 123, + sha: '97de212e80737a608d939f648d959671fb0a0142', + tag: false, + ref: 'develop', + status: status, + duration: duration + }, + project: { path_with_namespace: 'project_name', + web_url: 'example.gitlab.com' }, + commit: { author_name: 'hacker' } + } + end + + let(:message) { build_message } + + context 'pipeline succeeded' do + let(:status) { 'success' } + let(:color) { 'good' } + let(:duration) { 10 } + let(:message) { build_message('passed') } + + it 'returns a message with information about succeeded build' do + expect(subject.pretext).to be_empty + expect(subject.fallback).to eq(message) + expect(subject.attachments).to eq([text: message, color: color]) + end + end + + context 'pipeline failed' do + let(:status) { 'failed' } + let(:color) { 'danger' } + let(:duration) { 10 } + + it 'returns a message with information about failed build' do + expect(subject.pretext).to be_empty + expect(subject.fallback).to eq(message) + expect(subject.attachments).to eq([text: message, color: color]) + end + end + + def build_message(status_text = status) + "<example.gitlab.com|project_name>:" \ + " Pipeline <example.gitlab.com/pipelines/123|97de212e>" \ + " of <example.gitlab.com/commits/develop|develop> branch" \ + " by hacker #{status_text} in #{duration} #{'second'.pluralize(duration)}" + end +end |