summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/dependency_linker/podspec_json_linker_spec.rb
blob: d4a398c5948706298300a6c5ed55d49aa9bec306 (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
require 'rails_helper'

describe Gitlab::DependencyLinker::PodspecJsonLinker do
  describe '.support?' do
    it 'supports *.podspec.json' do
      expect(described_class.support?('Reachability.podspec.json')).to be_truthy
    end

    it 'does not support other files' do
      expect(described_class.support?('.podspec.json.example')).to be_falsey
    end
  end

  describe '#link' do
    let(:file_name) { "AFNetworking.podspec.json" }

    let(:file_content) do
      <<-CONTENT.strip_heredoc
        {
          "name": "AFNetworking",
          "version": "2.0.0",
          "license": "MIT",
          "summary": "A delightful iOS and OS X networking framework.",
          "homepage": "https://github.com/AFNetworking/AFNetworking",
          "authors": {
            "Mattt Thompson": "m@mattt.me"
          },
          "source": {
            "git": "https://github.com/AFNetworking/AFNetworking.git",
            "tag": "2.0.0",
            "submodules": true
          },
          "requires_arc": true,
          "platforms": {
            "ios": "6.0",
            "osx": "10.8"
          },
          "public_header_files": "AFNetworking/*.h",
          "subspecs": [
            {
              "name": "NSURLConnection",
              "dependencies": {
                "AFNetworking/Serialization": [

                ],
                "AFNetworking/Reachability": [

                ],
                "AFNetworking/Security": [

                ]
              },
              "source_files": [
                "AFNetworking/AFURLConnectionOperation.{h,m}",
                "AFNetworking/AFHTTPRequestOperation.{h,m}",
                "AFNetworking/AFHTTPRequestOperationManager.{h,m}"
              ]
            }
          ]
        }
      CONTENT
    end

    subject { Gitlab::Highlight.highlight(file_name, file_content) }

    def link(name, url)
      %{<a href="#{url}" rel="nofollow noreferrer noopener" target="_blank">#{name}</a>}
    end

    it 'links the gem name' do
      expect(subject).to include(link('AFNetworking', 'https://cocoapods.org/pods/AFNetworking'))
    end

    it 'links the license' do
      expect(subject).to include(link('MIT', 'http://choosealicense.com/licenses/mit/'))
    end

    it 'links the homepage' do
      expect(subject).to include(link('https://github.com/AFNetworking/AFNetworking', 'https://github.com/AFNetworking/AFNetworking'))
    end

    it 'links the source URL' do
      expect(subject).to include(link('https://github.com/AFNetworking/AFNetworking.git', 'https://github.com/AFNetworking/AFNetworking.git'))
    end

    it 'links dependencies' do
      expect(subject).to include(link('AFNetworking/Serialization', 'https://cocoapods.org/pods/AFNetworking'))
      expect(subject).to include(link('AFNetworking/Reachability', 'https://cocoapods.org/pods/AFNetworking'))
      expect(subject).to include(link('AFNetworking/Security', 'https://cocoapods.org/pods/AFNetworking'))
    end

    it 'does not link subspec names' do
      expect(subject).not_to include(link('NSURLConnection', 'https://cocoapods.org/pods/NSURLConnection'))
    end
  end
end