build_message_spec.rb 1.55 KB
Newer Older
1 2
require 'spec_helper'

3 4
describe ChatMessage::BuildMessage do
  subject { described_class.new(args) }
5 6 7 8 9 10 11 12

  let(:args) do
    {
      sha: '97de212e80737a608d939f648d959671fb0a0142',
      ref: 'develop',
      tag: false,

      project_name: 'project_name',
13
      project_url: 'http://example.gitlab.com',
14 15 16 17

      commit: {
        status: status,
        author_name: 'hacker',
Aran Koning's avatar
Aran Koning committed
18
        duration: duration,
19 20 21 22
      },
    }
  end

23 24
  let(:message) { build_message }

25
  context 'build succeeded' do
26 27
    let(:status) { 'success' }
    let(:color) { 'good' }
Aran Koning's avatar
Aran Koning committed
28
    let(:duration) { 10 }
29
    let(:message) { build_message('passed') }
30

31 32 33 34 35 36 37
    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

38
  context 'build failed' do
39 40
    let(:status) { 'failed' }
    let(:color) { 'danger' }
Aran Koning's avatar
Aran Koning committed
41
    let(:duration) { 10 }
42 43

    it 'returns a message with information about failed build' do
Aran Koning's avatar
Aran Koning committed
44 45 46 47
      expect(subject.pretext).to be_empty
      expect(subject.fallback).to eq(message)
      expect(subject.attachments).to eq([text: message, color: color])
    end
48 49
  end

50
  def build_message(status_text = status)
51 52
    "<http://example.gitlab.com|project_name>:" \
    " Commit <http://example.gitlab.com/commit/" \
53
    "97de212e80737a608d939f648d959671fb0a0142/builds|97de212e>" \
54
    " of <http://example.gitlab.com/commits/develop|develop> branch" \
55 56
    " by hacker #{status_text} in #{duration} #{'second'.pluralize(duration)}"
  end
57
end