diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2016-08-29 15:33:36 +0800 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2016-08-29 15:33:36 +0800 |
commit | a97133a6b13b0357f4037d2678569b738046acdb (patch) | |
tree | cb325f3fd84fecb79284b1d02ff0dee7da7c5685 | |
parent | 4fc478a4e0cb88dc72db627cd6081c1456f7ddf8 (diff) | |
download | gitlab-ce-a97133a6b13b0357f4037d2678569b738046acdb.tar.gz |
Shorten the line and use methods, feedback:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/5525#note_14664637
-rw-r--r-- | spec/models/project_services/slack_service/build_message_spec.rb | 17 | ||||
-rw-r--r-- | spec/models/project_services/slack_service/pipeline_message_spec.rb | 16 |
2 files changed, 21 insertions, 12 deletions
diff --git a/spec/models/project_services/slack_service/build_message_spec.rb b/spec/models/project_services/slack_service/build_message_spec.rb index 5ffa724e7a4..16fe1c93039 100644 --- a/spec/models/project_services/slack_service/build_message_spec.rb +++ b/spec/models/project_services/slack_service/build_message_spec.rb @@ -20,14 +20,15 @@ describe SlackService::BuildMessage do } end + let(:message) { build_message } + context '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 - message = '<example.gitlab.com|project_name>: Commit <example.gitlab.com/commit/97de212e80737a608d939f648d959671fb0a0142/builds|97de212e> of <example.gitlab.com/commits/develop|develop> branch by hacker passed in 10 seconds' - expect(subject.pretext).to be_empty expect(subject.fallback).to eq(message) expect(subject.attachments).to eq([text: message, color: color]) @@ -40,8 +41,6 @@ describe SlackService::BuildMessage do let(:duration) { 10 } it 'returns a message with information about failed build' do - message = '<example.gitlab.com|project_name>: Commit <example.gitlab.com/commit/97de212e80737a608d939f648d959671fb0a0142/builds|97de212e> of <example.gitlab.com/commits/develop|develop> branch by hacker failed in 10 seconds' - expect(subject.pretext).to be_empty expect(subject.fallback).to eq(message) expect(subject.attachments).to eq([text: message, color: color]) @@ -54,11 +53,17 @@ describe SlackService::BuildMessage do let(:duration) { 1 } it 'returns seconds as singular when there is only one' do - message = '<example.gitlab.com|project_name>: Commit <example.gitlab.com/commit/97de212e80737a608d939f648d959671fb0a0142/builds|97de212e> of <example.gitlab.com/commits/develop|develop> branch by hacker failed in 1 second' - 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>:" \ + " Commit <example.gitlab.com/commit/" \ + "97de212e80737a608d939f648d959671fb0a0142/builds|97de212e>" \ + " of <example.gitlab.com/commits/develop|develop> branch" \ + " by hacker #{status_text} in #{duration} #{'second'.pluralize(duration)}" + end end diff --git a/spec/models/project_services/slack_service/pipeline_message_spec.rb b/spec/models/project_services/slack_service/pipeline_message_spec.rb index 8258f118c13..1f1701202b4 100644 --- a/spec/models/project_services/slack_service/pipeline_message_spec.rb +++ b/spec/models/project_services/slack_service/pipeline_message_spec.rb @@ -19,14 +19,15 @@ describe SlackService::PipelineMessage do } end + let(:message) { build_message } + context '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 - message = '<example.gitlab.com|project_name>: Pipeline <example.gitlab.com/pipelines/123|97de212e> of <example.gitlab.com/commits/develop|develop> branch by hacker passed in 10 seconds' - expect(subject.pretext).to be_empty expect(subject.fallback).to eq(message) expect(subject.attachments).to eq([text: message, color: color]) @@ -39,8 +40,6 @@ describe SlackService::PipelineMessage do let(:duration) { 10 } it 'returns a message with information about failed build' do - message = '<example.gitlab.com|project_name>: Pipeline <example.gitlab.com/pipelines/123|97de212e> of <example.gitlab.com/commits/develop|develop> branch by hacker failed in 10 seconds' - expect(subject.pretext).to be_empty expect(subject.fallback).to eq(message) expect(subject.attachments).to eq([text: message, color: color]) @@ -53,11 +52,16 @@ describe SlackService::PipelineMessage do let(:duration) { 1 } it 'returns seconds as singular when there is only one' do - message = '<example.gitlab.com|project_name>: Pipeline <example.gitlab.com/pipelines/123|97de212e> of <example.gitlab.com/commits/develop|develop> branch by hacker failed in 1 second' - 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 |