File: integration_spec.rb

package info (click to toggle)
ruby-licensee 9.18.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 2,952 kB
  • sloc: xml: 12,037; ruby: 5,141; sh: 29; makefile: 9
file content (418 lines) | stat: -rw-r--r-- 12,865 bytes parent folder | download
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'integration test' do
  [
    Licensee::Projects::FSProject,
    Licensee::Projects::GitProject
  ].each do |project_type|
    context "with a #{project_type} project" do
      subject { project_type.new(project_path, **arguments) }

      let(:filename) { 'LICENSE' }
      let(:license) { Licensee::License.find('mit') }
      let(:other_license) { Licensee::License.find('other') }
      let(:content) { license.content }
      let(:license_path) { File.expand_path(filename, project_path) }
      let(:arguments) { {} }

      context 'fixtures' do
        let(:fixture) { 'mit' }
        let(:project_path) { fixture_path(fixture) }
        let(:git_path) { File.expand_path('.git', project_path) }

        if project_type == Licensee::Projects::GitProject
          before { git_init(project_path) }

          after { FileUtils.rm_rf(git_path) }
        end

        context 'with a folder named license' do
          let(:fixture) { 'license-folder' }

          it "doesn't match" do
            expect(subject.license).to be_nil
          end
        end

        context 'with no license files' do
          let(:project_path) { Dir.mktmpdir }
          let(:file_path) { File.expand_path('foo.md', project_path) }

          before do
            File.write(file_path, 'bar')
            git_init(project_path) if project_type == Licensee::Projects::GitProject
          end

          after { FileUtils.rm_rf(project_path) }

          it 'returns nil' do
            expect(subject.license).to be_nil
            expect(subject.license_files).to be_empty

            expect(subject.matched_file).to be_nil
            expect(subject.matched_files).to be_empty
          end
        end

        context 'with LICENSE.lesser' do
          let(:license) { Licensee::License.find('lgpl-3.0') }
          let(:fixture) { 'lgpl' }

          it 'matches to LGPL' do
            expect(subject.license).to eql(license)
            expect(subject.license_file.path).to eql('COPYING.lesser')
          end
        end

        context 'with multiple license files' do
          let(:fixture) { 'multiple-license-files' }

          it 'matches other' do
            expect(subject.license).to eql(other_license)
          end
        end

        context 'with multiple all rights reserved lines' do
          let(:license) { Licensee::License.find('bsd-3-clause') }
          let(:fixture) { 'multiple-arrs' }

          it 'matches other' do
            expect(subject.license).to eql(license)
          end
        end

        context 'with CC-BY-NC-SA' do
          let(:fixture) { 'cc-by-nc-sa' }

          it 'matches other' do
            expect(subject.license).to eql(other_license)
          end
        end

        context 'with CC-BY-ND' do
          let(:fixture) { 'cc-by-nd' }

          it 'matches other' do
            expect(subject.license).to eql(other_license)
          end
        end

        context 'with WRK Modified Apache 2.0.1' do
          let(:fixture) { 'wrk-modified-apache' }

          it 'matches other' do
            expect(subject.license).to eql(other_license)
          end
        end

        context 'with Pixar Modified Apache 2.0' do
          let(:fixture) { 'pixar-modified-apache' }

          it 'matches other' do
            expect(subject.license).to eql(other_license)
          end
        end

        context 'with FCPL Modified MPL' do
          let(:fixture) { 'fcpl-modified-mpl' }

          it 'matches other' do
            expect(subject.license).to eql(other_license)
          end
        end

        context 'MPL with HRs removed' do
          let(:license) { Licensee::License.find('mpl-2.0') }
          let(:fixture) { 'mpl-without-hrs' }

          it 'matches to MPL' do
            expect(subject.license).to eql(license)
          end
        end

        context 'GPL3 with instructions removed' do
          let(:license) { Licensee::License.find('gpl-3.0') }
          let(:fixture) { 'gpl3-without-instructions' }

          it 'matches to GPL3' do
            expect(subject.license).to eql(license)
          end
        end

        context 'DESCRIPTION file with a LICENSE file' do
          let(:fixture) { 'description-license' }
          let(:arguments) { { detect_packages: true } }

          it 'matches other' do
            expect(subject.license).to eql(other_license)
            expect(subject.package_file.path).to eql('DESCRIPTION')
          end
        end

        context 'A license with CRLF line-endings' do
          let(:license) { Licensee::License.find('gpl-3.0') }
          let(:fixture) { 'crlf-license' }

          it 'matches' do
            expect(subject.license).to eql(license)
          end
        end

        context 'A BSD license with CRLF line-endings' do
          let(:license) { Licensee::License.find('bsd-3-clause') }
          let(:fixture) { 'crlf-bsd' }

          it 'matches' do
            expect(subject.license).to eql(license)
          end
        end

        context 'BSD   PATENTS' do
          let(:license) { Licensee::License.find('other') }
          let(:fixture) { 'bsd-plus-patents' }

          it 'returns other' do
            expect(subject.license).to eql(license)
          end
        end

        context 'BSL' do
          let(:license) { Licensee::License.find('bsl-1.0') }
          let(:fixture) { 'bsl' }

          it 'returns bsl-1.0' do
            expect(subject.license).to eql(license)
          end
        end

        context 'CC0 as published by CC' do
          let(:license) { Licensee::License.find('cc0-1.0') }
          let(:fixture) { 'cc0-cc' }

          it 'returns cc0-1.0' do
            expect(subject.license).to eql(license)
          end
        end

        context 'CC0 as published on choosealicense.com 2013-2019' do
          let(:license) { Licensee::License.find('cc0-1.0') }
          let(:fixture) { 'cc0-cal2013' }

          it 'returns cc0-1.0' do
            expect(subject.license).to eql(license)
          end
        end

        context 'EUPL as published on choosealicense.com 2017-2019' do
          let(:license) { Licensee::License.find('eupl-1.2') }
          let(:fixture) { 'eupl-cal2017' }

          it 'returns eupl-1.2' do
            expect(subject.license).to eql(license)
          end
        end

        context 'Unlicense without optional line' do
          let(:license) { Licensee::License.find('unlicense') }
          let(:fixture) { 'unlicense-noinfo' }

          it 'returns unlicense' do
            expect(subject.license).to eql(license)
          end
        end

        context 'MIT w/optional phrase' do
          let(:license) { Licensee::License.find('mit') }
          let(:fixture) { 'mit-optional' }

          it 'returns mit' do
            expect(subject.license).to eql(license)
          end
        end

        context 'license   README reference' do
          let(:license) { Licensee::License.find('mit') }
          let(:fixture) { 'license-with-readme-reference' }
          let(:arguments) { { detect_readme: true } }

          it 'determines the project is MIT' do
            expect(subject.license).to eql(license)
          end
        end

        context 'apache license   README notice' do
          let(:license) { Licensee::License.find('apache-2.0') }
          let(:fixture) { 'apache-with-readme-notice' }
          let(:arguments) { { detect_readme: true } }

          it 'determines the project is Apache-2.0' do
            expect(subject.license).to eql(license)
          end
        end

        context 'GPL2 with Markdown formatting' do
          let(:license) { Licensee::License.find('gpl-2.0') }
          let(:fixture) { 'gpl-2.0_markdown_headings' }

          it 'matches to GPL2' do
            expect(subject.license).to eql(license)
          end
        end

        context 'Artistic with Markdown formatting' do
          let(:license) { Licensee::License.find('artistic-2.0') }
          let(:fixture) { 'artistic-2.0_markdown' }

          it 'matches to Artistic' do
            expect(subject.license).to eql(license)
          end
        end

        context 'BSD-3-Clause numbered and bulleted' do
          let(:license) { Licensee::License.find('bsd-3-clause') }
          let(:fixture) { 'bsd-3-lists' }

          it 'determines the project is BSD-3-Clause' do
            expect(subject.license).to eql(license)
          end
        end

        context 'BSD-3-Clause no-endorsement name with slashes' do
          let(:license) { Licensee::License.find('bsd-3-clause') }
          let(:fixture) { 'bsd-3-noendorseslash' }

          it 'determines the project is BSD-3-Clause' do
            expect(subject.license).to eql(license)
          end
        end

        context 'BSD-3-Clause author/owner variant' do
          let(:license) { Licensee::License.find('bsd-3-clause') }
          let(:fixture) { 'bsd-3-authorowner' }

          it 'determines the project is BSD-3-Clause' do
            expect(subject.license).to eql(license)
          end
        end

        context 'BSD-2-Clause author variant' do
          let(:license) { Licensee::License.find('bsd-2-clause') }
          let(:fixture) { 'bsd-2-author' }

          it 'determines the project is BSD-2-Clause' do
            expect(subject.license).to eql(license)
          end
        end

        context 'HTML license file' do
          let(:license) { Licensee::License.find('epl-1.0') }
          let(:fixture) { 'html' }

          it 'matches to GPL3' do
            expect(subject.license).to eql(license)
          end
        end

        context 'Vim license file' do
          let(:license) { Licensee::License.find('vim') }
          let(:fixture) { 'vim' }

          it 'matches to Vim' do
            expect(subject.license).to eql(license)
          end
        end

        context 'CC-BY-SA no CC licensor statement license file' do
          let(:license) { Licensee::License.find('cc-by-sa-4.0') }
          let(:fixture) { 'cc-by-sa-nocclicensor' }

          it 'matches to CC-BY-SA' do
            expect(subject.license).to eql(license)
          end
        end

        context 'CC-BY-SA markdown links file' do
          let(:license) { Licensee::License.find('cc-by-sa-4.0') }
          let(:fixture) { 'cc-by-sa-mdlinks' }

          it 'matches to CC-BY-SA' do
            expect(subject.license).to eql(license)
          end
        end

        context 'MIT with byte order mark' do
          let(:license) { Licensee::License.find('mit') }
          let(:fixture) { 'bom' }

          it 'matches to MIT' do
            expect(subject.license).to eql(license)
          end
        end
      end

      context 'with the license file stubbed' do
        let(:project_path) { Dir.mktmpdir }

        before do
          File.write(license_path, content)
          git_init(project_path) if project_type == Licensee::Projects::GitProject
        end

        after { FileUtils.rm_rf(project_path) }

        filenames = [
          'LICENSE.md', 'LICENSE.txt', 'LICENSE.md', 'LiCeNSe.Txt',
          'LICENSE-MIT', 'MIT-LICENSE', 'licence', 'unlicense'
        ]
        filenames.each do |filename|
          context "with a #{filename} file" do
            let(:filename) { filename }

            it 'matches the license file' do
              expect(subject.license).to eql(license)
              expect(subject.license_file.path).to eql(filename)
            end
          end
        end

        context 'a package.json file' do
          let(:content) { '{"license": "mit"}' }
          let(:filename) { 'package.json' }
          let(:license) { Licensee::License.find('mit') }
          let(:arguments) { { detect_packages: true } }

          it 'matches' do
            expect(subject.license).to eql(license)
            expect(subject.package_file.path).to eql(filename)
          end
        end

        context 'a README file' do
          let(:content) { "## License\n#{license.content}" }
          let(:filename) { 'README' }
          let(:license) { Licensee::License.find('mit') }
          let(:arguments) { { detect_readme: true } }

          it 'matches' do
            expect(subject.license).to eql(license)
            expect(subject.readme_file.path).to eql(filename)
          end
        end

        context 'a DESCRIPTION file' do
          let(:content) { "Package: test\nLicense: MIT" }
          let(:filename) { 'DESCRIPTION' }
          let(:license) { Licensee::License.find('mit') }
          let(:arguments) { { detect_packages: true } }

          it 'matches' do
            expect(subject.license).to eql(license)
            expect(subject.package_file.path).to eql(filename)
          end
        end
      end
    end
  end
end