slack_message_spec.rb 1.61 KB
Newer Older
1
require 'spec_helper'
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

describe SlackMessage do
  subject { SlackMessage.new(args) }

  let(:args) {
    {
      after: 'after',
      before: 'before',
      project_name: 'project_name',
      ref: 'refs/heads/master',
      user_name: 'user_name',
      project_url: 'url'
    }
  }

17 18
  let(:color) { '#345' }

19 20 21
  context 'push' do
    before do
      args[:commits] = [
22 23
        { message: 'message1', url: 'url1', id: 'abcdefghijkl', author: { name: 'author1' } },
        { message: 'message2', url: 'url2', id: '123456789012', author: { name: 'author2' } },
24 25 26 27
      ]
    end

    it 'returns a message regarding pushes' do
28
      subject.pretext.should ==
29
        'user_name pushed to branch <url/commits/master|master> of ' <<
30 31 32 33 34 35 36 37
        '<url|project_name> (<url/compare/before...after|Compare changes>)'
      subject.attachments.should == [
        {
          text: "<url1|abcdefghi>: message1 - author1\n" <<
                "<url2|123456789>: message2 - author2",
          color: color,
        }
      ]
38 39 40 41 42 43 44 45 46
    end
  end

  context 'new branch' do
    before do
      args[:before] = '000000'
    end

    it 'returns a message regarding a new branch' do
47
      subject.pretext.should ==
48 49
        'user_name pushed new branch <url/commits/master|master> to ' <<
        '<url|project_name>'
50
      subject.attachments.should be_empty
51 52 53 54 55 56 57 58 59
    end
  end

  context 'removed branch' do
    before do
      args[:after] = '000000'
    end

    it 'returns a message regarding a removed branch' do
60
      subject.pretext.should ==
61
        'user_name removed branch master from <url|project_name>'
62
      subject.attachments.should be_empty
63 64 65
    end
  end
end