Commit a97133a6 authored by Lin Jen-Shin's avatar Lin Jen-Shin
parent 4fc478a4
......@@ -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
......@@ -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
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