licensee 9.10.0 → 9.13.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/licensee +5 -4
- data/lib/licensee.rb +4 -2
- data/lib/licensee/commands/detect.rb +10 -5
- data/lib/licensee/commands/diff.rb +7 -8
- data/lib/licensee/commands/license_path.rb +2 -0
- data/lib/licensee/commands/version.rb +2 -0
- data/lib/licensee/content_helper.rb +234 -85
- data/lib/licensee/hash_helper.rb +7 -5
- data/lib/licensee/license.rb +32 -25
- data/lib/licensee/license_field.rb +4 -1
- data/lib/licensee/license_meta.rb +3 -0
- data/lib/licensee/license_rules.rb +2 -0
- data/lib/licensee/matchers.rb +2 -0
- data/lib/licensee/matchers/cabal.rb +16 -2
- data/lib/licensee/matchers/cargo.rb +3 -1
- data/lib/licensee/matchers/copyright.rb +6 -4
- data/lib/licensee/matchers/cran.rb +7 -3
- data/lib/licensee/matchers/dice.rb +6 -4
- data/lib/licensee/matchers/dist_zilla.rb +3 -1
- data/lib/licensee/matchers/exact.rb +3 -0
- data/lib/licensee/matchers/gemspec.rb +8 -5
- data/lib/licensee/matchers/matcher.rb +3 -1
- data/lib/licensee/matchers/npm_bower.rb +3 -1
- data/lib/licensee/matchers/package.rb +3 -0
- data/lib/licensee/matchers/reference.rb +3 -1
- data/lib/licensee/matchers/spdx.rb +3 -1
- data/lib/licensee/project_files.rb +2 -0
- data/lib/licensee/project_files/license_file.rb +13 -10
- data/lib/licensee/project_files/package_manager_file.rb +3 -0
- data/lib/licensee/project_files/project_file.rb +12 -4
- data/lib/licensee/project_files/readme_file.rb +5 -3
- data/lib/licensee/projects.rb +2 -0
- data/lib/licensee/projects/fs_project.rb +3 -0
- data/lib/licensee/projects/git_project.rb +19 -11
- data/lib/licensee/projects/github_project.rb +6 -1
- data/lib/licensee/projects/project.rb +16 -5
- data/lib/licensee/rule.rb +2 -0
- data/lib/licensee/version.rb +3 -1
- data/licensee.gemspec +47 -0
- data/spec/bin_spec.rb +3 -1
- data/spec/fixture_spec.rb +46 -0
- data/spec/fixtures/bsd-3-noendorseslash/LICENSE +30 -0
- data/spec/fixtures/cc0-cal2013/LICENSE +116 -0
- data/spec/fixtures/cc0-cc/LICENSE +121 -0
- data/spec/fixtures/detect.json +9 -7
- data/spec/fixtures/fixtures.yml +130 -0
- data/spec/fixtures/html/license.html +262 -0
- data/spec/fixtures/license-hashes.json +41 -0
- data/spec/fixtures/mit-optional/LICENSE.txt +21 -0
- data/spec/fixtures/multiple-arrs/LICENSE +30 -0
- data/spec/fixtures/unlicense-noinfo/LICENSE +22 -0
- data/spec/integration_spec.rb +68 -2
- data/spec/licensee/commands/detect_spec.rb +10 -6
- data/spec/licensee/commands/license_path_spec.rb +3 -1
- data/spec/licensee/commands/version_spec.rb +3 -1
- data/spec/licensee/content_helper_spec.rb +184 -67
- data/spec/licensee/hash_helper_spec.rb +3 -1
- data/spec/licensee/license_field_spec.rb +5 -3
- data/spec/licensee/license_meta_spec.rb +16 -12
- data/spec/licensee/license_rules_spec.rb +6 -2
- data/spec/licensee/license_spec.rb +62 -37
- data/spec/licensee/matchers/cabal_matcher_spec.rb +97 -2
- data/spec/licensee/matchers/cargo_matcher_spec.rb +5 -2
- data/spec/licensee/matchers/copyright_matcher_spec.rb +7 -5
- data/spec/licensee/matchers/cran_matcher_spec.rb +5 -2
- data/spec/licensee/matchers/dice_matcher_spec.rb +15 -12
- data/spec/licensee/matchers/dist_zilla_matcher_spec.rb +5 -2
- data/spec/licensee/matchers/exact_matcher_spec.rb +5 -2
- data/spec/licensee/matchers/gemspec_matcher_spec.rb +5 -2
- data/spec/licensee/matchers/matcher_spec.rb +6 -2
- data/spec/licensee/matchers/npm_bower_matcher_spec.rb +5 -3
- data/spec/licensee/matchers/package_matcher_spec.rb +6 -2
- data/spec/licensee/matchers/reference_matcher_spec.rb +4 -2
- data/spec/licensee/matchers/spdx_matcher_spec.rb +5 -2
- data/spec/licensee/project_files/license_file_spec.rb +20 -18
- data/spec/licensee/project_files/package_info_spec.rb +5 -1
- data/spec/licensee/project_files/project_file_spec.rb +8 -2
- data/spec/licensee/project_files/readme_file_spec.rb +4 -1
- data/spec/licensee/project_spec.rb +24 -17
- data/spec/licensee/projects/git_project_spec.rb +23 -0
- data/spec/licensee/projects/github_project_spec.rb +8 -5
- data/spec/licensee/rule_spec.rb +6 -3
- data/spec/licensee_spec.rb +12 -9
- data/spec/spec_helper.rb +28 -9
- data/spec/vendored_license_spec.rb +29 -10
- data/vendor/choosealicense.com/_data/meta.yml +0 -4
- data/vendor/choosealicense.com/_data/rules.yml +3 -0
- data/vendor/choosealicense.com/_licenses/0bsd.txt +39 -0
- data/vendor/choosealicense.com/_licenses/afl-3.0.txt +7 -6
- data/vendor/choosealicense.com/_licenses/agpl-3.0.txt +0 -1
- data/vendor/choosealicense.com/_licenses/apache-2.0.txt +1 -2
- data/vendor/choosealicense.com/_licenses/artistic-2.0.txt +1 -2
- data/vendor/choosealicense.com/_licenses/bsd-2-clause.txt +8 -6
- data/vendor/choosealicense.com/_licenses/bsd-3-clause-clear.txt +2 -2
- data/vendor/choosealicense.com/_licenses/bsd-3-clause.txt +12 -10
- data/vendor/choosealicense.com/_licenses/bsd-4-clause.txt +61 -0
- data/vendor/choosealicense.com/_licenses/bsl-1.0.txt +5 -2
- data/vendor/choosealicense.com/_licenses/cc-by-4.0.txt +3 -1
- data/vendor/choosealicense.com/_licenses/cc-by-sa-4.0.txt +3 -1
- data/vendor/choosealicense.com/_licenses/cc0-1.0.txt +113 -105
- data/vendor/choosealicense.com/_licenses/cecill-2.1.txt +579 -0
- data/vendor/choosealicense.com/_licenses/ecl-2.0.txt +1 -2
- data/vendor/choosealicense.com/_licenses/epl-1.0.txt +1 -2
- data/vendor/choosealicense.com/_licenses/epl-2.0.txt +3 -4
- data/vendor/choosealicense.com/_licenses/eupl-1.1.txt +0 -1
- data/vendor/choosealicense.com/_licenses/eupl-1.2.txt +0 -1
- data/vendor/choosealicense.com/_licenses/gpl-2.0.txt +0 -1
- data/vendor/choosealicense.com/_licenses/gpl-3.0.txt +1 -2
- data/vendor/choosealicense.com/_licenses/isc.txt +0 -1
- data/vendor/choosealicense.com/_licenses/lgpl-2.1.txt +0 -1
- data/vendor/choosealicense.com/_licenses/lgpl-3.0.txt +1 -3
- data/vendor/choosealicense.com/_licenses/lppl-1.3c.txt +1 -2
- data/vendor/choosealicense.com/_licenses/mit.txt +1 -2
- data/vendor/choosealicense.com/_licenses/mpl-2.0.txt +0 -1
- data/vendor/choosealicense.com/_licenses/ms-pl.txt +0 -1
- data/vendor/choosealicense.com/_licenses/ms-rl.txt +0 -1
- data/vendor/choosealicense.com/_licenses/ncsa.txt +21 -22
- data/vendor/choosealicense.com/_licenses/odbl-1.0.txt +573 -0
- data/vendor/choosealicense.com/_licenses/ofl-1.1.txt +4 -2
- data/vendor/choosealicense.com/_licenses/osl-3.0.txt +1 -2
- data/vendor/choosealicense.com/_licenses/postgresql.txt +4 -5
- data/vendor/choosealicense.com/_licenses/unlicense.txt +1 -2
- data/vendor/choosealicense.com/_licenses/upl-1.0.txt +4 -5
- data/vendor/choosealicense.com/_licenses/vim.txt +111 -0
- data/vendor/choosealicense.com/_licenses/wtfpl.txt +0 -1
- data/vendor/choosealicense.com/_licenses/zlib.txt +4 -2
- metadata +77 -19
@@ -1,7 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
RSpec.describe Licensee::ProjectFiles::PackageManagerFile do
|
4
|
+
subject { described_class.new(content, filename) }
|
5
|
+
|
2
6
|
let(:content) { '' }
|
3
7
|
let(:filename) { '' }
|
4
|
-
subject { described_class.new(content, filename) }
|
5
8
|
|
6
9
|
context 'name scoring' do
|
7
10
|
{
|
@@ -17,6 +20,7 @@ RSpec.describe Licensee::ProjectFiles::PackageManagerFile do
|
|
17
20
|
}.each do |filename, expected_score|
|
18
21
|
context "a file named #{filename}" do
|
19
22
|
let(:score) { described_class.name_score(filename) }
|
23
|
+
|
20
24
|
it 'scores the file' do
|
21
25
|
expect(score).to eql(expected_score)
|
22
26
|
end
|
@@ -1,14 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
RSpec.describe Licensee::ProjectFiles::ProjectFile do
|
4
|
+
subject { Licensee::ProjectFiles::LicenseFile.new(content, filename) }
|
5
|
+
|
2
6
|
let(:filename) { 'LICENSE.txt' }
|
3
7
|
let(:mit) { Licensee::License.find('mit') }
|
4
8
|
let(:content) { mit.content }
|
5
9
|
let(:possible_matchers) { [Licensee::Matchers::Exact] }
|
6
10
|
|
7
|
-
subject { Licensee::ProjectFiles::LicenseFile.new(content, filename) }
|
8
11
|
before do
|
9
12
|
allow(subject).to receive(:possible_matchers).and_return(possible_matchers)
|
10
13
|
end
|
14
|
+
|
11
15
|
before { allow(subject).to receive(:length).and_return(mit.length) }
|
16
|
+
|
12
17
|
before { allow(subject).to receive(:wordset).and_return(mit.wordset) }
|
13
18
|
|
14
19
|
it 'stores the content' do
|
@@ -24,7 +29,7 @@ RSpec.describe Licensee::ProjectFiles::ProjectFile do
|
|
24
29
|
end
|
25
30
|
|
26
31
|
it 'returns the confidence' do
|
27
|
-
expect(subject.confidence).to
|
32
|
+
expect(subject.confidence).to be(100)
|
28
33
|
end
|
29
34
|
|
30
35
|
it 'returns the license' do
|
@@ -48,6 +53,7 @@ RSpec.describe Licensee::ProjectFiles::ProjectFile do
|
|
48
53
|
let(:hash) { subject.to_h }
|
49
54
|
let(:expected) do
|
50
55
|
{
|
56
|
+
attribution: 'Copyright (c) [year] [fullname]',
|
51
57
|
filename: 'LICENSE.txt',
|
52
58
|
content: mit.content.to_s,
|
53
59
|
content_hash: subject.content_hash,
|
@@ -1,7 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
RSpec.describe Licensee::ProjectFiles::ReadmeFile do
|
4
|
+
subject { described_class.new(content, filename) }
|
5
|
+
|
2
6
|
let(:filename) { 'README.md' }
|
3
7
|
let(:content) { '' }
|
4
|
-
subject { described_class.new(content, filename) }
|
5
8
|
|
6
9
|
context 'scoring names' do
|
7
10
|
{
|
@@ -1,16 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
[
|
2
4
|
Licensee::Projects::FSProject,
|
3
5
|
Licensee::Projects::GitProject,
|
4
6
|
Licensee::Projects::GitHubProject
|
5
7
|
].each do |project_type|
|
6
8
|
RSpec.describe project_type do
|
9
|
+
subject { described_class.new(path) }
|
10
|
+
|
7
11
|
let(:stubbed_org) { '_licensee_test_fixture' }
|
8
12
|
let(:mit) { Licensee::License.find('mit') }
|
9
13
|
let(:other) { Licensee::License.find('other') }
|
10
14
|
let(:fixture) { 'mit' }
|
11
15
|
let(:path) { fixture_path(fixture) }
|
12
16
|
let(:api_base) { 'https://api.github.com/repos' }
|
13
|
-
subject { described_class.new(path) }
|
14
17
|
|
15
18
|
if described_class == Licensee::Projects::GitProject
|
16
19
|
before do
|
@@ -44,14 +47,16 @@
|
|
44
47
|
.to_return(status: 200, body: File.read(file))
|
45
48
|
end
|
46
49
|
end
|
50
|
+
|
47
51
|
let(:path) { "https://github.com/#{stubbed_org}/#{fixture}" }
|
48
52
|
end
|
49
53
|
|
50
54
|
if described_class == Licensee::Projects::GitProject
|
51
55
|
context 'when initialized with a repo' do
|
52
|
-
let(:repo) { Rugged::Repository.new(path) }
|
53
56
|
subject { described_class.new(repo) }
|
54
57
|
|
58
|
+
let(:repo) { Rugged::Repository.new(path) }
|
59
|
+
|
55
60
|
it 'returns the repository' do
|
56
61
|
expect(subject.repository).to be_a(Rugged::Repository)
|
57
62
|
end
|
@@ -59,6 +64,7 @@
|
|
59
64
|
|
60
65
|
context 'when initialized with a revision' do
|
61
66
|
let(:revision) { subject.repository.last_commit.oid }
|
67
|
+
|
62
68
|
before do
|
63
69
|
subject.instance_variable_set('@revision', revision)
|
64
70
|
end
|
@@ -96,9 +102,9 @@
|
|
96
102
|
let(:files) { subject.send(:files) }
|
97
103
|
|
98
104
|
it 'returns the file list' do
|
99
|
-
expect(files.count).to
|
105
|
+
expect(files.count).to be(2)
|
100
106
|
license = files.find { |f| f[:name] == 'LICENSE.txt' }
|
101
|
-
expect(license).
|
107
|
+
expect(license).not_to be_nil
|
102
108
|
|
103
109
|
if described_class == Licensee::Projects::GitProject
|
104
110
|
expect(files.first).to have_key(:oid)
|
@@ -121,7 +127,7 @@
|
|
121
127
|
|
122
128
|
it 'looks for licenses in parent directories up to the search root' do
|
123
129
|
# should not include the license in 'license-in-parent-folder' dir
|
124
|
-
expect(files.count).to
|
130
|
+
expect(files.count).to be(1)
|
125
131
|
expect(files.first[:name]).to eql('LICENSE.txt')
|
126
132
|
end
|
127
133
|
end
|
@@ -130,7 +136,7 @@
|
|
130
136
|
let(:fixture) { 'license-in-parent-folder/license-folder/package' }
|
131
137
|
|
132
138
|
it 'looks for licenses in current directory only' do
|
133
|
-
expect(files.count).to
|
139
|
+
expect(files.count).to be(0)
|
134
140
|
end
|
135
141
|
end
|
136
142
|
end
|
@@ -147,9 +153,10 @@
|
|
147
153
|
end
|
148
154
|
|
149
155
|
context 'readme detection' do
|
150
|
-
let(:fixture) { 'readme' }
|
151
156
|
subject { described_class.new(path, detect_readme: true) }
|
152
157
|
|
158
|
+
let(:fixture) { 'readme' }
|
159
|
+
|
153
160
|
it 'returns the readme' do
|
154
161
|
expect(subject.readme_file).to be_a(Licensee::ProjectFiles::ReadmeFile)
|
155
162
|
expect(subject.readme_file.filename).to eql('README.md')
|
@@ -162,6 +169,8 @@
|
|
162
169
|
end
|
163
170
|
|
164
171
|
context 'package manager detection' do
|
172
|
+
subject { described_class.new(path, detect_packages: true) }
|
173
|
+
|
165
174
|
let(:fixture) { 'gemspec' }
|
166
175
|
|
167
176
|
# Using a `.gemspec` extension in the fixture breaks `gem release`
|
@@ -200,8 +209,6 @@
|
|
200
209
|
FileUtils.rm("#{fixture_path(fixture)}/project.gemspec")
|
201
210
|
end
|
202
211
|
|
203
|
-
subject { described_class.new(path, detect_packages: true) }
|
204
|
-
|
205
212
|
it 'returns the package file' do
|
206
213
|
expected = Licensee::ProjectFiles::PackageManagerFile
|
207
214
|
expect(subject.package_file).to be_a(expected)
|
@@ -230,19 +237,19 @@
|
|
230
237
|
end
|
231
238
|
|
232
239
|
it 'returns both licenses' do
|
233
|
-
expect(subject.licenses.count).to
|
240
|
+
expect(subject.licenses.count).to be(2)
|
234
241
|
expect(subject.licenses.first).to eql(Licensee::License.find('mpl-2.0'))
|
235
242
|
expect(subject.licenses.last).to eql(mit)
|
236
243
|
end
|
237
244
|
|
238
245
|
it 'returns both matched_files' do
|
239
|
-
expect(subject.matched_files.count).to
|
246
|
+
expect(subject.matched_files.count).to be(2)
|
240
247
|
expect(subject.matched_files.first.filename).to eql('LICENSE')
|
241
248
|
expect(subject.matched_files.last.filename).to eql('LICENSE.txt')
|
242
249
|
end
|
243
250
|
|
244
251
|
it 'returns both license_files' do
|
245
|
-
expect(subject.license_files.count).to
|
252
|
+
expect(subject.license_files.count).to be(2)
|
246
253
|
expect(subject.license_files.first.filename).to eql('LICENSE')
|
247
254
|
expect(subject.license_files.last.filename).to eql('LICENSE.txt')
|
248
255
|
end
|
@@ -258,29 +265,29 @@
|
|
258
265
|
end
|
259
266
|
|
260
267
|
it 'matched_file returns copying.lesser' do
|
261
|
-
expect(subject.matched_file).
|
268
|
+
expect(subject.matched_file).not_to be_nil
|
262
269
|
expect(subject.matched_file.filename).to eql('COPYING.lesser')
|
263
270
|
end
|
264
271
|
|
265
272
|
it 'license_file returns copying.lesser' do
|
266
|
-
expect(subject.license_file).
|
273
|
+
expect(subject.license_file).not_to be_nil
|
267
274
|
expect(subject.license_file.filename).to eql('COPYING.lesser')
|
268
275
|
end
|
269
276
|
|
270
277
|
it 'returns both licenses' do
|
271
|
-
expect(subject.licenses.count).to
|
278
|
+
expect(subject.licenses.count).to be(2)
|
272
279
|
expect(subject.licenses.first).to eql(lgpl)
|
273
280
|
expect(subject.licenses.last).to eql(gpl)
|
274
281
|
end
|
275
282
|
|
276
283
|
it 'returns both matched_files' do
|
277
|
-
expect(subject.matched_files.count).to
|
284
|
+
expect(subject.matched_files.count).to be(2)
|
278
285
|
expect(subject.matched_files.first.filename).to eql('COPYING.lesser')
|
279
286
|
expect(subject.matched_files.last.filename).to eql('LICENSE')
|
280
287
|
end
|
281
288
|
|
282
289
|
it 'returns both license_files' do
|
283
|
-
expect(subject.license_files.count).to
|
290
|
+
expect(subject.license_files.count).to be(2)
|
284
291
|
expect(subject.license_files.first.filename).to eql('COPYING.lesser')
|
285
292
|
expect(subject.license_files.last.filename).to eql('LICENSE')
|
286
293
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Licensee::Projects::GitProject do
|
4
|
+
let(:fixture) { 'mit' }
|
5
|
+
|
6
|
+
context 'new git repo handled as file system project' do
|
7
|
+
let(:path) { fixture_path(fixture) }
|
8
|
+
|
9
|
+
before do
|
10
|
+
Dir.chdir path do
|
11
|
+
`git init`
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
after do
|
16
|
+
FileUtils.rm_rf File.expand_path '.git', path
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'raises InvalidRepository error' do
|
20
|
+
expect { described_class.new(path) }.to raise_error(ArgumentError)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,14 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
RSpec.describe Licensee::Projects::GitHubProject do
|
4
|
+
subject(:instance) { described_class.new(github_url) }
|
5
|
+
|
2
6
|
let(:repo) { 'benbalter/licensee' }
|
3
7
|
let(:github_url) { "https://github.com/#{repo}" }
|
4
8
|
let(:mit) { Licensee::License.find('mit') }
|
5
9
|
let(:readme_file) { File.read(fixture_path('mit/README.md')) }
|
6
10
|
let(:license_file) { File.read(fixture_path('mit/LICENSE.txt')) }
|
7
|
-
subject(:instance) { described_class.new(github_url) }
|
8
11
|
|
9
12
|
describe '#initialize' do
|
10
13
|
context 'with a GitHub URI' do
|
11
|
-
it '
|
14
|
+
it 'sets @repo' do
|
12
15
|
expect(instance.repo).to eq(repo)
|
13
16
|
end
|
14
17
|
end
|
@@ -16,7 +19,7 @@ RSpec.describe Licensee::Projects::GitHubProject do
|
|
16
19
|
context 'with a GitHub git URI' do
|
17
20
|
let(:github_url) { "https://github.com/#{repo}.git" }
|
18
21
|
|
19
|
-
it '
|
22
|
+
it 'sets @repo, stripping the trailing extension' do
|
20
23
|
expect(instance.repo).to eq(repo)
|
21
24
|
end
|
22
25
|
end
|
@@ -24,7 +27,7 @@ RSpec.describe Licensee::Projects::GitHubProject do
|
|
24
27
|
context 'with a non-GitHub URI' do
|
25
28
|
let(:github_url) { "https://gitlab.com/#{repo}" }
|
26
29
|
|
27
|
-
it '
|
30
|
+
it 'raises an ArgumentError' do
|
28
31
|
expect { instance }.to raise_error(ArgumentError)
|
29
32
|
end
|
30
33
|
end
|
@@ -32,7 +35,7 @@ RSpec.describe Licensee::Projects::GitHubProject do
|
|
32
35
|
context 'with a local folder' do
|
33
36
|
let(:github_url) { fixture_path('mit') }
|
34
37
|
|
35
|
-
it '
|
38
|
+
it 'raises an ArgumentError' do
|
36
39
|
expect { instance }.to raise_error(ArgumentError)
|
37
40
|
end
|
38
41
|
end
|
data/spec/licensee/rule_spec.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
RSpec.describe Licensee::Rule do
|
2
|
-
let(:groups) { %w[permissions conditions limitations] }
|
3
4
|
subject do
|
4
5
|
described_class.new(
|
5
6
|
description: 'description',
|
@@ -9,6 +10,8 @@ RSpec.describe Licensee::Rule do
|
|
9
10
|
)
|
10
11
|
end
|
11
12
|
|
13
|
+
let(:groups) { %w[permissions conditions limitations] }
|
14
|
+
|
12
15
|
it 'stores properties' do
|
13
16
|
expect(subject.tag).to eql('tag')
|
14
17
|
expect(subject.label).to eql('label')
|
@@ -28,7 +31,7 @@ RSpec.describe Licensee::Rule do
|
|
28
31
|
|
29
32
|
it 'determines the file path' do
|
30
33
|
path = described_class.file_path
|
31
|
-
expect(File.exist?(path)).to
|
34
|
+
expect(File.exist?(path)).to be(true)
|
32
35
|
end
|
33
36
|
|
34
37
|
it 'loads a rule by tag' do
|
@@ -50,7 +53,7 @@ RSpec.describe Licensee::Rule do
|
|
50
53
|
end
|
51
54
|
|
52
55
|
it 'loads all rules' do
|
53
|
-
expect(described_class.all.count).to
|
56
|
+
expect(described_class.all.count).to be(17)
|
54
57
|
rule = described_class.all.first
|
55
58
|
expect(rule).to be_a(described_class)
|
56
59
|
expect(rule.tag).to eql('commercial-use')
|
data/spec/licensee_spec.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
RSpec.describe Licensee do
|
2
4
|
let(:project_path) { fixture_path('mit') }
|
3
5
|
let(:license_path) { fixture_path('mit/LICENSE.txt') }
|
4
6
|
let(:mit_license) { Licensee::License.find('mit') }
|
5
|
-
let(:hidden_license_count) {
|
7
|
+
let(:hidden_license_count) { 41 }
|
6
8
|
|
7
9
|
it 'exposes licenses' do
|
8
10
|
expect(described_class.licenses).to be_an(Array)
|
@@ -12,15 +14,15 @@ RSpec.describe Licensee do
|
|
12
14
|
end
|
13
15
|
|
14
16
|
it "detects a project's license" do
|
15
|
-
expect(
|
17
|
+
expect(described_class.license(project_path)).to eql(mit_license)
|
16
18
|
end
|
17
19
|
|
18
20
|
it "detect a file's license" do
|
19
|
-
expect(
|
21
|
+
expect(described_class.license(license_path)).to eql(mit_license)
|
20
22
|
end
|
21
23
|
|
22
24
|
describe '.project' do
|
23
|
-
subject {
|
25
|
+
subject { described_class.project(project_path) }
|
24
26
|
|
25
27
|
it 'inits a project' do
|
26
28
|
expect(subject).to be_a(Licensee::Projects::Project)
|
@@ -37,19 +39,20 @@ RSpec.describe Licensee do
|
|
37
39
|
|
38
40
|
context 'confidence threshold' do
|
39
41
|
it 'exposes the confidence threshold' do
|
40
|
-
expect(described_class.confidence_threshold).to
|
42
|
+
expect(described_class.confidence_threshold).to be(98)
|
41
43
|
end
|
42
44
|
|
43
45
|
it 'exposes the inverse of the confidence threshold' do
|
44
|
-
expect(described_class.inverse_confidence_threshold).to
|
46
|
+
expect(described_class.inverse_confidence_threshold).to be(0.02)
|
45
47
|
end
|
46
48
|
|
47
49
|
context 'user overridden' do
|
48
|
-
before {
|
49
|
-
|
50
|
+
before { described_class.confidence_threshold = 50 }
|
51
|
+
|
52
|
+
after { described_class.confidence_threshold = nil }
|
50
53
|
|
51
54
|
it 'lets the user override the confidence threshold' do
|
52
|
-
expect(described_class.confidence_threshold).to
|
55
|
+
expect(described_class.confidence_threshold).to be(50)
|
53
56
|
end
|
54
57
|
end
|
55
58
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start
|
3
5
|
|
4
6
|
require 'licensee'
|
5
7
|
require 'open3'
|
@@ -27,6 +29,13 @@ def fixtures_base
|
|
27
29
|
File.expand_path 'spec/fixtures', project_root
|
28
30
|
end
|
29
31
|
|
32
|
+
def fixtures
|
33
|
+
@fixtures ||= begin
|
34
|
+
dirs = Dir["#{fixtures_base}/*"].select { |e| File.directory?(e) }
|
35
|
+
dirs.map { |path| File.basename(path) }.sort_by { |k, _v| k }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
30
39
|
def fixture_path(fixture)
|
31
40
|
File.expand_path fixture, fixtures_base
|
32
41
|
end
|
@@ -49,6 +58,10 @@ def fixture_root_contents_from_api(fixture)
|
|
49
58
|
end.to_json
|
50
59
|
end
|
51
60
|
|
61
|
+
def fixture_licenses
|
62
|
+
@fixture_licenses ||= YAML.load_file(fixture_path('fixtures.yml'))
|
63
|
+
end
|
64
|
+
|
52
65
|
def field_values
|
53
66
|
{
|
54
67
|
fullname: 'Ben Balter',
|
@@ -90,7 +103,7 @@ def git_init(path)
|
|
90
103
|
end
|
91
104
|
|
92
105
|
def format_percent(float)
|
93
|
-
"#{format('
|
106
|
+
"#{format('%<float>.2f', float: float)}%"
|
94
107
|
end
|
95
108
|
|
96
109
|
def meta_fields
|
@@ -106,17 +119,19 @@ end
|
|
106
119
|
RSpec::Matchers.define :be_detected_as do |expected|
|
107
120
|
match do |actual|
|
108
121
|
@expected_as_array = [expected.content_normalized(wrap: 80)]
|
109
|
-
license_file = Licensee::ProjectFiles::LicenseFile.new(actual, 'LICENSE')
|
110
|
-
@actual = license_file.content_normalized(wrap: 80)
|
111
|
-
return false unless license_file.license
|
112
|
-
|
122
|
+
@license_file = Licensee::ProjectFiles::LicenseFile.new(actual, 'LICENSE')
|
123
|
+
@actual = @license_file.content_normalized(wrap: 80)
|
124
|
+
return false unless @license_file.license
|
125
|
+
|
126
|
+
values_match? expected, @license_file.license
|
113
127
|
end
|
114
128
|
|
115
129
|
failure_message do |actual|
|
116
130
|
license_file = Licensee::ProjectFiles::LicenseFile.new(actual, 'LICENSE')
|
117
131
|
license_name = expected.meta['spdx-id'] || expected.key
|
118
132
|
similarity = expected.similarity(license_file)
|
119
|
-
|
133
|
+
content = @license_file.content
|
134
|
+
msg = +"Expected '#{content}' to match the #{license_name} license"
|
120
135
|
msg << " (#{format_percent(similarity)} similarity"
|
121
136
|
msg << "using the #{license_file.matcher} matcher)"
|
122
137
|
end
|
@@ -126,9 +141,13 @@ RSpec::Matchers.define :be_detected_as do |expected|
|
|
126
141
|
license_name = expected.meta['spdx-id'] || expected.key
|
127
142
|
similarity = expected.similarity(license_file)
|
128
143
|
|
129
|
-
msg = "Expected the content to *not* match the #{license_name} license"
|
144
|
+
msg = +"Expected the content to *not* match the #{license_name} license"
|
130
145
|
msg << " (#{format_percent(similarity)} similarity)"
|
131
146
|
end
|
132
147
|
|
133
148
|
diffable
|
134
149
|
end
|
150
|
+
|
151
|
+
def license_hashes
|
152
|
+
@license_hashes ||= JSON.parse(fixture_contents('license-hashes.json'))
|
153
|
+
end
|