summaryrefslogtreecommitdiff
path: root/spec/services/projects/apple_target_platform_detector_service_spec.rb
blob: 6391161824c5f9d93d7b7ad8c419995604588a26 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Projects::AppleTargetPlatformDetectorService do
  let_it_be(:project) { build(:project) }

  subject { described_class.new(project).execute }

  context 'when project is not an xcode project' do
    before do
      allow(Gitlab::FileFinder).to receive(:new) { instance_double(Gitlab::FileFinder, find: []) }
    end

    it 'returns an empty array' do
      is_expected.to match_array []
    end
  end

  context 'when project is an xcode project' do
    using RSpec::Parameterized::TableSyntax

    let(:finder) { instance_double(Gitlab::FileFinder) }

    before do
      allow(Gitlab::FileFinder).to receive(:new) { finder }
    end

    def search_query(sdk, filename)
      "SDKROOT = #{sdk} filename:#{filename}"
    end

    context 'when setting string is found' do
      where(:sdk, :filename, :result) do
        'iphoneos'  | 'project.pbxproj' | [:ios]
        'iphoneos'  | '*.xcconfig'      | [:ios]
      end

      with_them do
        before do
          allow(finder).to receive(:find).with(anything) { [] }
          allow(finder).to receive(:find).with(search_query(sdk, filename)) { [instance_double(Gitlab::Search::FoundBlob)] }
        end

        it 'returns an array of unique detected targets' do
          is_expected.to match_array result
        end
      end
    end

    context 'when setting string is not found' do
      before do
        allow(finder).to receive(:find).with(anything) { [] }
      end

      it 'returns an empty array' do
        is_expected.to match_array []
      end
    end
  end
end