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
@@ -0,0 +1,121 @@
1
+ require 'spec_helper'
2
+
3
+ module LicenseFinder
4
+ describe Package do
5
+ subject do
6
+ described_class.new(
7
+ "a package",
8
+ "1.3.1",
9
+ summary: "a summary",
10
+ description: "a description",
11
+ homepage: "a homepage",
12
+ groups: %w[dev test],
13
+ children: %w[child-1 child2],
14
+ install_path: "some/package/path",
15
+ spec_licenses: %w[MIT GPL]
16
+ )
17
+ end
18
+
19
+ it_behaves_like "a Package"
20
+
21
+ its(:name) { should == "a package" }
22
+ its(:version) { should == "1.3.1" }
23
+ its(:summary) { should == "a summary" }
24
+ its(:description) { should == "a description" }
25
+ its(:homepage) { should == "a homepage" }
26
+ its(:groups) { should == %w[dev test] }
27
+ its(:children) { should == %w[child-1 child2] }
28
+ its(:install_path) { should eq "some/package/path" }
29
+
30
+ it "has defaults" do
31
+ subject = described_class.new(nil, nil)
32
+ expect(subject.name).to be_nil
33
+ expect(subject.version).to be_nil
34
+ expect(subject.summary).to eq ""
35
+ expect(subject.description).to eq ""
36
+ expect(subject.homepage).to eq ""
37
+ expect(subject.groups).to eq []
38
+ expect(subject.children).to eq []
39
+ expect(subject.install_path).to be_nil
40
+ expect(subject.license_names_from_spec).to eq []
41
+ expect(subject.licenses.map(&:name)).to eq ['unknown']
42
+ end
43
+
44
+ describe '#licenses' do
45
+ def stub_license_files(*license_names)
46
+ license_files = license_names.map do |license_name|
47
+ double(:file, license: License.find_by_name(license_name), path: "some/path")
48
+ end
49
+ allow(PossibleLicenseFiles).to receive(:find).
50
+ with("some/package/path").and_return(license_files)
51
+ end
52
+
53
+ it "are not required" do
54
+ subject = described_class.new(nil, nil)
55
+ expect(subject.licenses.map(&:name)).to eq ['unknown']
56
+ end
57
+
58
+ describe "decided by user" do
59
+ it "returns all decided licenses" do
60
+ subject = described_class.new(nil, nil)
61
+ subject.decide_on_license(License.find_by_name("MIT"))
62
+ subject.decide_on_license(License.find_by_name("GPL"))
63
+ expect(subject.licenses.map(&:name)).to match_array ["MIT", "GPL"]
64
+ end
65
+
66
+ it "de-duplicates across license aliases" do
67
+ subject = described_class.new(nil, nil)
68
+ subject.decide_on_license(License.find_by_name("MIT"))
69
+ subject.decide_on_license(License.find_by_name("Expat"))
70
+ expect(subject.licenses.map(&:name)).to eq ["MIT"]
71
+ end
72
+
73
+ it "trumps licenses from the spec" do
74
+ subject = described_class.new(nil, nil, spec_licenses: ["GPL"])
75
+ subject.decide_on_license(License.find_by_name("MIT"))
76
+ expect(subject.licenses.map(&:name)).to eq ["MIT"]
77
+ end
78
+
79
+ it "trumps licenses from the install path" do
80
+ stub_license_files 'Detected License'
81
+ subject = described_class.new(nil, nil, install_path: "some/package/path")
82
+ subject.decide_on_license(License.find_by_name("MIT"))
83
+ expect(subject.licenses.map(&:name)).to eq ["MIT"]
84
+ end
85
+ end
86
+
87
+ describe "from the spec" do
88
+ it "converts the names to licenses" do
89
+ subject = described_class.new(nil, nil, spec_licenses: ["MIT", "GPL"])
90
+ expect(subject.licenses.map(&:name)).to match_array ["MIT", "GPL"]
91
+ end
92
+
93
+ it "de-duplicates across license aliases" do
94
+ subject = described_class.new(nil, nil, spec_licenses: ["MIT", "Expat"])
95
+ expect(subject.licenses.map(&:name)).to eq ["MIT"]
96
+ end
97
+
98
+ it "trumps licenses from the install path" do
99
+ stub_license_files 'Detected License'
100
+ subject = described_class.new(nil, nil, spec_licenses: ["MIT"], install_path: "some/package/path")
101
+ expect(subject.licenses.map(&:name)).to eq ["MIT"]
102
+ end
103
+ end
104
+
105
+ describe "from the install path" do
106
+ it "uses the licenses reported by files in the install path" do
107
+ stub_license_files 'MIT', 'GPL'
108
+ subject = described_class.new(nil, nil, install_path: "some/package/path")
109
+ expect(subject.licenses.map(&:name)).to eq ["MIT", "GPL"]
110
+ end
111
+
112
+ it "de-duplicates across license aliases" do
113
+ stub_license_files 'MIT', 'Expat'
114
+ subject = described_class.new(nil, nil, install_path: "some/package/path")
115
+ expect(subject.licenses.map(&:name)).to eq ["MIT"]
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
121
+
@@ -3,20 +3,19 @@ require 'spec_helper'
3
3
  module LicenseFinder
4
4
  describe PossibleLicenseFile do
5
5
  context "file parsing" do
6
- subject { described_class.new('root', 'root/nested/path') }
6
+ subject { described_class.new('root/nested/path') }
7
7
 
8
8
  context "ignoring text" do
9
9
  before do
10
10
  allow(subject).to receive(:text).and_return('file text')
11
11
  end
12
12
 
13
- its(:file_path) { should == 'nested/path' }
14
13
  its(:text) { should == 'file text' } # this is a terrible test, considering the stubbing
15
14
  its(:path) { should == 'root/nested/path' }
16
15
  end
17
16
  end
18
17
 
19
- subject { described_class.new('gem', 'gem/license/path') }
18
+ subject { described_class.new('gem/license/path') }
20
19
 
21
20
  context "with a known license" do
22
21
  before do
@@ -3,51 +3,47 @@ require 'spec_helper'
3
3
  module LicenseFinder
4
4
  describe PossibleLicenseFiles do
5
5
  def fixture_path(fixture)
6
- Pathname.new(File.join(File.dirname(__FILE__), '..', '..', '..', 'spec', 'fixtures', fixture)).realpath.to_s
6
+ Pathname.new(__FILE__).dirname.join('..', '..', 'fixtures', fixture)
7
7
  end
8
8
 
9
9
  describe "#find" do
10
+ def files_in(fixture)
11
+ root_path = fixture_path(fixture)
12
+ subject = described_class.find(root_path.to_s)
13
+
14
+ subject.map do |f|
15
+ Pathname(f.path).relative_path_from(root_path).to_s
16
+ end
17
+ end
18
+
10
19
  it "is empty if passed a nil install path" do
11
20
  subject = described_class.new nil
12
21
  expect(subject.find).to eq([])
13
22
  end
14
23
 
15
24
  it "is empty if there aren't any license files" do
16
- subject = described_class.new('/not/a/dir')
17
- expect(subject.find).to eq([])
25
+ expect(files_in('not/a/dir')).to eq([])
18
26
  end
19
27
 
20
- it "includes files with names like LICENSE, License or COPYING" do
21
- subject = described_class.new(fixture_path('license_names'))
22
-
23
- expect(subject.find.map(&:file_path)).to match_array(
28
+ it "includes files with names like LICENSE, README or COPYING" do
29
+ expect(files_in('license_names')).to match_array(
24
30
  %w[COPYING.txt LICENSE Mit-License README.rdoc Licence.rdoc]
25
31
  )
26
32
  end
27
33
 
28
34
  it "includes files deep in the hierarchy" do
29
- subject = described_class.new(fixture_path('nested_gem'))
30
-
31
- expect(subject.find.map(&:file_path)).to match_array(%w[vendor/LICENSE])
35
+ expect(files_in('nested_gem')).to eq(['vendor/LICENSE'])
32
36
  end
33
37
 
34
- it "includes both files nested inside LICENSE directory and top level files" do
35
- subject = described_class.new(fixture_path('license_directory'))
36
- found_license_files = subject.find
37
-
38
- expect(found_license_files.map(&:file_path)).to match_array(%w[
39
- LICENSE/BSD-2-Clause.txt
40
- LICENSE/GPL-2.0.txt
41
- LICENSE/MIT.txt
42
- LICENSE/RUBY.txt
38
+ it "includes files nested inside LICENSE directory" do
39
+ expect(files_in('license_directory')).to match_array(%w[
43
40
  COPYING
44
- LICENSE/LICENSE
41
+ LICENSE/Apache.txt
45
42
  ])
46
43
  end
47
44
 
48
45
  it "handles non UTF8 encodings" do
49
- subject = described_class.new(fixture_path('utf8_gem'))
50
- expect { subject.find }.not_to raise_error
46
+ expect { files_in('utf8_gem') }.not_to raise_error
51
47
  end
52
48
  end
53
49
  end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ module LicenseFinder
4
+ describe CsvReport do
5
+ it "accepts a custom list of columns" do
6
+ dep = Package.new('gem_a', '1.0')
7
+ subject = described_class.new([dep], columns: %w[name version])
8
+ expect(subject.to_s).to eq("gem_a,1.0\n")
9
+ end
10
+
11
+ it "understands many columns" do
12
+ dep = Package.new('gem_a', '1.0', description: "A description", summary: "A summary")
13
+ dep.decide_on_license(License.find_by_name("MIT"))
14
+ dep.decide_on_license(License.find_by_name("GPL"))
15
+ dep.whitelisted!
16
+ subject = described_class.new([dep], columns: %w[name version licenses approved summary description])
17
+ expect(subject.to_s).to eq("gem_a,1.0,\"MIT,GPL\",Approved,A summary,A description\n")
18
+ end
19
+
20
+ it "ignores unknown columns" do
21
+ dep = Package.new('gem_a', '1.0')
22
+ subject = described_class.new([dep], columns: %w[unknown])
23
+ expect(subject.to_s).to eq("\n")
24
+ end
25
+ end
26
+ end
@@ -4,17 +4,22 @@ require "capybara"
4
4
  module LicenseFinder
5
5
  describe HtmlReport do
6
6
  describe "#to_s" do
7
- let(:dependency_name) { "the-name" }
8
7
  let(:dependency) do
9
- dep = Dependency.create name: dependency_name
10
- dep.set_licenses [License.find_by_name("MIT")].to_set
8
+ dep = Package.new("the-dep")
9
+ dep.decide_on_license License.find_by_name("MIT")
11
10
  dep
12
11
  end
12
+ let(:dependencies) { [dependency] }
13
13
 
14
- subject { Capybara.string(HtmlReport.new([dependency]).to_s) }
14
+ subject { Capybara.string(HtmlReport.new(dependencies, project_name: "project name").to_s) }
15
+
16
+ it "should show the project name" do
17
+ title = subject.find "h1"
18
+ expect(title).to have_text "project name"
19
+ end
15
20
 
16
21
  context "when the dependency is manually approved" do
17
- before { dependency.approve! "the-approver", "the-approval-note" }
22
+ before { dependency.approved_manually!(Decisions::TXN.new("the-approver", "the-approval-note", Time.now.utc)) }
18
23
 
19
24
  it "should show approved dependencies without action items" do
20
25
  is_expected.to have_selector ".approved"
@@ -31,7 +36,7 @@ module LicenseFinder
31
36
  end
32
37
 
33
38
  context "when the dependency is whitelisted" do
34
- before { allow(dependency).to receive_messages(whitelisted?: true) }
39
+ before { dependency.whitelisted! }
35
40
 
36
41
  it "should show approved dependencies without action items" do
37
42
  is_expected.to have_selector ".approved"
@@ -45,38 +50,50 @@ module LicenseFinder
45
50
  end
46
51
 
47
52
  context "when the dependency is not approved" do
48
- before {
49
- dependency.licenses = [License.find_by_name('GPL')].to_set
50
- dependency.manual_approval = nil
51
- }
52
-
53
53
  it "should show unapproved dependencies with action items" do
54
54
  is_expected.to have_selector ".unapproved"
55
55
  is_expected.to have_selector ".action-items li"
56
56
  end
57
57
  end
58
58
 
59
+ context "when the gem has a group" do
60
+ let(:dependency) do
61
+ Package.new(nil, nil, groups: ["foo group"])
62
+ end
63
+
64
+ it "should show the group" do
65
+ is_expected.to have_text "(foo group)"
66
+ end
67
+ end
68
+
69
+ context "when the gem does not have a group" do
70
+ it "should not show the group" do
71
+ is_expected.not_to have_text "()"
72
+ end
73
+ end
74
+
59
75
  context "when the gem has many relationships" do
60
- before do
61
- allow(dependency).to receive_messages(bundler_groups: [double(name: "foo group")],
62
- parents: [double(name: "foo parent")],
63
- children: [double(name: "foo child")])
76
+ let(:dependencies) do
77
+ grandparent = Package.new("foo grandparent", nil, children: ["foo parent"])
78
+ parent = Package.new("foo parent", nil, children: ["foo child"])
79
+ child = Package.new("foo child")
80
+ pm = PackageManager.new
81
+ allow(pm).to receive(:current_packages) { [grandparent, parent, child] }
82
+ pm.current_packages_with_relations
64
83
  end
65
84
 
66
85
  it "should show the relationships" do
67
- is_expected.to have_text "(foo group)"
68
- is_expected.to have_text "#{dependency_name} is required by:"
69
- is_expected.to have_text "foo parent"
70
- is_expected.to have_text "#{dependency_name} relies on:"
86
+ is_expected.to have_text "foo parent is required by:"
87
+ is_expected.to have_text "foo grandparent"
88
+ is_expected.to have_text "foo parent relies on:"
71
89
  is_expected.to have_text "foo child"
72
90
  end
73
91
  end
74
92
 
75
93
  context "when the gem has no relationships" do
76
94
  it "should not show any relationships" do
77
- is_expected.not_to have_text "()"
78
- is_expected.not_to have_text "#{dependency_name} is required by:"
79
- is_expected.not_to have_text "#{dependency_name} relies on:"
95
+ is_expected.not_to have_text "is required by:"
96
+ is_expected.not_to have_text "relies on:"
80
97
  end
81
98
  end
82
99
  end
@@ -4,27 +4,19 @@ module LicenseFinder
4
4
  describe MarkdownReport do
5
5
  describe '#to_s' do
6
6
  let(:dep1) do
7
- Dependency.new(
8
- 'name' => 'gem_a',
9
- 'version' => '1.0',
10
- 'licenses' => [License.find_by_name('other')].to_set
11
- )
7
+ Package.new('gem_a', '1.0')
12
8
  end
13
9
 
14
10
  let(:dep2) do
15
- dependency = Dependency.create(
16
- 'name' => 'gem_b',
17
- 'version' => '2.3',
18
- 'licenses' => [License.find_by_name('BSD')].to_set
19
- )
20
- dependency.approve!
21
- dependency
11
+ result = Package.new('gem_b', '2.3')
12
+ result.decide_on_license(License.find_by_name('BSD'))
13
+ result.approved_manually!(double(:approval).as_null_object)
14
+ result
22
15
  end
23
16
 
24
- subject { MarkdownReport.new([dep2, dep1]).to_s }
17
+ subject { MarkdownReport.new([dep2, dep1], project_name: "new_project_name").to_s }
25
18
 
26
19
  it 'should have the correct header' do
27
- LicenseFinder.config.project_name = "new_project_name"
28
20
  is_expected.to match "# new_project_name"
29
21
  end
30
22
 
@@ -34,12 +26,12 @@ module LicenseFinder
34
26
  end
35
27
 
36
28
  it "should list the unapproved dependency" do
37
- is_expected.to match "href='#gem_a'"
29
+ is_expected.to match 'href="#gem_a"'
38
30
  end
39
31
 
40
32
  it "should display a summary" do
41
33
  is_expected.to match "## Summary"
42
- is_expected.to match /\s+\* 1 other/
34
+ is_expected.to match /\s+\* 1 unknown/
43
35
  is_expected.to match /\s+\* 1 BSD/
44
36
  end
45
37
 
@@ -4,25 +4,34 @@ module LicenseFinder
4
4
  describe TextReport do
5
5
  describe '#to_s' do
6
6
  let(:dep1) do
7
- Dependency.new(
8
- 'name' => 'gem_a',
9
- 'version' => '1.0',
10
- 'licenses' => [License.find_by_name('MIT')].to_set
11
- )
7
+ result = Package.new('gem_a', '1.0')
8
+ result.decide_on_license(License.find_by_name('MIT'))
9
+ result
12
10
  end
13
11
 
14
12
  let(:dep2) do
15
- Dependency.new(
16
- 'name' => 'gem_b',
17
- 'version' => '1.0',
18
- 'licenses' => [License.find_by_name('MIT')].to_set
19
- )
13
+ result = Package.new('gem_b', '1.0')
14
+ result.decide_on_license(License.find_by_name('MIT'))
15
+ result
20
16
  end
21
17
 
22
- subject { TextReport.new([dep2, dep1]).to_s }
18
+ let(:dep3) do
19
+ result = Package.new('gem_c', '2.0')
20
+ result.decide_on_license(License.find_by_name('MIT'))
21
+ result.decide_on_license(License.find_by_name('BSD'))
22
+ result
23
+ end
24
+
25
+ subject { described_class.new([dep3, dep2, dep1]).to_s }
23
26
 
24
27
  it 'should generate a text report with the name, version and license of each dependency, sorted by name' do
25
- is_expected.to eq("gem_a, 1.0, MIT\ngem_b, 1.0, MIT")
28
+ is_expected.to eq("gem_a, 1.0, MIT\ngem_b, 1.0, MIT\ngem_c, 2.0, \"MIT, BSD\"\n")
29
+ end
30
+
31
+ it 'prints a warning message for packages that have not been installed' do
32
+ dep = Package.new('gem_d', '2.0', missing: true)
33
+ report = described_class.new([dep]).to_s
34
+ expect(report).to eq("gem_d, 2.0, \"This package is not installed. Please install to determine licenses.\"\n")
26
35
  end
27
36
  end
28
37
  end
data/spec/spec_helper.rb CHANGED
@@ -6,6 +6,7 @@ require 'license_finder'
6
6
  require 'rspec'
7
7
  require 'webmock/rspec'
8
8
  require 'rspec/its'
9
+ require 'fileutils'
9
10
 
10
11
  ENV['test_run'] = true.to_s
11
12
 
@@ -18,10 +19,6 @@ RSpec.configure do |config|
18
19
  end
19
20
 
20
21
  RSpec.configure do |config|
21
- config.around do |example|
22
- LicenseFinder::DB.transaction(rollback: :always) { example.run }
23
- end
24
-
25
22
  config.after(:suite) do
26
23
  ["./doc", "./elsewhere", "./test path", "./config"].each do |tmp_dir|
27
24
  FileUtils.rm_rf(tmp_dir)