licensee 9.10.1 → 9.13.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.md +1 -1
  3. data/bin/licensee +5 -4
  4. data/lib/licensee.rb +7 -5
  5. data/lib/licensee/commands/detect.rb +7 -5
  6. data/lib/licensee/commands/diff.rb +7 -8
  7. data/lib/licensee/commands/license_path.rb +2 -0
  8. data/lib/licensee/commands/version.rb +2 -0
  9. data/lib/licensee/content_helper.rb +230 -85
  10. data/lib/licensee/hash_helper.rb +7 -5
  11. data/lib/licensee/license.rb +21 -22
  12. data/lib/licensee/license_field.rb +3 -1
  13. data/lib/licensee/license_meta.rb +2 -0
  14. data/lib/licensee/license_rules.rb +2 -0
  15. data/lib/licensee/matchers.rb +2 -0
  16. data/lib/licensee/matchers/cabal.rb +16 -2
  17. data/lib/licensee/matchers/cargo.rb +3 -1
  18. data/lib/licensee/matchers/copyright.rb +6 -4
  19. data/lib/licensee/matchers/cran.rb +5 -3
  20. data/lib/licensee/matchers/dice.rb +6 -4
  21. data/lib/licensee/matchers/dist_zilla.rb +3 -1
  22. data/lib/licensee/matchers/exact.rb +2 -0
  23. data/lib/licensee/matchers/gemspec.rb +7 -5
  24. data/lib/licensee/matchers/matcher.rb +3 -1
  25. data/lib/licensee/matchers/npm_bower.rb +3 -1
  26. data/lib/licensee/matchers/package.rb +2 -0
  27. data/lib/licensee/matchers/reference.rb +3 -1
  28. data/lib/licensee/matchers/spdx.rb +3 -1
  29. data/lib/licensee/project_files.rb +2 -0
  30. data/lib/licensee/project_files/license_file.rb +12 -10
  31. data/lib/licensee/project_files/package_manager_file.rb +2 -0
  32. data/lib/licensee/project_files/project_file.rb +12 -5
  33. data/lib/licensee/project_files/readme_file.rb +5 -3
  34. data/lib/licensee/projects.rb +2 -0
  35. data/lib/licensee/projects/fs_project.rb +9 -2
  36. data/lib/licensee/projects/git_project.rb +19 -11
  37. data/lib/licensee/projects/github_project.rb +3 -1
  38. data/lib/licensee/projects/project.rb +7 -5
  39. data/lib/licensee/rule.rb +2 -0
  40. data/lib/licensee/version.rb +3 -1
  41. data/licensee.gemspec +45 -0
  42. data/spec/bin_spec.rb +3 -1
  43. data/spec/fixture_spec.rb +46 -0
  44. data/spec/fixtures/bsd-3-noendorseslash/LICENSE +30 -0
  45. data/spec/fixtures/cc0-cal2013/LICENSE +116 -0
  46. data/spec/fixtures/cc0-cc/LICENSE +121 -0
  47. data/spec/fixtures/detect.json +10 -8
  48. data/spec/fixtures/fixtures.yml +134 -0
  49. data/spec/fixtures/html/license.html +262 -0
  50. data/spec/fixtures/license-hashes.json +41 -0
  51. data/spec/fixtures/mit-optional/LICENSE.txt +21 -0
  52. data/spec/fixtures/multiple-arrs/LICENSE +30 -0
  53. data/spec/fixtures/readme-invalid-encoding/README.md +24 -0
  54. data/spec/fixtures/unlicense-noinfo/LICENSE +22 -0
  55. data/spec/integration_spec.rb +68 -2
  56. data/spec/licensee/commands/detect_spec.rb +11 -7
  57. data/spec/licensee/commands/license_path_spec.rb +3 -1
  58. data/spec/licensee/commands/version_spec.rb +3 -1
  59. data/spec/licensee/content_helper_spec.rb +185 -67
  60. data/spec/licensee/hash_helper_spec.rb +3 -1
  61. data/spec/licensee/license_field_spec.rb +5 -3
  62. data/spec/licensee/license_meta_spec.rb +16 -12
  63. data/spec/licensee/license_rules_spec.rb +6 -2
  64. data/spec/licensee/license_spec.rb +37 -35
  65. data/spec/licensee/matchers/cabal_matcher_spec.rb +97 -2
  66. data/spec/licensee/matchers/cargo_matcher_spec.rb +5 -2
  67. data/spec/licensee/matchers/copyright_matcher_spec.rb +7 -5
  68. data/spec/licensee/matchers/cran_matcher_spec.rb +5 -2
  69. data/spec/licensee/matchers/dice_matcher_spec.rb +15 -12
  70. data/spec/licensee/matchers/dist_zilla_matcher_spec.rb +5 -2
  71. data/spec/licensee/matchers/exact_matcher_spec.rb +5 -2
  72. data/spec/licensee/matchers/gemspec_matcher_spec.rb +5 -2
  73. data/spec/licensee/matchers/matcher_spec.rb +6 -2
  74. data/spec/licensee/matchers/npm_bower_matcher_spec.rb +5 -3
  75. data/spec/licensee/matchers/package_matcher_spec.rb +6 -2
  76. data/spec/licensee/matchers/reference_matcher_spec.rb +4 -2
  77. data/spec/licensee/matchers/spdx_matcher_spec.rb +5 -2
  78. data/spec/licensee/project_files/license_file_spec.rb +20 -18
  79. data/spec/licensee/project_files/package_info_spec.rb +5 -1
  80. data/spec/licensee/project_files/project_file_spec.rb +8 -2
  81. data/spec/licensee/project_files/readme_file_spec.rb +4 -1
  82. data/spec/licensee/project_spec.rb +24 -17
  83. data/spec/licensee/projects/git_project_spec.rb +23 -0
  84. data/spec/licensee/projects/github_project_spec.rb +8 -5
  85. data/spec/licensee/rule_spec.rb +6 -3
  86. data/spec/licensee_spec.rb +12 -9
  87. data/spec/spec_helper.rb +27 -9
  88. data/spec/vendored_license_spec.rb +29 -10
  89. data/vendor/choosealicense.com/_data/meta.yml +0 -4
  90. data/vendor/choosealicense.com/_data/rules.yml +3 -0
  91. data/vendor/choosealicense.com/_licenses/0bsd.txt +39 -0
  92. data/vendor/choosealicense.com/_licenses/afl-3.0.txt +7 -6
  93. data/vendor/choosealicense.com/_licenses/agpl-3.0.txt +0 -1
  94. data/vendor/choosealicense.com/_licenses/apache-2.0.txt +1 -2
  95. data/vendor/choosealicense.com/_licenses/artistic-2.0.txt +1 -2
  96. data/vendor/choosealicense.com/_licenses/bsd-2-clause.txt +8 -6
  97. data/vendor/choosealicense.com/_licenses/bsd-3-clause-clear.txt +2 -2
  98. data/vendor/choosealicense.com/_licenses/bsd-3-clause.txt +12 -10
  99. data/vendor/choosealicense.com/_licenses/bsd-4-clause.txt +61 -0
  100. data/vendor/choosealicense.com/_licenses/bsl-1.0.txt +5 -2
  101. data/vendor/choosealicense.com/_licenses/cc-by-4.0.txt +16 -14
  102. data/vendor/choosealicense.com/_licenses/cc-by-sa-4.0.txt +16 -14
  103. data/vendor/choosealicense.com/_licenses/cc0-1.0.txt +113 -105
  104. data/vendor/choosealicense.com/_licenses/cecill-2.1.txt +579 -0
  105. data/vendor/choosealicense.com/_licenses/ecl-2.0.txt +1 -2
  106. data/vendor/choosealicense.com/_licenses/epl-1.0.txt +1 -2
  107. data/vendor/choosealicense.com/_licenses/epl-2.0.txt +3 -4
  108. data/vendor/choosealicense.com/_licenses/eupl-1.1.txt +0 -1
  109. data/vendor/choosealicense.com/_licenses/eupl-1.2.txt +0 -1
  110. data/vendor/choosealicense.com/_licenses/gpl-2.0.txt +0 -1
  111. data/vendor/choosealicense.com/_licenses/gpl-3.0.txt +1 -2
  112. data/vendor/choosealicense.com/_licenses/isc.txt +2 -3
  113. data/vendor/choosealicense.com/_licenses/lgpl-2.1.txt +0 -1
  114. data/vendor/choosealicense.com/_licenses/lgpl-3.0.txt +1 -3
  115. data/vendor/choosealicense.com/_licenses/lppl-1.3c.txt +1 -2
  116. data/vendor/choosealicense.com/_licenses/mit.txt +1 -2
  117. data/vendor/choosealicense.com/_licenses/mpl-2.0.txt +0 -1
  118. data/vendor/choosealicense.com/_licenses/ms-pl.txt +0 -1
  119. data/vendor/choosealicense.com/_licenses/ms-rl.txt +0 -1
  120. data/vendor/choosealicense.com/_licenses/ncsa.txt +21 -22
  121. data/vendor/choosealicense.com/_licenses/odbl-1.0.txt +573 -0
  122. data/vendor/choosealicense.com/_licenses/ofl-1.1.txt +4 -2
  123. data/vendor/choosealicense.com/_licenses/osl-3.0.txt +1 -2
  124. data/vendor/choosealicense.com/_licenses/postgresql.txt +4 -5
  125. data/vendor/choosealicense.com/_licenses/unlicense.txt +1 -2
  126. data/vendor/choosealicense.com/_licenses/upl-1.0.txt +4 -5
  127. data/vendor/choosealicense.com/_licenses/vim.txt +111 -0
  128. data/vendor/choosealicense.com/_licenses/wtfpl.txt +0 -1
  129. data/vendor/choosealicense.com/_licenses/zlib.txt +4 -2
  130. metadata +79 -28
@@ -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 eql(100)
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 eql(2)
105
+ expect(files.count).to be(2)
100
106
  license = files.find { |f| f[:name] == 'LICENSE.txt' }
101
- expect(license).to_not be_nil
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 eql(1)
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 eql(0)
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 eql(2)
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 eql(2)
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 eql(2)
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).to_not be_nil
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).to_not be_nil
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 eql(2)
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 eql(2)
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 eql(2)
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 'should set @repo' do
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 'should set @repo, stripping the trailing extension' do
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 'should raise an ArgumentError' do
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 'should raise an ArgumentError' do
38
+ it 'raises an ArgumentError' do
36
39
  expect { instance }.to raise_error(ArgumentError)
37
40
  end
38
41
  end
@@ -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 eql(true)
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 eql(16)
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')
@@ -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) { 36 }
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(Licensee.license(project_path)).to eql(mit_license)
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(Licensee.license(license_path)).to eql(mit_license)
21
+ expect(described_class.license(license_path)).to eql(mit_license)
20
22
  end
21
23
 
22
24
  describe '.project' do
23
- subject { Licensee.project(project_path) }
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 eql(98)
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 eql(0.02)
46
+ expect(described_class.inverse_confidence_threshold).to be(0.02)
45
47
  end
46
48
 
47
49
  context 'user overridden' do
48
- before { Licensee.confidence_threshold = 50 }
49
- after { Licensee.confidence_threshold = nil }
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 eql(50)
55
+ expect(described_class.confidence_threshold).to be(50)
53
56
  end
54
57
  end
55
58
  end
@@ -1,5 +1,7 @@
1
- require 'coveralls'
2
- Coveralls.wear!
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('%.2f', float)}%"
106
+ "#{format('%<float>.2f', float: float)}%"
94
107
  end
95
108
 
96
109
  def meta_fields
@@ -106,18 +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
122
+ @license_file = Licensee::ProjectFiles::LicenseFile.new(actual, 'LICENSE')
123
+ @actual = @license_file.content_normalized(wrap: 80)
124
+ return false unless @license_file.license
112
125
 
113
- values_match? expected, license_file.license
126
+ values_match? expected, @license_file.license
114
127
  end
115
128
 
116
129
  failure_message do |actual|
117
130
  license_file = Licensee::ProjectFiles::LicenseFile.new(actual, 'LICENSE')
118
131
  license_name = expected.meta['spdx-id'] || expected.key
119
132
  similarity = expected.similarity(license_file)
120
- msg = "Expected the content to match the #{license_name} license"
133
+ content = @license_file.content
134
+ msg = +"Expected '#{content}' to match the #{license_name} license"
121
135
  msg << " (#{format_percent(similarity)} similarity"
122
136
  msg << "using the #{license_file.matcher} matcher)"
123
137
  end
@@ -127,9 +141,13 @@ RSpec::Matchers.define :be_detected_as do |expected|
127
141
  license_name = expected.meta['spdx-id'] || expected.key
128
142
  similarity = expected.similarity(license_file)
129
143
 
130
- msg = "Expected the content to *not* match the #{license_name} license"
144
+ msg = +"Expected the content to *not* match the #{license_name} license"
131
145
  msg << " (#{format_percent(similarity)} similarity)"
132
146
  end
133
147
 
134
148
  diffable
135
149
  end
150
+
151
+ def license_hashes
152
+ @license_hashes ||= JSON.parse(fixture_contents('license-hashes.json'))
153
+ end