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 5ffa724e7a47ba72c5c35f2d6dea92d3700f3995..16fe1c930397e814979327c26bcf9c27d1d8f207 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 = ': Commit of 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 = ': Commit of 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 = ': Commit of 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) + ":" \ + " Commit " \ + " of 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 8258f118c13080b9f188a91c5f070d1157393f51..1f1701202b4e0b019a1332b742620463ba03860d 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 = ': Pipeline of 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 = ': Pipeline of 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 = ': Pipeline of 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) + ":" \ + " Pipeline " \ + " of branch" \ + " by hacker #{status_text} in #{duration} #{'second'.pluralize(duration)}" + end end