summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/ci/status/build/failed_spec.rb
blob: 78f5214ca816eed8721c0ef59c75fecd00d937d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# frozen_string_literal: true

require 'spec_helper'

describe Gitlab::Ci::Status::Build::Failed do
  let(:build) { create(:ci_build, :script_failure) }
  let(:status) { double('core status') }
  let(:user) { double('user') }

  subject { described_class.new(status) }

  describe '#text' do
    it 'does not override status text' do
      expect(status).to receive(:text)

      subject.text
    end
  end

  describe '#icon' do
    it 'does not override status icon' do
      expect(status).to receive(:icon)

      subject.icon
    end
  end

  describe '#group' do
    it 'does not override status group' do
      expect(status).to receive(:group)

      subject.group
    end
  end

  describe '#favicon' do
    it 'does not override status label' do
      expect(status).to receive(:favicon)

      subject.favicon
    end
  end

  describe '#label' do
    it 'does not override label' do
      expect(status).to receive(:label)

      subject.label
    end
  end

  describe '#badge_tooltip' do
    let(:user) { create(:user) }
    let(:status) { Gitlab::Ci::Status::Failed.new(build, user) }

    it 'does override badge_tooltip' do
      expect(subject.badge_tooltip).to eq 'failed - (script failure)'
    end
  end

  describe '#status_tooltip' do
    let(:user) { create(:user) }
    let(:status) { Gitlab::Ci::Status::Failed.new(build, user) }

    it 'does override status_tooltip' do
      expect(subject.status_tooltip).to eq 'failed - (script failure)'
    end
  end

  describe '.matches?' do
    context 'with a failed build' do
      it 'returns true' do
        expect(described_class.matches?(build, user)).to be_truthy
      end
    end

    context 'with any other type of build' do
      let(:build) { create(:ci_build, :success) }

      it 'returns false' do
        expect(described_class.matches?(build, user)).to be_falsy
      end
    end
  end

  describe 'covers all failure reasons' do
    let(:status) { Gitlab::Ci::Status::Failed.new(build, user) }
    let(:tooltip) { subject.status_tooltip }

    CommitStatus.failure_reasons.keys.each do |failure_reason|
      context failure_reason do
        before do
          build.failure_reason = failure_reason
        end

        it "is a valid status" do
          expect { tooltip }.not_to raise_error
        end
      end
    end

    context 'invalid failure message' do
      before do
        expect(build).to receive(:failure_reason) { 'invalid failure message' }
      end

      it "is an invalid status" do
        expect { tooltip }.to raise_error(/key not found:/)
      end
    end
  end
end