license_finder 1.2 → 2.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (220) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -1
  3. data/CHANGELOG.rdoc +27 -0
  4. data/CONTRIBUTING.md +38 -0
  5. data/README.md +139 -159
  6. data/Rakefile +17 -13
  7. data/features/features/cli_spec.rb +43 -0
  8. data/features/features/configure/add_dependencies_spec.rb +37 -0
  9. data/features/features/configure/approve_dependencies_spec.rb +30 -0
  10. data/features/features/configure/assign_licenses_spec.rb +20 -0
  11. data/features/features/configure/ignore_dependencies_spec.rb +35 -0
  12. data/features/features/configure/ignore_groups_spec.rb +31 -0
  13. data/features/features/configure/name_project_spec.rb +32 -0
  14. data/features/features/configure/whitelist_licenses_spec.rb +40 -0
  15. data/features/features/package_managers/bower_spec.rb +14 -0
  16. data/features/features/package_managers/cocoapods_spec.rb +14 -0
  17. data/features/features/package_managers/gradle_spec.rb +14 -0
  18. data/features/features/package_managers/maven_spec.rb +14 -0
  19. data/features/features/package_managers/npm_spec.rb +14 -0
  20. data/features/features/package_managers/pip_spec.rb +14 -0
  21. data/features/features/report/csv_spec.rb +17 -0
  22. data/features/features/report/html_spec.rb +50 -0
  23. data/{spec → features}/fixtures/Podfile +0 -0
  24. data/{spec → features}/fixtures/build.gradle +0 -0
  25. data/{spec → features}/fixtures/pom.xml +0 -0
  26. data/features/support/testing_dsl.rb +295 -0
  27. data/lib/license_finder.rb +16 -50
  28. data/lib/license_finder/cli.rb +13 -253
  29. data/lib/license_finder/cli/approvals.rb +26 -0
  30. data/lib/license_finder/cli/base.rb +20 -0
  31. data/lib/license_finder/cli/dependencies.rb +39 -0
  32. data/lib/license_finder/cli/ignored_dependencies.rb +30 -0
  33. data/lib/license_finder/cli/ignored_groups.rb +30 -0
  34. data/lib/license_finder/cli/licenses.rb +24 -0
  35. data/lib/license_finder/cli/main.rb +82 -0
  36. data/lib/license_finder/cli/makes_decisions.rb +48 -0
  37. data/lib/license_finder/cli/patched_thor.rb +34 -0
  38. data/lib/license_finder/cli/project_name.rb +31 -0
  39. data/lib/license_finder/cli/whitelist.rb +32 -0
  40. data/lib/license_finder/configuration.rb +14 -145
  41. data/lib/license_finder/decision_applier.rb +46 -0
  42. data/lib/license_finder/decisions.rb +174 -0
  43. data/lib/license_finder/license.rb +13 -32
  44. data/lib/license_finder/license/definitions.rb +15 -13
  45. data/lib/license_finder/license/template.rb +1 -1
  46. data/lib/{data/licenses → license_finder/license/templates}/Apache2.txt +0 -0
  47. data/lib/{data/licenses → license_finder/license/templates}/BSD.txt +0 -0
  48. data/lib/{data/licenses → license_finder/license/templates}/GPLv2.txt +0 -0
  49. data/lib/{data/licenses → license_finder/license/templates}/ISC.txt +0 -0
  50. data/lib/{data/licenses → license_finder/license/templates}/LGPL.txt +0 -0
  51. data/lib/{data/licenses → license_finder/license/templates}/MIT.txt +0 -0
  52. data/lib/{data/licenses → license_finder/license/templates}/NewBSD.txt +0 -0
  53. data/lib/{data/licenses → license_finder/license/templates}/Python.txt +0 -0
  54. data/lib/{data/licenses → license_finder/license/templates}/Ruby.txt +0 -0
  55. data/lib/{data/licenses → license_finder/license/templates}/SimplifiedBSD.txt +0 -0
  56. data/lib/license_finder/package.rb +77 -7
  57. data/lib/license_finder/package_manager.rb +43 -0
  58. data/lib/license_finder/package_managers/bower.rb +1 -1
  59. data/lib/license_finder/package_managers/bower_package.rb +23 -44
  60. data/lib/license_finder/package_managers/bundler.rb +4 -7
  61. data/lib/license_finder/package_managers/bundler_package.rb +14 -31
  62. data/lib/license_finder/package_managers/cocoa_pods.rb +1 -1
  63. data/lib/license_finder/package_managers/cocoa_pods_package.rb +2 -10
  64. data/lib/license_finder/package_managers/gradle.rb +6 -2
  65. data/lib/license_finder/package_managers/gradle_package.rb +6 -30
  66. data/lib/license_finder/package_managers/manual_package.rb +25 -0
  67. data/lib/license_finder/package_managers/maven_package.rb +8 -37
  68. data/lib/license_finder/package_managers/npm.rb +16 -4
  69. data/lib/license_finder/package_managers/npm_package.rb +12 -43
  70. data/lib/license_finder/package_managers/pip_package.rb +17 -37
  71. data/lib/license_finder/platform.rb +0 -16
  72. data/lib/license_finder/possible_license_file.rb +9 -14
  73. data/lib/license_finder/possible_license_files.rb +1 -5
  74. data/lib/license_finder/report.rb +26 -0
  75. data/lib/license_finder/reports/csv_report.rb +58 -0
  76. data/lib/license_finder/reports/erb_report.rb +61 -0
  77. data/lib/license_finder/reports/html_report.rb +10 -1
  78. data/lib/license_finder/reports/markdown_report.rb +7 -1
  79. data/lib/license_finder/reports/templates/bootstrap.css +9 -0
  80. data/lib/license_finder/reports/templates/html_report.erb +105 -0
  81. data/lib/{templates → license_finder/reports/templates}/markdown_report.erb +7 -7
  82. data/lib/license_finder/reports/text_report.rb +5 -3
  83. data/lib/license_finder/version.rb +3 -0
  84. data/license_finder.gemspec +2 -6
  85. data/release/instructions.md +8 -0
  86. data/spec/feature_helper.rb +11 -0
  87. data/spec/fixtures/config/license_finder.yml +3 -0
  88. data/spec/fixtures/{nested_readme/vendor/README → license_directory/LICENSE/Apache.txt} +0 -0
  89. data/spec/lib/license_finder/cli/approvals_spec.rb +63 -0
  90. data/spec/lib/license_finder/cli/dependencies_spec.rb +59 -0
  91. data/spec/lib/license_finder/cli/ignored_dependencies_spec.rb +47 -0
  92. data/spec/lib/license_finder/cli/ignored_groups_spec.rb +40 -0
  93. data/spec/lib/license_finder/cli/licenses_spec.rb +60 -0
  94. data/spec/lib/license_finder/cli/main_spec.rb +110 -0
  95. data/spec/lib/license_finder/cli/project_name_spec.rb +40 -0
  96. data/spec/lib/license_finder/cli/whitelist_spec.rb +58 -0
  97. data/spec/lib/license_finder/configuration_spec.rb +46 -191
  98. data/spec/lib/license_finder/decision_applier_spec.rb +65 -0
  99. data/spec/lib/license_finder/decisions_spec.rb +347 -0
  100. data/spec/lib/license_finder/license/definitions_spec.rb +1 -7
  101. data/spec/lib/license_finder/license_spec.rb +2 -30
  102. data/spec/lib/license_finder/package_manager_spec.rb +22 -0
  103. data/spec/lib/license_finder/package_managers/bower_package_spec.rb +33 -66
  104. data/spec/lib/license_finder/package_managers/bundler_package_spec.rb +7 -71
  105. data/spec/lib/license_finder/package_managers/cocoa_pods_package_spec.rb +8 -11
  106. data/spec/lib/license_finder/package_managers/gradle_package_spec.rb +28 -32
  107. data/spec/lib/license_finder/package_managers/gradle_spec.rb +18 -23
  108. data/spec/lib/license_finder/package_managers/maven_package_spec.rb +20 -43
  109. data/spec/lib/license_finder/package_managers/npm_package_spec.rb +22 -73
  110. data/spec/lib/license_finder/package_managers/npm_spec.rb +18 -21
  111. data/spec/lib/license_finder/package_managers/pip_package_spec.rb +24 -63
  112. data/spec/lib/license_finder/package_spec.rb +121 -0
  113. data/spec/lib/license_finder/possible_license_file_spec.rb +2 -3
  114. data/spec/lib/license_finder/possible_license_files_spec.rb +18 -22
  115. data/spec/lib/license_finder/reports/csv_report_spec.rb +26 -0
  116. data/spec/lib/license_finder/reports/html_report_spec.rb +39 -22
  117. data/spec/lib/license_finder/reports/markdown_report_spec.rb +8 -16
  118. data/spec/lib/license_finder/reports/text_report_spec.rb +21 -12
  119. data/spec/spec_helper.rb +1 -4
  120. data/spec/support/shared_examples_for_package.rb +0 -11
  121. data/spec/support/shared_examples_for_package_manager.rb +1 -0
  122. data/spec/support/stdout_helpers.rb +4 -11
  123. metadata +73 -158
  124. data/db/migrate/201303290935_create_dependencies.rb +0 -14
  125. data/db/migrate/201303291155_create_licenses.rb +0 -13
  126. data/db/migrate/201303291402_create_approvals.rb +0 -13
  127. data/db/migrate/201303291456_create_ancestries.rb +0 -9
  128. data/db/migrate/201303291519_create_bundler_groups.rb +0 -13
  129. data/db/migrate/201303291720_move_manual_from_approvals_to_licenses.rb +0 -11
  130. data/db/migrate/201303291753_allow_null_license_names.rb +0 -7
  131. data/db/migrate/201304011027_allow_null_dependency_version.rb +0 -7
  132. data/db/migrate/201304020947_change_table_name_licenses_to_license_aliases.rb +0 -5
  133. data/db/migrate/201304181524_add_manual_to_dependencies.rb +0 -7
  134. data/db/migrate/201307250917_add_license_manual_to_dependencies.rb +0 -7
  135. data/db/migrate/201307251004_data_fix_manual_licenses.rb +0 -15
  136. data/db/migrate/201307251107_reassociate_license.rb +0 -23
  137. data/db/migrate/201307251340_remove_manual_from_license_aliases.rb +0 -7
  138. data/db/migrate/201311192002_add_manually_approved_to_dependencies.rb +0 -7
  139. data/db/migrate/201311192003_reassociate_manual_approval.rb +0 -13
  140. data/db/migrate/201311192010_drop_approvals.rb +0 -5
  141. data/db/migrate/201401302113_re_reassociate_license.rb +0 -23
  142. data/db/migrate/201403181732_rename_manual_fields.rb +0 -10
  143. data/db/migrate/201403190028_add_manual_approvals.rb +0 -22
  144. data/db/migrate/201403191419_add_timestamps_to_manual_approvals.rb +0 -15
  145. data/db/migrate/201403191645_remove_license_aliases.rb +0 -23
  146. data/db/migrate/201410031451_rename_dependency_license_name.rb +0 -6
  147. data/features/cli.feature +0 -37
  148. data/features/cocoapods_dependencies.feature +0 -10
  149. data/features/configure_bundler_groups.feature +0 -23
  150. data/features/configure_ignore_dependencies.feature +0 -16
  151. data/features/configure_project_name.feature +0 -10
  152. data/features/configure_whitelist.feature +0 -27
  153. data/features/gradle_dependencies.feature +0 -9
  154. data/features/manually_added.feature +0 -19
  155. data/features/manually_approved.feature +0 -10
  156. data/features/manually_assigned_license.feature +0 -16
  157. data/features/maven_dependencies.feature +0 -9
  158. data/features/multiple_licenses.feature +0 -9
  159. data/features/node_dependencies.feature +0 -9
  160. data/features/python_dependencies.feature +0 -9
  161. data/features/report_csv.feature +0 -15
  162. data/features/report_html.feature +0 -24
  163. data/features/step_definitions/cli_steps.rb +0 -51
  164. data/features/step_definitions/cocoapod_steps.rb +0 -8
  165. data/features/step_definitions/configure_bundler_groups_steps.rb +0 -30
  166. data/features/step_definitions/configure_ignore_dependencies.rb +0 -35
  167. data/features/step_definitions/configure_project_name_steps.rb +0 -3
  168. data/features/step_definitions/configure_whitelist_steps.rb +0 -45
  169. data/features/step_definitions/gradle_steps.rb +0 -8
  170. data/features/step_definitions/manually_added_steps.rb +0 -28
  171. data/features/step_definitions/manually_approved_steps.rb +0 -24
  172. data/features/step_definitions/manually_assigned_license_steps.rb +0 -34
  173. data/features/step_definitions/maven_steps.rb +0 -8
  174. data/features/step_definitions/multiple_licenses_steps.rb +0 -14
  175. data/features/step_definitions/node_steps.rb +0 -8
  176. data/features/step_definitions/python_steps.rb +0 -8
  177. data/features/step_definitions/report_csv_steps.rb +0 -20
  178. data/features/step_definitions/report_html_steps.rb +0 -60
  179. data/features/step_definitions/shared_steps.rb +0 -307
  180. data/lib/data/license_finder.example.yml +0 -12
  181. data/lib/license_finder/dependency_manager.rb +0 -92
  182. data/lib/license_finder/package_saver.rb +0 -44
  183. data/lib/license_finder/reports/dependency_report.rb +0 -34
  184. data/lib/license_finder/reports/detailed_text_report.rb +0 -19
  185. data/lib/license_finder/reports/formatted_report.rb +0 -40
  186. data/lib/license_finder/reports/reporter.rb +0 -27
  187. data/lib/license_finder/tables.rb +0 -9
  188. data/lib/license_finder/tables/bundler_group.rb +0 -7
  189. data/lib/license_finder/tables/dependency.rb +0 -113
  190. data/lib/license_finder/tables/manual_approval.rb +0 -13
  191. data/lib/license_finder/yml_to_sql.rb +0 -117
  192. data/lib/templates/html_report.erb +0 -117
  193. data/lib/templates/text_report.erb +0 -3
  194. data/release/gem_version.rb +0 -3
  195. data/release/manual_instructions.md +0 -29
  196. data/release/publish.sh +0 -32
  197. data/spec/fixtures/APACHE-2-LICENSE +0 -202
  198. data/spec/fixtures/GPLv2 +0 -339
  199. data/spec/fixtures/ISC-LICENSE +0 -10
  200. data/spec/fixtures/MIT-LICENSE +0 -22
  201. data/spec/fixtures/MIT-LICENSE-with-varied-disclaimer +0 -22
  202. data/spec/fixtures/README-with-MIT-LICENSE +0 -222
  203. data/spec/fixtures/license_directory/LICENSE/BSD-2-Clause.txt +0 -25
  204. data/spec/fixtures/license_directory/LICENSE/GPL-2.0.txt +0 -339
  205. data/spec/fixtures/license_directory/LICENSE/LICENSE +0 -191
  206. data/spec/fixtures/license_directory/LICENSE/MIT.txt +0 -21
  207. data/spec/fixtures/license_directory/LICENSE/RUBY.txt +0 -60
  208. data/spec/fixtures/mit_licensed_gem/LICENSE +0 -22
  209. data/spec/fixtures/other_licensed_gem/LICENSE +0 -3
  210. data/spec/fixtures/readme/Project ReadMe b/data/spec/fixtures/readme/Project → ReadMe +0 -0
  211. data/spec/fixtures/readme/README +0 -0
  212. data/spec/fixtures/readme/Readme.markdown +0 -0
  213. data/spec/lib/license_finder/cli_spec.rb +0 -298
  214. data/spec/lib/license_finder/dependency_manager_spec.rb +0 -198
  215. data/spec/lib/license_finder/package_saver_spec.rb +0 -82
  216. data/spec/lib/license_finder/reports/detailed_text_report_spec.rb +0 -33
  217. data/spec/lib/license_finder/reports/reporter_spec.rb +0 -33
  218. data/spec/lib/license_finder/tables/dependency_spec.rb +0 -196
  219. data/spec/lib/license_finder/yml_to_sql_spec.rb +0 -123
  220. data/spec/lib/license_finder_spec.rb +0 -16
@@ -2,17 +2,11 @@ require 'spec_helper'
2
2
 
3
3
  describe LicenseFinder::License::Definitions do
4
4
  it "should create unrecognized licenses" do
5
- license = described_class.build_unrecognized("foo", [])
5
+ license = described_class.build_unrecognized("foo")
6
6
  expect(license.name).to eq("foo")
7
7
  expect(license.url).to be_nil
8
8
  expect(license).to be_matches_name("foo")
9
9
  expect(license).not_to be_matches_text("foo")
10
- expect(license).not_to be_whitelisted
11
- end
12
-
13
- it "should whitelist unrecognized licenses" do
14
- license = described_class.build_unrecognized("foo", ["foo"])
15
- expect(license).to be_whitelisted
16
10
  end
17
11
  end
18
12
 
@@ -15,23 +15,13 @@ module LicenseFinder
15
15
  end
16
16
 
17
17
  context "making the default license" do
18
- it "set the name to 'other'" do
19
- expect(License.find_by_name(nil).name).to eq("other")
18
+ it "set the name to 'unknown'" do
19
+ expect(License.find_by_name(nil).name).to eq("unknown")
20
20
  end
21
21
 
22
22
  it "does not equal other uses of the default license" do
23
23
  expect(License.find_by_name(nil)).not_to eq(License.find_by_name(nil))
24
24
  end
25
-
26
- context "when there is a whitelist" do
27
- before do
28
- allow(LicenseFinder.config).to receive(:whitelist).and_return(["not empty"])
29
- end
30
-
31
- it "does not blow up" do
32
- expect(License.find_by_name(nil).name).to eq("other")
33
- end
34
- end
35
25
  end
36
26
  end
37
27
 
@@ -51,30 +41,12 @@ module LicenseFinder
51
41
  defaults = {
52
42
  short_name: "Default Short Name",
53
43
  url: "http://example.com/license",
54
- whitelisted: false,
55
44
  matcher: License::Matcher.from_text('Default Matcher')
56
45
  }
57
46
 
58
47
  License.new(defaults.merge(settings))
59
48
  end
60
49
 
61
- describe "#whitelisted?" do
62
- it "is true if the settings say it is" do
63
- expect(make_license).not_to be_whitelisted
64
- expect(make_license(whitelisted: true)).to be_whitelisted
65
- end
66
-
67
- it "can be made true (without mutating original)" do
68
- original = make_license
69
- license = original.whitelist
70
- expect(license).not_to eq(original)
71
- expect(license).to be_whitelisted
72
- expect(license.url).to eq("http://example.com/license")
73
- expect(license).to be_matches_name "Default Short Name"
74
- expect(license).to be_matches_text "Default Matcher"
75
- end
76
- end
77
-
78
50
  describe "#matches_name?" do
79
51
  it "should match on short_name" do
80
52
  expect(make_license(short_name: "Foo")).to be_matches_name "Foo"
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ module LicenseFinder
4
+ describe PackageManager do
5
+ describe "#current_packages_with_relations" do
6
+ it "sets packages' parents" do
7
+ grandparent = Package.new("grandparent", nil, children: ["parent"])
8
+ parent = Package.new("parent", nil, children: ["child"])
9
+ child = Package.new("child")
10
+
11
+ pm = described_class.new
12
+ allow(pm).to receive(:current_packages) { [grandparent, parent, child] }
13
+
14
+ expect(pm.current_packages_with_relations.map(&:parents)).to eq([
15
+ [].to_set,
16
+ ["grandparent"].to_set,
17
+ ["parent"].to_set
18
+ ])
19
+ end
20
+ end
21
+ end
22
+ end
@@ -23,83 +23,50 @@ module LicenseFinder
23
23
  its(:summary) { should == "description" }
24
24
  its(:description) { should == "some readme stuff" }
25
25
  its(:homepage) { should == "homepage" }
26
- its(:groups) { should == [] }
27
- its(:children) { should == [] }
26
+ its(:groups) { should == [] } # TODO: does `bower list` output devDependencies? If so, put them in 'dev' group?
27
+ its(:children) { should == [] } # TODO: get dependencies from dependencies and devDependencies, like NPM
28
+ its(:install_path) { should eq "/path/to/thing" }
29
+
30
+
31
+ context "when package is NOT installed" do
32
+ subject do
33
+ described_class.new(
34
+ "missing" => true,
35
+ "endpoint" => {
36
+ "name" => "some_package_that_is_not_installed",
37
+ "target" => ">=3.0"
38
+ }
39
+ )
40
+ end
41
+
42
+ it "shows the name and version from the endpoint block" do
43
+ expect(subject.name).to eq("some_package_that_is_not_installed")
44
+ expect(subject.version).to eq(">=3.0")
45
+ end
28
46
 
29
- describe '#licenses' do
30
- def stub_license_files(license_files)
31
- allow(PossibleLicenseFiles).to receive(:find).with("/path/to/thing").and_return(license_files)
47
+ it 'reports itself as missing' do
48
+ expect(subject).to be_missing
32
49
  end
50
+ end
33
51
 
34
- let(:package1) { { "pkgMeta" => {"license" => "MIT"}, "canonicalDir" => "/some/path" } }
35
- let(:package2) { { "pkgMeta" => {"licenses" => [{"type" => "BSD", "url" => "github.github/github"}]}, "canonicalDir" => "/some/path" } }
36
- let(:package3) { { "pkgMeta" => {"license" => {"type" => "PSF", "url" => "github.github/github"}}, "canonicalDir" => "/some/path" } }
37
- let(:package4) { { "pkgMeta" => {"licenses" => ["MIT"]}, "canonicalDir" => "/some/path" } }
52
+ describe '#license_names_from_spec' do
53
+ let(:package1) { { "pkgMeta" => {"license" => "MIT"} } }
54
+ let(:package2) { { "pkgMeta" => {"licenses" => [{"type" => "BSD"}]} } }
55
+ let(:package3) { { "pkgMeta" => {"license" => {"type" => "PSF"}} } }
56
+ let(:package4) { { "pkgMeta" => {"licenses" => ["MIT"]} } }
38
57
 
39
- it 'finds the license for both license structures' do
58
+ it 'finds the license for all license structures' do
40
59
  package = BowerPackage.new(package1)
41
- expect(package.licenses.length).to eq 1
42
- expect(package.licenses.first.name).to eq("MIT")
60
+ expect(package.license_names_from_spec).to eq ["MIT"]
43
61
 
44
62
  package = BowerPackage.new(package2)
45
- expect(package.licenses.length).to eq 1
46
- expect(package.licenses.first.name).to eq("BSD")
63
+ expect(package.license_names_from_spec).to eq ["BSD"]
47
64
 
48
65
  package = BowerPackage.new(package3)
49
- expect(package.licenses.length).to eq 1
50
- expect(package.licenses.first.name).to eq("Python Software Foundation License")
66
+ expect(package.license_names_from_spec).to eq ["PSF"]
51
67
 
52
68
  package = BowerPackage.new(package4)
53
- expect(package.licenses.length).to eq 1
54
- expect(package.licenses.first.name).to eq("MIT")
55
- end
56
-
57
-
58
- context "regardless of whether there are licenses in files" do
59
- before do
60
- stub_license_files [double(:file, license: License.find_by_name('Detected License'), path: "/")]
61
- end
62
-
63
- it "returns the license from the spec if there is only one unique license" do
64
- package = BowerPackage.new({ "pkgMeta" => {"licenses" => ["MIT", "Expat"]}, "canonicalDir" => "/path/to/thing" })
65
- expect(package.licenses.length).to eq 1
66
- expect(package.licenses.first.name).to eq("MIT")
67
- end
68
-
69
- it "returns 'multiple licenses' if there's more than one license" do
70
- package = BowerPackage.new({ "pkgMeta" => {"licenses" => ["MIT", "BSD"]}, "canonicalDir" => "/some/path" })
71
- expect(package.licenses.length).to eq 2
72
- expect(package.licenses.map(&:name)).to eq %w(MIT BSD)
73
- end
74
- end
75
-
76
- context "when there is nothing in the spec" do
77
- it "returns a license in a file if only one unique license detected" do
78
- stub_license_files([
79
- double(:first_file, license: License.find_by_name('MIT'), path: "/"),
80
- double(:second_file, license: License.find_by_name('Expat'), path: "/")
81
- ])
82
-
83
- expect(subject.licenses.length).to eq 1
84
- expect(subject.licenses.first.name).to eq "MIT"
85
- end
86
-
87
- it "returns 'other' if there are no licenses in files" do
88
- stub_license_files []
89
-
90
- expect(subject.licenses.length).to eq 1
91
- expect(subject.licenses.first.name).to eq "other"
92
- end
93
-
94
- it "returns 'other' if there are many licenses in files" do
95
- stub_license_files([
96
- double(:first_file, license: License.find_by_name('First Detected License'), path: "/"),
97
- double(:second_file, license: License.find_by_name('Second Detected License'), path: "/")
98
- ])
99
-
100
- expect(subject.licenses.length).to eq 2
101
- expect(subject.licenses.map(&:name)).to eq ["First Detected License", "Second Detected License"]
102
- end
69
+ expect(package.license_names_from_spec).to eq ["MIT"]
103
70
  end
104
71
  end
105
72
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  module LicenseFinder
4
4
  describe BundlerPackage do
5
- subject { described_class.new(gemspec, nil) }
5
+ subject { described_class.new(gemspec, bundler_dependency) }
6
6
 
7
7
  it_behaves_like "a Package"
8
8
 
@@ -13,86 +13,22 @@ module LicenseFinder
13
13
  s.summary = 'summary'
14
14
  s.description = 'description'
15
15
  s.homepage = 'homepage'
16
+ s.licenses = ['MIT', 'GPL']
16
17
 
17
18
  s.add_dependency 'foo'
18
19
  end
19
20
  end
20
21
 
22
+ let(:bundler_dependency) { double(:dependency, groups: [1, 2, 3]) }
23
+
21
24
  its(:name) { should == 'spec_name' }
22
25
  its(:version) { should == '2.1.3' }
23
26
  its(:summary) { should == "summary" }
24
27
  its(:description) { should == "description" }
25
28
  its(:homepage) { should == "homepage" }
26
- its(:groups) { should == [] }
29
+ its(:groups) { should == [1, 2, 3] }
27
30
  its(:children) { should == ['foo'] }
28
-
29
- describe "#licenses" do
30
- def stub_license_files(license_files)
31
- allow(PossibleLicenseFiles).to receive(:find).and_return(license_files)
32
- end
33
-
34
- context "regardless of whether there are licenses in files" do
35
- before do
36
- stub_license_files [double(:file, license: License.find_by_name('Detected License'), path: "/")]
37
- end
38
-
39
- context 'if the gemspec provides two synonymous licenses' do
40
- before { gemspec.licenses = ['MIT', 'Expat'] }
41
-
42
- it 'returns the license only once' do
43
- expect(subject.licenses.length).to eq 1
44
- expect(subject.licenses.first.name).to eq "MIT"
45
- end
46
- end
47
-
48
- context 'if the gemspec provides many licenses' do
49
- before { gemspec.licenses = ['First Gemspec License', 'Second Gemspec License'] }
50
-
51
- it "returns 'multiple licenses' with the names of the licenses from the gemspec (but not those from detected files)" do
52
- expect(subject.licenses.length).to eq 2
53
- expect(subject.licenses.map(&:name)).to eq ["First Gemspec License", "Second Gemspec License"]
54
- end
55
- end
56
- end
57
-
58
- context "when there is nothing in the spec" do
59
- it "returns a license in a file if there is only one unique license detected" do
60
- stub_license_files([
61
- double(:first_file, license: License.find_by_name('MIT'), path: "/"),
62
- double(:second_file, license: License.find_by_name('Expat'), path: "/")
63
- ])
64
-
65
- expect(subject.licenses.length).to eq 1
66
- expect(subject.licenses.first.name).to eq "MIT"
67
- end
68
-
69
- it "returns 'other' if there are no licenses in files" do
70
- stub_license_files []
71
-
72
- expect(subject.licenses.length).to eq 1
73
- expect(subject.licenses.first.name).to eq "other"
74
- end
75
-
76
- it "returns 'multiple licenses' if there are many licenses in files" do
77
- stub_license_files([
78
- double(:first_file, license: License.find_by_name('First Detected License'), path: "/"),
79
- double(:second_file, license: License.find_by_name('Second Detected License'), path: "/")
80
- ])
81
-
82
- expect(subject.licenses.length).to eq 2
83
- expect(subject.licenses.map(&:name)).to eq ["First Detected License", "Second Detected License"]
84
- end
85
- end
86
- end
87
-
88
- describe "#groups" do
89
- subject { described_class.new(gemspec, bundler_dependency) }
90
-
91
- let(:bundler_dependency) { double(:dependency, groups: [1, 2, 3]) }
92
-
93
- it "returns bundler dependency's groups" do
94
- expect(subject.groups).to eq(bundler_dependency.groups)
95
- end
96
- end
31
+ its(:license_names_from_spec) { should eq ['MIT', 'GPL'] }
32
+ its(:install_path) { should =~ /spec_name-2\.1\.3\z/ }
97
33
  end
98
34
  end
@@ -11,9 +11,9 @@ module LicenseFinder
11
11
 
12
12
  its(:name) { should == "Name" }
13
13
  its(:version) { should == "1.0.0" }
14
- its(:summary) { should be_nil }
15
- its(:description) { should be_nil }
16
- its(:homepage) { should be_nil }
14
+ its(:summary) { should eq "" }
15
+ its(:description) { should eq "" }
16
+ its(:homepage) { should eq "" }
17
17
  its(:groups) { should == [] }
18
18
  its(:children) { should == [] }
19
19
 
@@ -25,21 +25,18 @@ module LicenseFinder
25
25
  license = double(:license, name: "LicenseName")
26
26
  allow(License).to receive(:find_by_text).with(license_text).and_return(license)
27
27
 
28
- expect(subject.licenses.length).to eq 1
29
- expect(subject.licenses.first.name).to eq "LicenseName"
28
+ expect(subject.licenses.map(&:name)).to eq ["LicenseName"]
30
29
  end
31
30
 
32
- it "returns other if the license can't be found by text" do
31
+ it "returns unknown if the license can't be found by text" do
33
32
  allow(License).to receive(:find_by_text).with(license_text).and_return(nil)
34
33
 
35
- expect(subject.licenses.length).to eq 1
36
- expect(subject.licenses.first.name).to eq "other"
34
+ expect(subject.licenses.map(&:name)).to eq ["unknown"]
37
35
  end
38
36
  end
39
37
 
40
- it "returns other when there's no license" do
41
- expect(subject.licenses.length).to eq 1
42
- expect(subject.licenses.first.name).to eq "other"
38
+ it "returns unknown when there's no license" do
39
+ expect(subject.licenses.map(&:name)).to eq ["unknown"]
43
40
  end
44
41
  end
45
42
  end
@@ -4,13 +4,8 @@ module LicenseFinder
4
4
  describe GradlePackage do
5
5
  subject do
6
6
  described_class.new(
7
- {
8
- "name" => "ch.qos.logback:logback-classic:1.1.1",
9
- "file" => ["logback-classic-1.1.1.jar"],
10
- "license" => [
11
- { "name" => "Eclipse Public License - v 1.0", "url"=>"http://www.eclipse.org/legal/epl-v10.html"}
12
- ]
13
- }
7
+ "name" => "ch.qos.logback:logback-classic:1.1.1",
8
+ "license" => [ { "name" => "MIT" } ]
14
9
  )
15
10
  end
16
11
 
@@ -18,48 +13,49 @@ module LicenseFinder
18
13
 
19
14
  its(:name) { should == "logback-classic" }
20
15
  its(:version) { should == "1.1.1" }
16
+ its(:summary) { should == "" }
21
17
  its(:description) { should == "" }
18
+ its(:homepage) { should == "" }
19
+ its(:groups) { should == [] } # no way to get groups from gradle?
20
+ its(:children) { should == [] } # no way to get children from gradle?
21
+ its(:install_path) { should be_nil }
22
22
 
23
- describe "#licenses" do
24
- it "returns the license if found" do
25
- expect(subject.licenses.length).to eq 1
26
- expect(subject.licenses.first.name).to eq "Eclipse Public License - v 1.0"
23
+ describe "#license_names_from_spec" do
24
+ it "returns the license" do
25
+ expect(subject.license_names_from_spec).to eq ["MIT"]
27
26
  end
28
27
 
29
- context "when there are multiple licenses" do
28
+ context "when there are no licenses" do
29
+ subject { described_class.new("name" => "a:b:c") }
30
+
31
+ it "is empty" do
32
+ expect(subject.license_names_from_spec).to be_empty
33
+ end
34
+ end
35
+
36
+ context "when there are no real licenses" do
30
37
  subject do
31
38
  described_class.new(
32
- {
33
- "name" => "ch.qos.logback:logback-classic:1.1.1",
34
- "file" => ["logback-classic-1.1.1.jar"],
35
- "license" => [
36
- { "name" => "Eclipse Public License - v 1.0", "url"=>"http://www.eclipse.org/legal/epl-v10.html"},
37
- { "name"=>"GNU Lesser General Public License", "url"=>"http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html"}
38
- ]
39
- }
39
+ "name" => "a:b:c",
40
+ "license" => [ { "name" => "No license found"} ]
40
41
  )
41
42
  end
42
43
 
43
- it "returns 'multiple licenses'" do
44
- expect(subject.licenses.length).to eq 2
45
- expect(subject.licenses.map(&:name)).to eq ['Eclipse Public License - v 1.0', 'GNU Lesser General Public License']
44
+ it "is empty" do
45
+ expect(subject.license_names_from_spec).to be_empty
46
46
  end
47
47
  end
48
48
 
49
- context "when the license is not found" do
49
+ context "when there are multiple licenses" do
50
50
  subject do
51
51
  described_class.new(
52
- {
53
- "name" => "ch.qos.logback:logback-classic:1.1.1",
54
- "file" => ["logback-classic-1.1.1.jar"],
55
- "license" => []
56
- }
52
+ "name" => "a:b:c",
53
+ "license" => [ { "name" => "1" }, { "name" => "2" } ]
57
54
  )
58
55
  end
59
56
 
60
- it "returns 'other' otherwise" do
61
- expect(subject.licenses.length).to eq 1
62
- expect(subject.licenses.first.name).to eq "other"
57
+ it "returns multiple licenses" do
58
+ expect(subject.license_names_from_spec).to eq ['1', '2']
63
59
  end
64
60
  end
65
61
  end