summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/ci/build/credentials/factory_spec.rb
blob: 848adb2e6e53fb7e218071e08cac4fd92c663c1c (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
# frozen_string_literal: true

require 'spec_helper'

describe Gitlab::Ci::Build::Credentials::Factory do
  let(:build) { create(:ci_build, name: 'spinach', stage: 'test', stage_idx: 0) }

  subject { described_class.new(build).create! }

  class TestProvider
    def initialize(build); end
  end

  before do
    allow_next_instance_of(described_class) do |instance|
      allow(instance).to receive(:providers).and_return([TestProvider])
    end
  end

  context 'when provider is valid' do
    before do
      allow_next_instance_of(TestProvider) do |instance|
        allow(instance).to receive(:valid?).and_return(true)
      end
    end

    it 'generates an array of credentials objects' do
      is_expected.to be_kind_of(Array)
      is_expected.not_to be_empty
      expect(subject.first).to be_kind_of(TestProvider)
    end
  end

  context 'when provider is not valid' do
    before do
      allow_next_instance_of(TestProvider) do |instance|
        allow(instance).to receive(:valid?).and_return(false)
      end
    end

    it 'generates an array without specific credential object' do
      is_expected.to be_kind_of(Array)
      is_expected.to be_empty
    end
  end
end