licensee 9.10.1 → 9.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/lib/licensee/commands/diff.rb +2 -7
  3. data/lib/licensee/content_helper.rb +169 -78
  4. data/lib/licensee/license.rb +5 -4
  5. data/lib/licensee/license_field.rb +1 -1
  6. data/lib/licensee/matchers/cabal.rb +1 -1
  7. data/lib/licensee/matchers/cargo.rb +1 -1
  8. data/lib/licensee/matchers/copyright.rb +2 -2
  9. data/lib/licensee/matchers/cran.rb +3 -3
  10. data/lib/licensee/matchers/dist_zilla.rb +1 -1
  11. data/lib/licensee/matchers/gemspec.rb +5 -5
  12. data/lib/licensee/matchers/matcher.rb +1 -1
  13. data/lib/licensee/matchers/npm_bower.rb +1 -1
  14. data/lib/licensee/matchers/reference.rb +1 -1
  15. data/lib/licensee/matchers/spdx.rb +1 -1
  16. data/lib/licensee/project_files/license_file.rb +7 -7
  17. data/lib/licensee/project_files/readme_file.rb +3 -3
  18. data/lib/licensee/projects/github_project.rb +1 -1
  19. data/lib/licensee/version.rb +1 -1
  20. data/spec/fixtures/detect.json +2 -2
  21. data/spec/fixtures/license-hashes.json +36 -0
  22. data/spec/licensee/commands/detect_spec.rb +1 -1
  23. data/spec/licensee/content_helper_spec.rb +131 -32
  24. data/spec/licensee/license_spec.rb +1 -1
  25. data/spec/licensee/matchers/dice_matcher_spec.rb +2 -2
  26. data/spec/licensee/project_files/license_file_spec.rb +1 -1
  27. data/spec/spec_helper.rb +10 -5
  28. data/spec/vendored_license_spec.rb +19 -2
  29. data/vendor/choosealicense.com/_data/meta.yml +0 -4
  30. data/vendor/choosealicense.com/_licenses/afl-3.0.txt +0 -1
  31. data/vendor/choosealicense.com/_licenses/agpl-3.0.txt +0 -1
  32. data/vendor/choosealicense.com/_licenses/apache-2.0.txt +0 -1
  33. data/vendor/choosealicense.com/_licenses/artistic-2.0.txt +0 -1
  34. data/vendor/choosealicense.com/_licenses/bsd-2-clause.txt +8 -6
  35. data/vendor/choosealicense.com/_licenses/bsd-3-clause-clear.txt +0 -1
  36. data/vendor/choosealicense.com/_licenses/bsd-3-clause.txt +11 -9
  37. data/vendor/choosealicense.com/_licenses/bsl-1.0.txt +0 -1
  38. data/vendor/choosealicense.com/_licenses/cc-by-4.0.txt +0 -1
  39. data/vendor/choosealicense.com/_licenses/cc-by-sa-4.0.txt +0 -1
  40. data/vendor/choosealicense.com/_licenses/cc0-1.0.txt +0 -1
  41. data/vendor/choosealicense.com/_licenses/ecl-2.0.txt +0 -1
  42. data/vendor/choosealicense.com/_licenses/epl-1.0.txt +0 -1
  43. data/vendor/choosealicense.com/_licenses/epl-2.0.txt +0 -1
  44. data/vendor/choosealicense.com/_licenses/eupl-1.1.txt +0 -1
  45. data/vendor/choosealicense.com/_licenses/eupl-1.2.txt +0 -1
  46. data/vendor/choosealicense.com/_licenses/gpl-2.0.txt +0 -1
  47. data/vendor/choosealicense.com/_licenses/gpl-3.0.txt +1 -2
  48. data/vendor/choosealicense.com/_licenses/isc.txt +0 -1
  49. data/vendor/choosealicense.com/_licenses/lgpl-2.1.txt +0 -1
  50. data/vendor/choosealicense.com/_licenses/lgpl-3.0.txt +1 -2
  51. data/vendor/choosealicense.com/_licenses/lppl-1.3c.txt +0 -1
  52. data/vendor/choosealicense.com/_licenses/mit.txt +0 -1
  53. data/vendor/choosealicense.com/_licenses/mpl-2.0.txt +0 -1
  54. data/vendor/choosealicense.com/_licenses/ms-pl.txt +0 -1
  55. data/vendor/choosealicense.com/_licenses/ms-rl.txt +0 -1
  56. data/vendor/choosealicense.com/_licenses/ncsa.txt +0 -1
  57. data/vendor/choosealicense.com/_licenses/ofl-1.1.txt +0 -1
  58. data/vendor/choosealicense.com/_licenses/osl-3.0.txt +0 -1
  59. data/vendor/choosealicense.com/_licenses/postgresql.txt +2 -3
  60. data/vendor/choosealicense.com/_licenses/unlicense.txt +0 -1
  61. data/vendor/choosealicense.com/_licenses/upl-1.0.txt +0 -1
  62. data/vendor/choosealicense.com/_licenses/wtfpl.txt +0 -1
  63. data/vendor/choosealicense.com/_licenses/zlib.txt +0 -1
  64. metadata +4 -4
@@ -3,24 +3,24 @@ module Licensee
3
3
  class Gemspec < Licensee::Matchers::Package
4
4
  # a value is a string surrounded by any amount of whitespace
5
5
  # optionally ended with (non-captured) ".freeze"
6
- VALUE_REGEX = /\s*[\'\"]([a-z\-0-9\.]+)[\'\"](?:\.freeze)?\s*/i
6
+ VALUE_REGEX = /\s*[\'\"]([a-z\-0-9\.]+)[\'\"](?:\.freeze)?\s*/i.freeze
7
7
 
8
8
  # an array contains one or more values. all values, or array itself,
9
9
  # can be surrounded by any amount of whitespace. do not capture
10
10
  # non-value groups
11
- ARRAY_REGEX = /\s*\[#{VALUE_REGEX}(?:,#{VALUE_REGEX})*\]\s*/i
11
+ ARRAY_REGEX = /\s*\[#{VALUE_REGEX}(?:,#{VALUE_REGEX})*\]\s*/i.freeze
12
12
 
13
13
  DECLARATION_REGEX = /
14
14
  ^\s*[a-z0-9_]+\.([a-z0-9_]+)\s*\=#{VALUE_REGEX}$
15
- /ix
15
+ /ix.freeze
16
16
 
17
17
  LICENSE_REGEX = /
18
18
  ^\s*[a-z0-9_]+\.license\s*\=#{VALUE_REGEX}$
19
- /ix
19
+ /ix.freeze
20
20
 
21
21
  LICENSE_ARRAY_REGEX = /
22
22
  ^\s*[a-z0-9_]+\.licenses\s*\=#{ARRAY_REGEX}$
23
- /ix
23
+ /ix.freeze
24
24
 
25
25
  private
26
26
 
@@ -25,7 +25,7 @@ module Licensee
25
25
  private
26
26
 
27
27
  def potential_matches
28
- @potential_matches ||= Licensee.licenses(hidden: true)
28
+ @potential_matches ||= Licensee.licenses(hidden: true, psuedo: false)
29
29
  end
30
30
  end
31
31
  end
@@ -5,7 +5,7 @@ module Licensee
5
5
  # a lenient regex for speed and security. Moar parsing moar problems.
6
6
  LICENSE_REGEX = /
7
7
  \s*[\"\']license[\"\']\s*\:\s*[\'\"]([a-z\-0-9\.+ ()]+)[\'\"],?\s*
8
- /ix
8
+ /ix.freeze
9
9
 
10
10
  private
11
11
 
@@ -3,7 +3,7 @@ module Licensee
3
3
  # Matches README files that include a license by reference
4
4
  class Reference < Licensee::Matchers::Matcher
5
5
  def match
6
- License.all(hidden: true, psuedo: false).find do |license|
6
+ potential_matches.find do |license|
7
7
  title_or_source = [license.title_regex, license.source_regex].compact
8
8
  /\b#{Regexp.union(title_or_source)}\b/ =~ file.content
9
9
  end
@@ -3,7 +3,7 @@ module Licensee
3
3
  class Spdx < Licensee::Matchers::Package
4
4
  # While we could parse the LICENSE.spdx file, prefer
5
5
  # a lenient regex for speed and security. Moar parsing moar problems.
6
- LICENSE_REGEX = /PackageLicenseDeclared:\s*([a-z\-0-9\. +()]+)\s*/i
6
+ LICENSE_REGEX = /PackageLicenseDeclared:\s*([a-z\-0-9\. +()]+)\s*/i.freeze
7
7
 
8
8
  private
9
9
 
@@ -5,22 +5,22 @@ module Licensee
5
5
 
6
6
  # List of extensions to give preference to
7
7
  PREFERRED_EXT = %w[md markdown txt].freeze
8
- PREFERRED_EXT_REGEX = /\.#{Regexp.union(PREFERRED_EXT)}\z/
8
+ PREFERRED_EXT_REGEX = /\.#{Regexp.union(PREFERRED_EXT)}\z/.freeze
9
9
 
10
10
  # Regex to match any extension except .spdx or .header
11
- OTHER_EXT_REGEX = %r{\.(?!spdx|header|gemspec)[^./]+\z}i
11
+ OTHER_EXT_REGEX = %r{\.(?!spdx|header|gemspec)[^./]+\z}i.freeze
12
12
 
13
13
  # Regex to match, LICENSE, LICENCE, unlicense, etc.
14
- LICENSE_REGEX = /(un)?licen[sc]e/i
14
+ LICENSE_REGEX = /(un)?licen[sc]e/i.freeze
15
15
 
16
16
  # Regex to match COPYING, COPYRIGHT, etc.
17
- COPYING_REGEX = /copy(ing|right)/i
17
+ COPYING_REGEX = /copy(ing|right)/i.freeze
18
18
 
19
19
  # Regex to match OFL.
20
- OFL_REGEX = /ofl/i
20
+ OFL_REGEX = /ofl/i.freeze
21
21
 
22
22
  # BSD + PATENTS patent file
23
- PATENTS_REGEX = /patents/i
23
+ PATENTS_REGEX = /patents/i.freeze
24
24
 
25
25
  # Hash of Regex => score with which to score potential license files
26
26
  FILENAME_REGEXES = {
@@ -46,7 +46,7 @@ module Licensee
46
46
  # detected as CC-BY or CC-BY-SA which are 98%+ similar
47
47
  CC_FALSE_POSITIVE_REGEX = /
48
48
  ^(creative\ commons\ )?Attribution-(NonCommercial|NoDerivatives)
49
- /xi
49
+ /xi.freeze
50
50
 
51
51
  def possible_matchers
52
52
  [Matchers::Copyright, Matchers::Exact, Matchers::Dice]
@@ -7,8 +7,8 @@ module Licensee
7
7
  /\AREADME\.(#{Regexp.union(EXTENSIONS).source})\z/i => 0.9
8
8
  }.freeze
9
9
 
10
- TITLE_REGEX = /licen[sc]e:?/i
11
- UNDERLINE_REGEX = /\n[-=]+/m
10
+ TITLE_REGEX = /licen[sc]e:?/i.freeze
11
+ UNDERLINE_REGEX = /\n[-=]+/m.freeze
12
12
  CONTENT_REGEX = /^
13
13
  (?: # Header lookbehind
14
14
  [\#=]+\s#{TITLE_REGEX}\s*[\#=]* # Start of hashes or rdoc header
@@ -25,7 +25,7 @@ module Licensee
25
25
  |
26
26
  \z # End of file
27
27
  )
28
- /mix
28
+ /mix.freeze
29
29
 
30
30
  def possible_matchers
31
31
  super.push(Matchers::Reference)
@@ -13,7 +13,7 @@ module Licensee
13
13
  # If there's any trailing data (e.g. `.git`) this pattern will ignore it:
14
14
  # we're going to use the API rather than clone the repo.
15
15
  GITHUB_REPO_PATTERN =
16
- %r{https://github.com/([^\/]+\/([^\/]+(?=\.git)|[^\/]+)).*}
16
+ %r{https://github.com/([^\/]+\/([^\/]+(?=\.git)|[^\/]+)).*}.freeze
17
17
 
18
18
  class RepoNotFound < StandardError; end
19
19
 
@@ -1,3 +1,3 @@
1
1
  module Licensee
2
- VERSION = '9.10.1'.freeze
2
+ VERSION = '9.11.0'.freeze
3
3
  end
@@ -88,8 +88,8 @@
88
88
  {
89
89
  "filename": "LICENSE.md",
90
90
  "content": "MIT License\n\nCopyright (c) 2014-2017 Ben Balter\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n",
91
- "content_hash": "46cdc03462b9af57968df67b450cc4372ac41f53",
92
- "content_normalized": "permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files the \"software\" , to deal in the software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the software, and to permit persons to whom the software is furnished to do so, subject to the following conditions: the above copyright notice and this permission notice shall be included in all copies or substantial portions of the software. the software is provided \"as is\", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. in no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.",
91
+ "content_hash": "d64f3bb4282a97b37454b5bb96a8a264a3363dc3",
92
+ "content_normalized": "permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"software\"), to deal in the software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the software, and to permit persons to whom the software is furnished to do so, subject to the following conditions: the above copyright notice and this permission notice shall be included in all copies or substantial portions of the software. the software is provided \"as is\", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. in no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.",
93
93
  "matcher": {
94
94
  "name": "exact",
95
95
  "confidence": 100
@@ -0,0 +1,36 @@
1
+ {
2
+ "upl-1.0": "093b8b048dec7bc685c9ee6a5afffa4a1d148c02",
3
+ "ofl-1.1": "1fb0563aa1250e18a6948afde286edc95761f461",
4
+ "lgpl-3.0": "bdb3c042bd84f914eacfbe4977c5e58352745809",
5
+ "agpl-3.0": "d445855a1f169b12cbee97d320c2e3522d053016",
6
+ "gpl-2.0": "3becd209e8ed8039656c1debe01dd17b9a79208f",
7
+ "cc-by-4.0": "899872bc08626e6cf154dcf9e08ff0de82c9b3db",
8
+ "ms-rl": "402bf344e506a8d10175c1e516b396c060ffd823",
9
+ "wtfpl": "f8544c074f203d86cdcb24082fedfb2cf2fe411a",
10
+ "osl-3.0": "ab241ef932d3ac038e8ed62c860e9eba051ae7a0",
11
+ "bsl-1.0": "ca8f916d00c234719956e932061f192abb2d5bf9",
12
+ "lgpl-2.1": "91e779a787786276618f58d6e396a5e64a981805",
13
+ "mpl-2.0": "b4db668fa7573bfdcae74eb51eafc961034f0a61",
14
+ "isc": "d168f98624be864548b2bbf4f198fdbf702d6743",
15
+ "cc0-1.0": "ec5027313ed11fea202060f6958ac25b086d6dcb",
16
+ "bsd-3-clause-clear": "251d4599b622d2a87b2c4bb21dfacd438c048466",
17
+ "gpl-3.0": "b22f1b1f953a38a8a11686587b98831858d6468b",
18
+ "unlicense": "86c75861af1b9b9e0573b190dcb2c2cdbbee7037",
19
+ "bsd-2-clause": "59f0099ff04225daf184db3fe55e478256133b1a",
20
+ "artistic-2.0": "a2ff6e7fb76e51bda9a5350c759a824f206049d1",
21
+ "zlib": "576139d1f785b8f3539099b9702fc68005ee2213",
22
+ "lppl-1.3c": "60961652297042d28bb689c17fac47eca7348d16",
23
+ "epl-2.0": "b57663bc9c3f41446a8cd3f0050149221a58fe66",
24
+ "mit": "d64f3bb4282a97b37454b5bb96a8a264a3363dc3",
25
+ "postgresql": "87550a6bb3409db00d8552b2ac07d373ea56a024",
26
+ "afl-3.0": "4702ff33018a2874510beeef5916d6e8629cdc32",
27
+ "ncsa": "04c052b69de47ab0641068657a14632cdf9aa48d",
28
+ "cc-by-sa-4.0": "d11590d97684231d5358252e0cc97373d62ec4f1",
29
+ "bsd-3-clause": "fa22c672927af9c7334874561198799cbf4bdf31",
30
+ "epl-1.0": "e306464a81ab0e6688653c6509245b451637172c",
31
+ "ms-pl": "c900293d66a241e54f7817367a8f32f7f94e12ff",
32
+ "ecl-2.0": "58e7f645bfa1c5ccca7e2c37e626b3487e4d9d1b",
33
+ "eupl-1.2": "f122f96b9f1a56e4806a89cb1cc6ca2bb956f3e5",
34
+ "apache-2.0": "ab3901051663cb8ee5dea9ebdff406ad136910e3",
35
+ "eupl-1.1": "873e30dbc5f75d076d7aecb6ceb84fb6bb765452"
36
+ }
@@ -10,7 +10,7 @@ RSpec.describe 'detect command' do
10
10
  let(:stdout) { output[0] }
11
11
  let(:stderr) { output[1] }
12
12
  let(:status) { output[2] }
13
- let(:hash) { '46cdc03462b9af57968df67b450cc4372ac41f53' }
13
+ let(:hash) { license_hashes['mit'] }
14
14
  let(:expected) do
15
15
  {
16
16
  'License' => 'MIT',
@@ -29,6 +29,7 @@ RSpec.describe Licensee::ContentHelper do
29
29
  end
30
30
  subject { ContentHelperTestHelper.new(content) }
31
31
  let(:mit) { Licensee::License.find('mit') }
32
+ let(:normalized_content) { subject.content_normalized }
32
33
 
33
34
  it 'creates the wordset' do
34
35
  wordset = Set.new(
@@ -53,7 +54,7 @@ RSpec.describe Licensee::ContentHelper do
53
54
  end
54
55
 
55
56
  it 'knows the length delta' do
56
- expect(subject.length_delta(mit)).to eql(884)
57
+ expect(subject.length_delta(mit)).to eql(885)
57
58
  expect(subject.length_delta(subject)).to eql(0)
58
59
  end
59
60
 
@@ -78,9 +79,42 @@ RSpec.describe Licensee::ContentHelper do
78
79
  expect(percent).to eql('12.35%')
79
80
  end
80
81
 
81
- context 'normalizing' do
82
- let(:normalized_content) { subject.content_normalized }
82
+ context '#strip' do
83
+ {
84
+ version: "The MIT License\nVersion 1.0\nfoo",
85
+ hrs: "The MIT License\n=====\n-----\n*******\nfoo",
86
+ markdown_headings: "# The MIT License\n\nfoo",
87
+ whitespace: "The MIT License\n\n foo ",
88
+ all_rights_reserved: "Copyright 2016 Ben Balter\n\nfoo",
89
+ urls: "https://example.com\nfoo",
90
+ developed_by: "Developed By: Ben Balter\n\nFoo",
91
+ borders: '* Foo *',
92
+ title: "The MIT License\nfoo",
93
+ copyright: "The MIT License\nCopyright 2018 Ben Balter\nFoo",
94
+ end_of_terms: "Foo\nend of terms and conditions\nbar",
95
+ block_markup: '> Foo',
96
+ link_markup: '[Foo](http://exmaple.com)',
97
+ comment_markup: "/*\n* The MIT License\n* Foo\n*/"
98
+ }.each do |field, fixture|
99
+ context "#strip_#{field}" do
100
+ let(:content) { fixture }
101
+
102
+ it "strips #{field}" do
103
+ expect(normalized_content).to eql('foo')
104
+ end
105
+ end
106
+ end
83
107
 
108
+ context 'span markup' do
109
+ let(:content) { '_foo_ *foo* **foo** ~foo~' }
110
+
111
+ it 'strips span markup' do
112
+ expect(normalized_content).to eql('foo foo foo foo')
113
+ end
114
+ end
115
+ end
116
+
117
+ context 'integration fixture' do
84
118
  it 'strips copyright' do
85
119
  expect(normalized_content).to_not match 'Copyright'
86
120
  expect(normalized_content).to_not match 'Ben Balter'
@@ -98,22 +132,6 @@ RSpec.describe Licensee::ContentHelper do
98
132
  expect(normalized_content).to_not include '* *'
99
133
  end
100
134
 
101
- it 'strips formatting from the MPL' do
102
- license = Licensee::License.find('mpl-2.0')
103
- expect(license.content_normalized).to_not include('* *')
104
- end
105
-
106
- it 'normalizes http: to https:' do
107
- license = Licensee::License.find('mpl-2.0')
108
- expect(license.content).to include('http:')
109
- expect(license.content_normalized).to_not include('http:')
110
- end
111
-
112
- it 'wraps' do
113
- lines = mit.content_normalized(wrap: 40).split("\n")
114
- expect(lines.first.length).to be <= 40
115
- end
116
-
117
135
  it 'squeezes whitespace' do
118
136
  expect(normalized_content).to_not match ' '
119
137
  end
@@ -148,15 +166,93 @@ RSpec.describe Licensee::ContentHelper do
148
166
  expect(normalized_content).to match('"software"')
149
167
  end
150
168
 
169
+ it 'strips the title' do
170
+ expect(normalized_content).to_not match('MIT')
171
+ end
172
+
173
+ it 'normalize the content' do
174
+ expected = 'the made up license. this license provided "as is". '
175
+ expected << "please respect the contributors' wishes when implementing "
176
+ expected << "the license's \"software\"."
177
+ expect(normalized_content).to eql(expected)
178
+ end
179
+ end
180
+
181
+ context 'normalizing' do
182
+ context 'https' do
183
+ let(:content) { 'http://example.com' }
184
+
185
+ it 'normalized URL protocals' do
186
+ expect(subject.content_normalized).to eql('https://example.com')
187
+ end
188
+ end
189
+
190
+ context 'ampersands' do
191
+ let(:content) { 'Foo & Bar' }
192
+
193
+ it 'normalized ampersands' do
194
+ expect(subject.content_normalized).to eql('foo and bar')
195
+ end
196
+ end
197
+
198
+ context 'lists' do
199
+ let(:content) { "1. Foo\n * Bar" }
200
+
201
+ it 'normalizes lists' do
202
+ expect(subject.content_normalized).to eql('- foo - bar')
203
+ end
204
+ end
205
+
206
+ context 'dashes' do
207
+ let(:content) { 'Foo-Bar—–baz-buzz' }
208
+
209
+ it 'normalizes dashes' do
210
+ expect(subject.content_normalized).to eql('foo-bar-baz-buzz')
211
+ end
212
+ end
213
+
214
+ context 'quotes' do
215
+ let(:content) { "`a` 'b' \"c\" ‘d’ “e”" }
216
+
217
+ it 'normalizes quotes' do
218
+ expect(subject.content_normalized).to eql('"a" "b" "c" "d" "e"')
219
+ end
220
+ end
221
+
222
+ it 'strips formatting from the MPL' do
223
+ license = Licensee::License.find('mpl-2.0')
224
+ expect(license.content_normalized).to_not include('* *')
225
+ end
226
+
227
+ it 'normalizes http: to https:' do
228
+ license = Licensee::License.find('mpl-2.0')
229
+ expect(license.content).to include('http:')
230
+ expect(license.content_normalized).to_not include('http:')
231
+ end
232
+
233
+ it 'wraps' do
234
+ lines = mit.content_normalized(wrap: 40).split("\n")
235
+ expect(lines.first.length).to be <= 40
236
+ end
237
+
238
+ context 'spelling' do
239
+ let(:content) { 'licence' }
240
+
241
+ it 'normalizes' do
242
+ expect(subject.content_normalized).to eql('license')
243
+ end
244
+ end
245
+
151
246
  Licensee::License.all(hidden: true).each do |license|
152
247
  context license.name do
153
248
  let(:stripped_content) { subject.content_without_title_and_version }
154
249
 
155
250
  it 'strips the title' do
156
- regex = Licensee::ContentHelper::ALT_TITLE_REGEX[license.key]
251
+ skip "Doesn't strip ECL title" if license.key == 'ecl-2.0'
252
+ regex = Licensee::License::ALT_TITLE_REGEX[license.key]
157
253
  regex ||= /\A#{license.name_without_version}/i
158
- expect(license.content_normalized).to_not match(regex)
159
254
  expect(stripped_content).to_not match(regex)
255
+ expect(license.content_normalized).to_not match(regex)
160
256
  end
161
257
 
162
258
  it 'strips the version' do
@@ -181,17 +277,6 @@ RSpec.describe Licensee::ContentHelper do
181
277
  end
182
278
  end
183
279
 
184
- it 'strips the title' do
185
- expect(normalized_content).to_not match('MIT')
186
- end
187
-
188
- it 'normalize the content' do
189
- expected = 'the made up license. this license provided "as is". '
190
- expected << "please respect the contributors' wishes when implementing "
191
- expected << "the license's \"software\"."
192
- expect(normalized_content).to eql(expected)
193
- end
194
-
195
280
  context 'a title in parenthesis' do
196
281
  let(:content) { "(The MIT License)\n\nfoo" }
197
282
 
@@ -275,4 +360,18 @@ RSpec.describe Licensee::ContentHelper do
275
360
  end
276
361
  end
277
362
  end
363
+
364
+ context 'metaprogramming' do
365
+ it 'raises on invalid normalization' do
366
+ expect { subject.send(:normalize, :foo) }.to raise_error(ArgumentError)
367
+ end
368
+
369
+ it 'raises on invalid strip' do
370
+ expect { subject.send(:strip, :foo) }.to raise_error(ArgumentError)
371
+ end
372
+
373
+ it 'backwards compatibalizes regexes' do
374
+ expect(described_class::WHITESPACE_REGEX).to eql(/\s+/)
375
+ end
376
+ end
278
377
  end
@@ -14,7 +14,7 @@ RSpec.describe Licensee::License do
14
14
  let(:no_license) { described_class.find('no-license') }
15
15
  let(:gpl) { described_class.find('gpl-3.0') }
16
16
  let(:lgpl) { described_class.find('lgpl-3.0') }
17
- let(:content_hash) { '46cdc03462b9af57968df67b450cc4372ac41f53' }
17
+ let(:content_hash) { license_hashes['mit'] }
18
18
 
19
19
  let(:license_dir) do
20
20
  File.expand_path 'vendor/choosealicense.com/_licenses', project_root
@@ -22,12 +22,12 @@ RSpec.describe Licensee::Matchers::Dice do
22
22
 
23
23
  it 'sorts licenses by similarity' do
24
24
  expect(subject.matches_by_similarity[0]).to eql([gpl, 100.0])
25
- expect(subject.matches_by_similarity[1]).to eql([agpl, 95.76581285938317])
25
+ expect(subject.matches_by_similarity[1]).to eql([agpl, 95.67966280295047])
26
26
  end
27
27
 
28
28
  it 'returns a list of licenses above the confidence threshold' do
29
29
  expect(subject.matches_by_similarity[0]).to eql([gpl, 100.0])
30
- expect(subject.matches_by_similarity[1]).to eql([agpl, 95.76581285938317])
30
+ expect(subject.matches_by_similarity[1]).to eql([agpl, 95.67966280295047])
31
31
  end
32
32
 
33
33
  it 'returns the match confidence' do
@@ -3,7 +3,7 @@ RSpec.describe Licensee::ProjectFiles::LicenseFile do
3
3
  let(:gpl) { Licensee::License.find('gpl-3.0') }
4
4
  let(:mit) { Licensee::License.find('mit') }
5
5
  let(:content) { sub_copyright_info(mit) }
6
- let(:content_hash) { '46cdc03462b9af57968df67b450cc4372ac41f53' }
6
+ let(:content_hash) { license_hashes['mit'] }
7
7
 
8
8
  subject { described_class.new(content, filename) }
9
9